Enqueue solid and powerful abstraction over asynchronous queues.
Configuration
In order to use AMQP Support we need to add ConnectionFactory to our Dependency Container.
# config/services.yaml# You need to have RabbitMQ instance running on your localhost, or change DSN Enqueue\AmqpExt\AmqpConnectionFactory: class: Enqueue\AmqpExt\AmqpConnectionFactory arguments:-"amqp://guest:guest@localhost:5672//"
# Register AMQP Service in ProvideruseEnqueue\AmqpExt\AmqpConnectionFactory;publicfunctionregister(){$this->app->singleton(AmqpConnectionFactory::class,function () {returnnewAmqpConnectionFactory("amqp+lib://guest:guest@localhost:5672//"); });}
We register our AmqpConnection under the class name Enqueue\AmqpExt\AmqpConnectionFactory. This will help Ecotone resolve it automatically, without any additional configuration.
Now orders channel will be available in our Messaging System.
Message Channel Configuration
DbalBackedMessageChannelBuilder::create("orders")->withAutoDeclare(false)// do not auto declare queue->withDefaultTimeToLive(1000)// limit TTL of messages
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
Available Exchange configurations
$amqpExchange =AmqpExchange::createDirectExchange$amqpExchange =AmqpExchange::createFanoutExchange$amqpExchange =AmqpExchange::createTopicExchange$amqpExchange =AmqpExchange::createHeadersExchange$amqpExchange = $amqpExchange->withDurability(true)// exchanges survive broker restart->withAutoDeletion()// exchange is deleted when last queue is unbound from it
Available Queue configurations
$amqpQueue =AmqpQueue::createDirectExchange->withDurability(true)// the queue will survive a broker restart ->withExclusivity() // used by only one connection and the queue will be deleted when that connection closes
->withAutoDeletion() // queue that has had at least one consumer is deleted when last consumer unsubscribes
->withDeadLetterExchangeTarget($amqpExchange);
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.