RabbitMQ Support
Asynchronous PHP RabbitMQ
Last updated
Was this helpful?
Asynchronous PHP RabbitMQ
Last updated
Was this helpful?
solid and powerful abstraction over asynchronous queues.
In order to use AMQP Support
we need to add ConnectionFactory
to our Dependency Container.
To create AMQP Backed (RabbitMQ Channel), we need to create .
Now orders
channel will be available in our Messaging System.
Message Channels simplify to the maximum integration with Message Broker. From application perspective all we need to do, is to provide channel implementation. Ecotone will take care of whole publishing and consuming part.
By default the queue name will follow channel name, which in above example will be "orders". However we can use "orders" as reference name in our Application, yet name queue differently:
If you want to publish Message directly to Exchange, you may use of Publisher.
Reference name
- Name under which it will be available in Dependency Container.
Exchange name
- Name of exchange where Message should be published
Default Conversion [Optional]
- Default type, payload will be converted to.
withDefaultPersistentDelivery
- should AMQP messages be persistent
.
withDefaultRoutingKey
- default routing key added to AMQP message
withRoutingKeyFromHeader
- should routing key be retrieved from header with name
withHeaderMapper
- On default headers are not send with AMQP message. You map provide mapping for headers that should be mapped to AMQP Message
We can bind given method as Message Consumer
To connect consumer directly to a AMQP Queue, we need to provide Ecotone
with information, how the Queue is configured.
AmqpQueue::createWith(string $name)
- Registers Queue with specific name
AmqpExchange::create*(string $name)
- Registers of given type with specific name
AmqpBinding::createFromName(string $exchangeName, string $queueName, string $routingKey)
- Registering binding between exchange and queue
Provides Consumer that will be registered at given name "orders_consumer"
and will be polling "orders"
queue
Ecotone AMQP
comes with support for RabbitMQ Transaction for published messages.
This means that, if you send more than one message at time, it will be commited together.
To enable transactions on specific endpoint if default is disabled, mark consumer with Ecotone\Amqp\AmqpTransaction\AmqpTransaction
annotation.
AMQP Distributed Bus is described in more details under .
By default Ecotone will aim for resiliency to avoid Message being lost. This protects from lost heartbeats issue (AMQP bug which make message vanish without exceptions) and ensures that Message are considered delivered only when Broker has acknowledged storing them on the Broker side (Using ). However Publisher confirms comes with time cost, as it makes publishing process awaits for acknowledge from RabbitMQ. Therefore if delivery guarantee is not an issue, and we can accept risk of losing messages we can consider disable it to speed up publishing time:
Publisher acknowledgments can be combined with to ensure high message guarantee.
If you want to enable/disable for all or specific for Command Bus. You may use of ServiceContext.
By default RabbitMQ transactions are disabled, as you may ensure consistency using .