swarrot / SwarrotBundle

A symfony bundle for swarrot integration
MIT License
89 stars 59 forks source link

Durable Message config #102

Closed noniagriconomie closed 7 years ago

noniagriconomie commented 7 years ago

Hi,

We begin to use your bundle and the lib behind, it works well

I have 2 questions about our first implementation:

            $message = new Message(json_encode([
                'channel' => SlackWebHookApi::CHANNEL_TECH_LOG,
                'text' => 'RabbitMq'.$i
            ]), ['delivery_mode' => 2]); // AMQP_DURABLE
            $messagePublisher->publish('slack_publisher', $message);

If i did not set the ['delivery_mode' => 2], if we publish message and restart the rabbitmq server, message is lost (queue empty)

Many thanks :)

odolbeau commented 7 years ago

Hi @noniagriconomie.

Regarding the first question, it's not mandatory. If your queues are explicitly created with the correct flag, you don't need to add this information in all message headers you sent.

For the second question, it's kind of mandatory in your case as you're using durable messages. When you don't use this option, you don't need to ack or nack any message when consuming them.

noniagriconomie commented 7 years ago

hey @odolbeau

thank you for fast answer Ok I understood, i will review my code/config then

issue closed :)

bricelalu commented 4 years ago

@odolbeau @noniagriconomie Hello. Regarding the first question, as it is written in the RabbitMQ documentation: https://www.rabbitmq.com/reliability.html#broker-side, yes it is mandatory. Messages need to be delivered with delivery_mode=2, otherwise, messages will not be persisted on disk and they will not survive a restart. I had this unpleasant experience recently ;) Durable "queues" and "exchanges" are not enough.

FYI in the messenger component, they will implement this behavior by default, privileging safety before performance: https://github.com/symfony/symfony/issues/34685

Maybe we should do the same in swarrot? What do you think @odolbeau?

Thanks :)