英文:
how to add delivery delay on AWS SQS messages using Spring JmsTemplate
问题
嗨,我想实现类似于使用Java和JmsTemplate发送具有特定传递延迟的SQS消息的函数。\n实际上,我已经完成了发送没有延迟的消息的实现。\n像这样:\n\n\n @Override\n public boolean sendMessage(String queueName, String message) throws EventBrokerException {\n final String messageWithTransactionGuid = addTransactionGuidToMessage(message);\n jmsTemplate.convertAndSend(queueName, messageWithTransactionGuid);\n return isSuccess;\n }\n
\n\n我阅读了一些文章,也许我需要做类似这样的事情?\n\n\n jmsTemplate.convertAndSend(queueName, messageWithTransactionGuid, new MessagePostProcessor() {\n @Override\n public Message postProcessMessage(Message message) throws JMSException {\n message.setIntProperty(/*指定字段名和延迟秒数*/);\n return message;\n }\n });\n
\n但我没有看到任何示例,我阅读了源代码,也没有找到需要指定什么,请问有人可以帮忙吗?
英文:
Hi I want to implement the function like sending sqs messages with a specific delivery delay using java and JmsTemplate.
Actually, I finished the implementation of sending messages without delay.
like this:
@Override
public boolean sendMessage(String queueName, String message) throws EventBrokerException {
final String messageWithTransactionGuid = addTransactionGuidToMessage(message);
jmsTemplate.convertAndSend(queueName, messageWithTransactionGuid);
return isSuccess;
}
I read some articles, Maybe I need to do somthing like this???
jmsTemplate.convertAndSend(queueName, messageWithTransactionGuid, new MessagePostProcessor() {
@Override
public Message postProcessMessage(Message message) throws JMSException {
message.setIntProperty(/*specify field name and delay seconds*/);
return message;
}
});
But I didn't see any examples, I read the sourcecode and didn't find out what to specify, can anybody help?
答案1
得分: 2
所以我所做的是一个简单的方法:
private Boolean doSendMessage(String queueName, String message, long deliveryDelay){
jmsTemplate.setDeliveryDelay(deliveryDelay);
jmsTemplate.convertAndSend(queueName, message);
jmsTemplate.setDeliveryDelay(DEFAULT_MESSAGE_DELIVERY_DELAY);
return isSuccess;
}
这里的 DEFAULT_MESSAGE_DELIVERY_DELAY
是 -1。
我注入了 jmsTemplate,并设置了 setDeliveryDelay 和 resetDeliveryDelay。
英文:
So what I did is a simple way:
private Boolean doSendMessage(String queueName, String message, long deliveryDelay){
jmsTemplate.setDeliveryDelay(deliveryDelay);
jmsTemplate.convertAndSend(queueName, message);
jmsTemplate.setDeliveryDelay(DEFAULT_MESSAGE_DELIVERY_DELAY);
return isSuccess;
}
Here DEFAULT_MESSAGE_DELIVERY_DELAY
is -1.
I injected jsmTemplate, and setDeliveryDelay and resetDeliveryDelay
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论