| description | Production-grade RabbitMQ consumer with Ecotone |
|---|
Set up production-grade RabbitMQ consumption with a single attribute. Built-in reconnection, graceful shutdown, and health checks replace custom consumer process management scripts.
You'll know you need this when:
- Your custom RabbitMQ consumer scripts need manual connection handling, reconnection logic, and shutdown management
- Consumer processes crash on connection drops and require external restart supervision
- You need health checks and graceful shutdown for containerized deployments
- You want to combine consumption with instant retry, error channels, and deduplication declaratively
{% hint style="success" %} This feature is available as part of Ecotone Enterprise. {% endhint %}
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.
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.
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.
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.
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.
We can define custom deduplication key to ensure no same Message will be handled twice.
#[Deduplicated('orderId')]
#[RabbitConsumer(
endpointId: 'orders_consumer',
queueName: 'orders'
)]
public function handle(Order $payload): void
{
// handle
}Read more about deduplication in related section.