[QUESTION] Message ordering in a fanout exchange

116 views
Skip to first unread message

Dominik Enzinger

unread,
May 25, 2018, 7:09:25 AM5/25/18
to rabbitmq-users
Lady- and Gentlerabbits,

considering the following template, is every consumer of each dedicated queue receiving messages in the exact same order as the are published?



Important Notes
  • Exchange A is a fanout exchange
  • Application A will send each message in order with Publisher Confirms and Batch Publishing, see Code Snippet A
  • Each applications has its own dedicated queue and will be consumed by only one consumer.
  • RabbitMQ version is >= 3.7.5

Code Snippet A

$channel = $this->connection->channel();

$channel->set_ack_handler(
    function (AMQPMessage $AMQPMessage) {
        $this->acknowledge($AMQPMessage); // This will delete the message from the message buffer
    }
);

$channel->confirm_select();

// Ensure exchange exists
$channel->exchange_declare($this->exchange, '', true);

$i = 0;
foreach ($this->messageBuffer->findUnsentMessages() as $message) { // This will iterate through every message from the buffer in order
    $AMQPMessage = $this->converter->toAMQPMessage($message);

    $channel->batch_basic_publish($AMQPMessage, $this->exchange);

    if ($i % self::BATCH_SIZE === 0) {
        $channel->publish_batch();
    }

    $i++;
}

$channel->publish_batch();

$channel->wait_for_pending_acks();

$channel->close();

Thanks in advance,

Dominik.

Michael Klishin

unread,
May 25, 2018, 4:02:43 PM5/25/18
to rabbitm...@googlegroups.com
Exchanges do not store messages. They process them in the order they were published
on the channel.

Queues then store and deliver messages in the FIFO manner. Requeueing [1]
can complicate this but RabbitMQ will try to requeue deliveries into the original position
if possible.

HTH.


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+unsubscribe@googlegroups.com.
To post to this group, send email to rabbitmq-users@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
MK

Staff Software Engineer, Pivotal/RabbitMQ
Reply all
Reply to author
Forward
0 new messages