1

I have a rabbitmq setup with a producer and many consumers.

What would the best practice way to tell the consumers that the producer isn't able to send due to crash or some other failure?

In case of a failure in the producer I'd like to notify and show a fitting message to all consumers.

1
  • The case of "producer not producing" is indeed handled by default in RabbitMQ - it is the same as the case of the queue having no messages. The broker is perfectly happy to do nothing in either case.
    – theMayer
    Dec 10, 2018 at 20:44

2 Answers 2

1

There is not an automatic way to do that, but in general, the messages systems are designed to decoupling the producers and the consumers. The basic idea is that the consumers don't know anything about producers.

Said, that you should handle the producers crashes and maybe adopt policies as publish confirm you want more control about your producers

1
  • Yes I saw the docs discussing the acks mechanism but don't know how to use them in my case. The producer might not produce for some time yet I must keep a liveliness status of the producer in all my consumers. Should I create a "liveliness mechanism" myself for that case? Create a message that will be sent with some interval and make sure I get an acknowledgement from the producer?
    – user5326354
    Dec 11, 2018 at 10:14
0

I know it's kind of late to answer your question but here is my method for letting know the consumers that the producer is alive : you can add a ping message for example inside a Task which will publish to RabbitMQ each X seconds.

This solution works with ACKS back from RMQ and it works when you have a big number of messages coming in. This does not affect your performance by using ACKS

For example, taking the code in C# :

...
m_mainTimer = new System.Timers.Timer();
m_mainTimer.Interval = 10000;   // every 10 secs
m_mainTimer.Elapsed += m_mainTimer_Elapsed;
m_mainTimer.AutoReset = false;  // makes it fire only once
m_mainTimer.Start(); // Start
...
void m_mainTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e){
     try {
          // send to RMQ
          sendMessageToRabbitMQ("PING", "error");
          m_timerTaskSuccess = true;
     } catch (Exception ex) {
          m_timerTaskSuccess = false;
     } finally {
          if (m_timerTaskSuccess) {
                m_mainTimer.Start();
          }
     }
}

The actual message in RMQ:

{
  "Message": "PING",
  "Timestamp": 1620303014184
}

If you don't get this message in less than 11 seconds you know there is a problem.

I hope it helps the others as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.