I have a JMS producer sending 2 kinds of messages: business logic and heart beat messages. Currently, both are handled by the same receiver, but I am now trying to have dedicated classes for each by using selectors. The problem I have is whenever I add the selector to the receiver, it stops receiving messages. Here is what I have so far. For simplicity, I have only added the code for the heart beat:
To send the message, I have this:
private void sendHeartBeat() {
this.buildTemplate().send(new HeartbeatMessageCreator(this.someId));
}
private JmsTemplate buildTemplate() {
if (this.cachedJmsTemplate == null) {
final ActiveMQTopic activeMQTopic = new ActiveMQTopic(this.topic);
this.cachedJmsTemplate = new JmsTemplate(this.config.getCachedConnectionFactory());
this.cachedJmsTemplate.setDefaultDestination(activeMQTopic);
this.cachedJmsTemplate.setPubSubDomain(true);
}
return this.cachedJmsTemplate;
}
HeartbeatMessageCreator:
class HeartbeatMessageCreator implements MessageCreator {
private final String someID;
HeartbeatMessageCreator(final String someID) {
this.someID = someID;
}
@Override
public Message createMessage(final Session session) throws JMSException {
final Serializable message = new ZHeartBeat(this.someID);
final Message jmsMessage = session.createObjectMessage(message);
jmsMessage.setJMSType(message.getClass().getName());
jmsMessage.setStringProperty("InternalMessageType", "HeartBeat"); // <-- Setting my separator here
return jmsMessage;
}
The consumer is as follow:
@Component
public class MyListener {
@JmsListener(destination = "${myTopic}", containerFactory = "myJmsContainer", selector = "InternalMessageType = 'HeartBeat'")
public final void onMessage(final Message message) {
...
}
}
In this configuration, the consumer never sees the messages coming in, but if I remove the selector part from the @JmsListener annotation, they are delivered. I am not sure what I am doing wrong here. Any idea ?