I am using a JmsTemplate
(spring-jms-5.2.8) for sending messages to an embedded ActiveMQ broker to a several topics. I want some of the topics to be persistent (the messages sent to them to be persisted) and some of them not. Unfortunately, the JmsTemplate seems to be configuring the delivery mode globally = for all messages sent through it (requiring the QOS enabled).
Setting the delivery mode directly on the message doesn't help because it gets overridden later on.
jmsTemplate.convertAndSend(destination, event, message -> {
message.setJMSDeliveryMode(XXX);
return message;
});
What is the best solution to this? Do really all the messages going through the JmsTemplate have to be either persistent or non-persistent? Do I have to create two separate JmsTemplates? Is that a good approach? What about the connection factory I am passing in? Can the same connection factory be used for both templates?
Thanks.
Do I have to create two separate JmsTemplates? Is that a good approach?
Yes; the simplest solution is to define 2 templates.
What about the connection factory above?
?? It's not clear what you mean by "above".
You can use the same factory in each template; they will share the connection.