Uploaded image for project: 'ActiveMQ .Net'
  1. ActiveMQ .Net
  2. AMQNET-769

Redelivery Options do not work

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • AMQP-2.0.0
    • None
    • NMS
    • None

    Description

      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.

       

       

      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");

      Then, to read messages, I do:

       

      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();
          }
        }

      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:
       

      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");

      In this case it's even worse because the broker will attempt redelivery indefinetly.

      Attachments

        Activity

          People

            Unassigned Unassigned
            marcogalassi Marco Galassi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: