JBOSS JMS subscriber receiving messages with wrong selector
we use the below pseudo implementation for message synchronization between nodes in our Jboss clusters.-
void someMethod() {
Topic topic = (Topic) context.lookup(topicName);
//create separate sessions for publisher and subscriber
this.publisher_session = this.connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
this.publisher = publisher_session.createPublisher(topic);
this.subscriber_session = this.connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
String selector = NAME_PROPERTY + "='" + getTestValue() + "'";
this.subscriber = subscriber_session.createSubscriber(topic,selector,true);
subscriber.setMessageListener(this);
connection.setExceptionListener(this);
this.connection.start();
}
protected void publish(Message message)
{
try
{
synchronized (publisher_session)
{
ObjectMessage objMessage =
getSession().createObjectMessage(message);
objMessage.setStringProperty(NAME_PROPERTY, getTestValue());
getPublisher().publish(objMessage);
}
}
catch (JMSException e)
{
logger.error("Failed to publish message: " + message + " for "
+ getTestValue(), e);
}
}
public void onMessage(Message message)
{
// Validate type
if (!(message instanceof ObjectMessage))
{
throw new IllegalArgumentException
("message not instanceof ObjectMessage: " + message.getClass());
}
ObjectMessage objectMessage = (ObjectMessage) message;
try
{
// Validate selector
if (!objectMessage.getStringProperty
(NAME_PROPERTY).equals(getTestValue()))
{
throw new IllegalArgumentException
("Selector mechanism failed: received message regarding "
+ objectMessage.getStringProperty(NAME_PROPERTY)); <========== THIS EXCEPTION GETS THROWN
}
// Further code
}
catch (JMSException ex)
{
logger.error("Problem getting message for " + getTestValue(), ex);
}
}
Expectation here is that since selector matches the value of objMessage.setStringProperty(NAME_PROPERTY, getTestValue()), respective messages will arrive for subscriber and then the validation will pass.
But this is not happening.
The onMessage() method keeps throwing exception for some time and after restart, starts behaving fine, till it misbehaves once again. Currently running in JBOSS EAP 6.0.1