I have two Spring Boot applications using JmsListener
consuming from an ActiveMQ Artemis multicast queue named onboard_application
and address named onboard_address
but only one manages to receive the message and then the message gets deleted from the queue.
My listeners look like below snippet:
@JmsListener(destination = "onboard_address::onboard_application")
public void applicationOnboardingMessageReceiver(String message) throws JsonProcessingException {
ApplicationDTO appDTO = objectMapper.readValue(message, ApplicationDTO.class);
//Business logic
}
My message sender looks like:
public void sendMulticastMessage(String channel, Object payload) throws Exception {
try {
jmsTemplate.setPubSubDomain(true);
jmsTemplate.convertAndSend(channel, objectMapper.writeValueAsString(payload));
} catch (JsonProcessingException e) {
//Take action
}
}
Configuration in application.yml
:
spring:
artemis:
mode: native
user: artemis
password: artemis
broker-url: tcp://localhost:61616
jms:
pub-sub-domain: true
Could you please suggest what am I missing or doing wrong? Thanks in advance.
What you're observing is the expected behavior since both JmsListener
instances are configured to consume from a single queue (i.e. onboard_address::onboard_application
- the fully qualified queue name). All the consumers on a particular queue share the messages on that queue.
If you want normal multicast (i.e. pub/sub) semantics then you should simply specify the name of the address, e.g.:
@JmsListener(destination = "onboard_address")
Use the same value for the application which sends the messages.
You can read more about the ActiveMQ Artemis address model in the documentation.