Reputation: 1418
I want to use ActiveMQ within Spring Boot app as embedded server. To setup ActiveMQ I used following tutorial: Spring Boot. Messaging with JMS. My app will be the broker and the consumer. There are multiple threads creating messages like this:
@Autowired
private JmsTemplate jmsTemplate;
.......
MessageCreator messageCreator = session -> session.createObjectMessage(transactionNotificationData);
jmsTemplate.setSessionAcknowledgeMode(Session.CLIENT_ACKNOWLEDGE);
jmsTemplate.send(QUEUE, messageCreator);
I have another class with following method:
@JmsListener(destination = QUEUE)
public void receive(Message message) throws IOException {
brokerService.getPersistenceAdapter();
try {
if (message instanceof ObjectMessage) {
ObjectMessage objMessage = (ObjectMessage) message;
NotificationData notification = (NotificationData) objMessage.getObject();
LOG.info("Received <" + notification.notification + ">");
...... do some stuff ........
// message.acknowledge();
}
} catch (JMSException e) {
e.printStackTrace();
}
During the tests I can see the messages are produced and consumed.
As you can see message.acknowledge()
is commented. So I expect the message will be redelivered after rerun of my app. However it doesn't happen.
Upvotes: 0
Views: 2427
Reputation: 3831
Message Acknowledgement is automatically handled by the container and it executes after the onMessage() is successfully executed,(receive() in your case),
so even when you comment message.acknowledge();
, container on its own sends the acknowledgement
you can have a look at following link for more reference
Hope this helps!
Good luck!
Upvotes: 2