1
Console.WriteLine($"Publishing to Default EXG & queue: {result.QueueName}");

Todo : BUILD Retries, Republish and Acknowledgement Workflow.

                    IBasicProperties messageProps = _channel.CreateBasicProperties();
                    messageProps.Persistent = true;

//Handle Acks

                    _channel.BasicAcks += _channel_BasicAcks;
                    _channel.ConfirmSelect();
//Publish                    

                    byte[] body = Encoding.UTF8.GetBytes(messageToPublish);

                    _channel.QueueBind(
                        queueName,
                        exchangeName,
                        routingKey,
                        null
                        );
                    _channel.BasicPublish
                    (   exchange: exchangeName,
                        routingKey: routingKey,
                        basicProperties: messageProps,
                        body: body);

//Wait for the Confirmations      

                    _channel.ConfirmSelect();
                    _channel.WaitForConfirmsOrDie(10000);

The Event

_channel_BasicAcks (Object Sender, EventArgs e)

which is being called now externally from the scope of the publish method(async) instead of Synchronously getting response.

For a hardbound requirement of retrying individual messages immediately after a nack in a bulk publish how do I make this strictly synchronous.

Sync Wrapper to Async Publish method is the Solution I came up with, it works though it is not the best there is! Is there a better performing solution instead of having to trial and error with timeouts!

DL Narasimhan
  • 731
  • 9
  • 25

1 Answers1

1

For a hardbound requirement of retrying individual messages immediately after a nack in a bulk publish how do I make this strictly synchronous.

Don't wait for acks synchronously!

Save messages client-side until you receive an asynchronous ack / nack for it, then do something based on that response. Specify a certain number of "outstanding" acknowledgements that are acceptable and do not publish if that limit is reached. Specify a time limit that is acceptable for receiving an ack/nack and if that limit is exceeded, do something in your application to deal with it.


NOTE: the RabbitMQ team monitors the rabbitmq-users mailing list and only sometimes answers questions on StackOverflow.

Luke Bakken
  • 8,993
  • 2
  • 20
  • 33