Stefano Cazzola
Stefano Cazzola

Reputation: 1687

JMS - Message redlivery on fail

I've got this scenario:

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?

Upvotes: 0

Views: 291

Answers (1)

fhofmann
fhofmann

Reputation: 847

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

Upvotes: 1

Related Questions