0

I've got this scenario:

  • a JMS message elaboration via an MDB might fail (throws a RuntimeException in this case)
  • the message should be redelivered, though after a delay (ideal, but not strictly necessary: after an increasing delay depending on the number of fails)
  • after x failures, the message should be disregarded and never sent again

Right now, the behaviour I have is that the failed message is redelivered instantly for 10 times, and I haven't been able to customize this.

Is there a way I can achieve this via @JMSdefinition (or other annotations as well) or setting the correct properties in the message? If so, how to do?

Stefano Cazzola
  • 1,597
  • 1
  • 20
  • 36

1 Answers1

1

You can schedule the message with _AMQ_SCHED_DELIVERY property:

    Queue q = (Queue) ServiceLocator.getInstance().getDestination("QUEUE");
    QueueConnectionFactory factory = (QueueConnectionFactory) ServiceLocator.getInstance().getConnectionFactory(
            "java:/ConnectionFactory");
    QueueConnection connection = factory.createQueueConnection();
    QueueSession session = null;
    QueueSender sender = null;
    session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
    sender = session.createSender(q);
    ObjectMessage msg = session.createObjectMessage();
    if (redelivedCount > 0) {
      msg.setIntProperty("redelivedCount", redelivedCount);
      // schedule to run in 10 secs
      msg.setLongProperty("_AMQ_SCHED_DELIVERY", System.currentTimeMillis() + 10000);
    }
    msg.setStringProperty("action", action);
    msg.setObject(params);
    sender.send(msg);
fhofmann
  • 847
  • 7
  • 15