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.