You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@activemq.apache.org by "Marco Galassi (Jira)" <ji...@apache.org> on 2022/05/10 19:03:00 UTC

[jira] [Created] (AMQNET-769) Redelivery Options do not work

Marco Galassi created AMQNET-769:
------------------------------------

             Summary: Redelivery Options do not work
                 Key: AMQNET-769
                 URL: https://issues.apache.org/jira/browse/AMQNET-769
             Project: ActiveMQ .Net
          Issue Type: Bug
          Components: NMS
    Affects Versions: AMQP-2.0.0
            Reporter: Marco Galassi


I'm trying to set redelivery options, but they don't seem to work.

I want to be able to use the redelivery options so that if there is an error/issue/something, the message gets sent back to the broker and redelivered according to certain options.

For instance, I want to set:
 * InitialRedeliveryDelay = 500ms
 * BackOffMultiplier = 2
 * UseExponentialBackOff = true
 * MaximumRedeliveries = 5

I haven't found many examples, but I came up with this by stitching together the ActiveMQ documentation, the Apache.NMS.amqp docs and a few online examples.

 

 
{code:java}
String brokerUri = "amqp://127.0.0.1:5672";
IConnectionFactory factory = new ConnectionFactory(brokerUri);
IConnection connection = factory.CreateConnection();
RedeliveryPolicy rdp = new RedeliveryPolicy();
rdp.MaximumRedeliveries = 5;
rdp.BackOffMultiplier = 2;
rdp.InitialRedeliveryDelay = 5000;
rdp.UseExponentialBackOff = true;
connection.RedeliveryPolicy = rdp;
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IDestination dest = session.GetQueue("foo.bar");{code}
Then, to read messages, I do:

 
{code:java}
IMessageConsumer consumer = session.CreateConsumer(dest);
DateTime start = DateTime.Now;
long count = 0;
Console.WriteLine("Waiting for messages...");
while (true)
  {
    IMessage msg = consumer.Receive();
    count++;
    ITextMessage txtMsg = msg as ITextMessage;
    String body = txtMsg.Text;
    Console.WriteLine(DateTime.Now + "_" + count + " ____ " + body);
    if (body == "end")
    {
      session.Recover();
    }
    else
    {
      msg.Acknowledge();
    }
  }{code}
This is not working. The only thing that seems to work is that it correctly sets the maximum redeliveries attemps before sending the Poison ACK to the Broker.

 

None of the other options are taken into consideration

 
I have also tried to pass all these options in the uri, as specified in the ([ActiveMQ docs under "Nested Options"|[https://activemq.apache.org/connection-configuration-uri])] as follows:
 
{code:java}
String brokerUri = "amqp://127.0.0.1:5672?jms.redeliveryPolicy.maximumRedeliveries=5&jms.redeliveryPolicy.BackOffMultiplier=2&jms.redeliveryPolicy.InitialRedeliveryDelay=2000&jms.redeliveryPolicy.UseExponentialBackOff=true";
IConnectionFactory factory = new ConnectionFactory(brokerUri);
IConnection connection = factory.CreateConnection();
connection.Start();
ISession session = connection.CreateSession(AcknowledgementMode.ClientAcknowledge);
IDestination dest = session.GetQueue("foo.bar");{code}
In this case it's even worse because the broker will attempt redelivery indefinetly.



--
This message was sent by Atlassian Jira
(v8.20.7#820007)