【发布时间】:2019-10-01 07:14:31
【问题描述】:
我在 Spring Boot 应用程序中使用 ActiveMq 设置 JMS。但无法理解如何防止发送者(消息提供者)将重复的消息添加到队列中。
我的应用初始JMS和消息转换器bean配置如下
@Bean
public Queue queue() {
return new ActiveMQQueue("pendingDocuments.queue");
}
@Bean
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}
发送方方法实现
@Autowired
private JmsMessagingTemplate jmsMessagingTemplate;
@Autowired
private Queue pendingDocumentsQueue;
public void getPendingDocuments(){
/*My Custom Java Object, Actually these objects will read from DB for every 5 min, so process no way to know either these are already added to queue or not*/
Document document= new Document();
document.setUniqueId("122212");
document.setContent("TEST CONTENT");
this.jmsMessagingTemplate.convertAndSend(this.pendingDocumentsQueue, document);
}
我想知道如何根据文档唯一 ID 将消息(我的文档对象)添加到队列中。
【问题讨论】:
-
identifying 重复消息是 activemq 的工作,您不必自己编写代码,请参阅 [activemq.apache.org/components/artemis/documentation/1.0.0/…,另一方面,如果您想避免它 - stackoverflow.com/questions/4934386/…
-
我已经浏览了这些链接,但我无法理解在我的配置中应该将以下代码放在哪里。 message.setStringProperty(HDR_DUPLICATE_DETECTION_ID.toString(), myUniqueID);
-
对于它的价值,问题似乎与 ActiveMQ 5.x 有关,有关设置 HDR_DUPLICATE_DETECTION_ID 字符串属性的文档适用于 ActiveMQ Artemis(即下一代 ActiveMQ 代理)。
标签: java spring spring-boot jms activemq