Rabbit Consumer
To quickly get up and running with consuming existing Queues, we can use Rabbit Consumer feature. Simply by marking given method with Amqp Consumer attribute, we are getting access to asynchronous process that will now run and consume Message from defined Queue.
This feature is available as part of Ecotone Enterprise.
Consume Messages from Queue
To consume Messages from Queue, it's enough to mark given method with AmqpConsumer attribute:
#[RabbitConsumer(
endpointId: 'orders_consumer',
queueName: 'orders'
)]
public function handle(string $payload): void
{
// handle
}
And then we can run related process using endpoint Id "orders_consumer". Read more on running asynchronous processes in related section.
Automatic Conversion
If we have our Custom Conversion or JMS Module installed, then we can leverage automatic conversion:
#[RabbitConsumer(
endpointId: 'orders_consumer',
queueName: 'orders'
)]
public function handle(Order $payload): void
{
// handle
}
Read more about Conversion in related section.
Instant Retry
In case of failure we may try to recover instantly. To do so we can provide InstantRetry attribute:
#[InstantRetry(retryTimes: 3)]
#[RabbitConsumer(
endpointId: 'orders_consumer',
queueName: 'orders'
)]
public function handle(Order $payload): void
{
// handle
}
Read more about Instant Retry in related section.
Error Channel
To handle Message when failure happen, we may decide to send it to Error Channel. This can be used to for example store the Message for later review.
#[ErrorChannel('customErrorChannel')]
#[RabbitConsumer(
endpointId: 'orders_consumer',
queueName: 'orders'
)]
public function handle(Order $payload): void
{
// handle
}
Read more about Error Channel in related section.
Final Failure Strategy
We can also define in case of unrecoverable failure, what should happen:
#[RabbitConsumer(
endpointId: 'orders_consumer',
queueName: 'orders',
finalFailureStrategy: FinalFailureStrategy::RESEND
)]
public function handle(Order $payload): void
{
// handle
}
Read more about final failure strategy in related section.
Last updated
Was this helpful?