Scheduling

Scheduling PHP

Scheduling

Ecotone comes with support for running period tasks or cron jobs using Scheduled. Scheduled creates Message from given method and send it to requestChannelName.

class CurrencyExchanger
{
#[Scheduled(requestChannelName: "exchange", endpointId: "currencyExchanger")]
#[Poller(fixedRateInMilliseconds=1000)]
public function callExchange() : array
{
return ["currency" => "EUR", "ratio" => 1.23];
}
}
‚Äč
#[CommandHandler("exchange")]
public function exchange(ExchangeCommand $command) : void;

endpointId - Scheduled requires defined endpointId, it will be used in order to run Adapter. requestChannelName - The channel name to which Message should be send poller - Configuration how to execute Inbound Channel Adapter, read more in next section. This configuration tells Ecotone to execute Channel Adapter every second.

Symfony
Laravel
Lite
Symfony
console ecotone:list
+--------------------+
| Endpoint Names |
+--------------------+
| currencyExchanger |
+--------------------+
Laravel
artisan ecotone:list
+--------------------+
| Endpoint Names |
+--------------------+
| currencyExchanger |
+--------------------+
Lite
$consumers = $messagingSystem->list()

After setting up Scheduled endpoint we can run the endpoint:

Symfony
Laravel
Lite
Symfony
console ecotone:run currencyExchanger -vvv
Laravel
artisan ecotone:run currencyExchanger -vvv
Lite
$messagingSystem->run("currencyExchanger");

After runningcurrencyExchanger endpoint it will poll message from callExchangeand call Command Handler exchangewith array payload ["currency" => "EUR", "ratio" => 1.23]. When the Message will arrive on the Command Handler it will be automatically converted to ExchangeCommand. If you want to understand how the conversion works, you may read about it in Conversion section.

Polling Metadata

Polling Metadata defines how polling consumer should behave.

#[Poller(
1 cron="* * * * *",
2 initialDelayInMilliseconds=2000,
3 fixedRateInMilliseconds=1000,
4 memoryLimitInMegabytes=100,
5 handledMessageLimit=10,
6 executionTimeLimitInMilliseconds=200,
7 errorChannelName="errorChannel"
)]

cron - Defines that consumer should be called according to given cron expression initialDelayInMilliseconds - Delay after executing consumer, before consumer will start polling memoryLimitInMegabytes - Limit of RAM, before execution of consumer will be stopped. handledMessageLimit - Limit of handled messages, before execution of consumer will be stopped executionTimeLimitInMilliseconds - How long consumer should be running before it will be stopped errorChannelName - In case of failure during consumer execution, where to send exception.