I've got a problem with publish messages to RabbitMQ. Our application must work in transactional layer.
But, i don't understand one case: If I firstly start transaction and commit it, all next messages don't published to RabbitMQ.
$connection = new \AMQPConnection([
'host' => 'rabbitmq',
'port' => 5672,
'login' => 'guest',
'password' => 'guest',
]);
$connection->connect();
$channel = new \AMQPChannel($connection);
$exchange = new \AMQPExchange($channel);
$exchange->setName('some_test');
$exchange->setFlags(AMQP_DURABLE);
$exchange->setType(AMQP_EX_TYPE_DIRECT);
$exchange->declareExchange();
$queue = new \AMQPQueue($channel);
$queue->setFlags(AMQP_DURABLE);
$queue->setName('some_test_queue');
$queue->declareQueue();
$queue->bind('some_test', 'some:foo:bar');
$channel->startTransaction();
$exchange->publish('some #1', 'some:foo:bar');
$exchange->publish('some #2', 'some:foo:bar');
$channel->commitTransaction();
$exchange->publish('some #3', 'some:foo:bar');
Last messages not published to exchange. But, if I call to commitTransaction
in channel, last messages was success published to queue.
I read the documentation here: https://www.rabbitmq.com/confirms.html#publisher-confirms
Maybe RabbitMQ after first transaction mark this channel as transactional and always wait commit/rollback after publish any messages?