我有这种情况:
RuntimeException
)现在,我的行为是失败的消息会立即重新传递10次,而我无法自定义此消息。
有没有办法可以通过@JMSdefinition
(或其他注释)或在邮件中设置正确的属性来实现这一点?如果是的话,怎么办?
答案 0 :(得分:1)
您可以使用 _AMQ_SCHED_DELIVERY 属性安排消息:
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);