I am setting up JMS using ActiveMq in spring boot application. But unable to understand how to prevent sender (Message provider) to adding duplicate messages to queue.
My application initial JMS and message converter beans configuration as follows
@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;
}
Sender method implementation
@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);
}
I would like to know how can we add messages (my document object) to queue based on document unique id.