Scheduling
Scheduling PHP
Ecotone comes with support for running period tasks or cron jobs.

Scheduled Method

1
class NotificationService
2
{
3
#[Scheduled(endpointId: "notificationSender")]
4
#[Poller(fixedRateInMilliseconds: 1000)]
5
public function sendNotifications(): void
6
{
7
echo "Sending notifications...\n";
8
}
9
}
Copied!
endpointId - it's name which identifies process to run poller - Configuration how to execute this method read more in next section. Above configuration tells Ecotone to execute this method every second.
Symfony
Laravel
Lite
1
console ecotone:list
2
+--------------------+
3
| Endpoint Names |
4
+--------------------+
5
| notificationSender |
6
+--------------------+
Copied!
1
artisan ecotone:list
2
+--------------------+
3
| Endpoint Names |
4
+--------------------+
5
| notificationSender |
6
+--------------------+
Copied!
1
$consumers = $messagingSystem->list()
Copied!
After setting up Scheduled endpoint we can run the endpoint:
Symfony
Laravel
Lite
1
console ecotone:run notificationSender -vvv
Copied!
1
artisan ecotone:run notificationSender -vvv
Copied!
1
$messagingSystem->run("notificationSender");
Copied!

Scheduled Handler

You can run Scheduled for given Handler. Right now method return Message which is send to given routing.
1
class CurrencyExchanger
2
{
3
#[Scheduled(requestChannelName: "exchange", endpointId: "currencyExchanger")]
4
#[Poller(fixedRateInMilliseconds=1000)]
5
public function callExchange() : array
6
{
7
return ["currency" => "EUR", "ratio" => 1.23];
8
}
9
}
10
11
#[CommandHandler("exchange")]
12
public function exchange(ExchangeCommand $command) : void;
Copied!
requestChannelName - The channel name to which Message should be send.
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.
Export as PDF
Copy link