RabbitMQ Support
Asynchronous PHP RabbitMQ
Installation
Module Powered By
Enqueue solid and powerful abstraction over asynchronous queues.
Configuration
In order to use AMQP Support
we need to add ConnectionFactory
to our Dependency Container.
We register our AmqpConnection under the class name Enqueue\AmqpExt\AmqpConnectionFactory.
This will help Ecotone resolve it automatically, without any additional configuration.
Message Channel
To create AMQP Backed Message Channel (RabbitMQ Channel), we need to create Service Context.
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.
Message Channel Configuration
Customize Queue Name
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:
Custom Publisher and Consumer
To create custom publisher or consumer provide Service Context.
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.
Distributed Publisher
Distributed Consumer
Message Publisher
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 publishedDefault Conversion [Optional]
- Default type, payload will be converted to.
Publisher Configuration
withDefaultPersistentDelivery
- should AMQP messages bepersistent
.withDefaultRoutingKey
- default routing key added to AMQP messagewithRoutingKeyFromHeader
- should routing key be retrieved from header with namewithHeaderMapper
- On default headers are not send with AMQP message. You map provide mapping for headers that should be mapped toAMQP Message
Message Consumer
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 nameAmqpExchange::create*(string $name)
- Registers of given type with specific nameAmqpBinding::createFromName(string $exchangeName, string $queueName, string $routingKey)
- Registering binding between exchange and queueProvides Consumer that will be registered at given name
"orders_consumer"
and will be polling"orders"
queue
Available Exchange configurations
Available Queue configurations
Publisher Transactions
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.
If you want to enable/disable for all Asynchronous Endpoints or specific for Command Bus. You may use of ServiceContext.
By default RabbitMQ transactions are disabled, as you may ensure consistency using Resilient Sending.
To enable transactions on specific endpoint if default is disabled, mark consumer with Ecotone\Amqp\AmqpTransaction\AmqpTransaction
annotation.
Last updated