activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prademak <p.radema...@huizemolenaar.nl>
Subject Setting message selector synchronously?
Date Tue, 31 Mar 2009 13:13:49 GMT

I'm setting the message selector for a non-persistent topic subscription at
runtime via the
ActiveMQActivationSpec.setMessageSelector and then restarting the
org.jencks.JCAConnector as follows: 

...
logger.info("Setting selector to: " + selector);
activemqActivationSpec.setMessageSelector(selector);
jcaConnector.destroy();
jcaConnector.setActivationSpec(activemqActivationSpec);
jcaConnector.start();
Thread.sleep(WAIT_FOR_SELECTOR_SET_MS); // Wait for the selector to be
set/activated on the broker
...

(I'm using ActiveMQ 5.2.0 and Jencks 2.1)			

Apparently, the message selector is set asynchronously, since when in my
tests I directly start sending messages after the call to
setMessageSelector(..) and restarting the connector, I still receive
messages that should have been rejected based on the new selector. However,
if I wait for a few seconds, and then start sending the messages, everything
seems to be working fine. 

I ran into the same issue when I was using Spring's JmsTemplate +
DefaultMessageListenerContainer. 
(I've moved from JmsTemplate to Jencks to prevent me
from missing messages ( http://activemq.apache.org/jmstemplate-gotchas.html
JmsTemplate gotchas ))  
When using Spring I set the message selector in the following way:

...
DefaultMessagListenerContainer dmlc;
...
String selector = JMSSelectorCreator.createJMSKeySelector(allKeys);
dmlc.setMessageSelector(selector);
if (dmlc.getCacheLevel() > DefaultMessageListenerContainer.CACHE_CONSUMER) {
	logger.warn("Cache level of DefaultMessageListenerContainer is  >
CACHE_CONSUMER, therefore a restart of the container is required to
activate" +
					" a new Message Selector. Consider setting a lower cache level.");
	dmlc.shutdown();
	dmlc.initialize();
}
Thread.sleep(WAIT_FOR_SELECTOR_SET_MS);
...

However, as noted before, waiting for the message to be set/activated was
still required.

Which leads me to my question:
Is there any way of getting notified when the message selector has been
set/activated on the broker? 
(I've looked into Advisory messages, but these don't seems to provide
information on selectors) Or is there a method to set the selector that
blocks until the selector has actually been set/activated on the server?

Thanks,
Peter
 




-- 
View this message in context: http://www.nabble.com/Setting-message-selector-synchronously--tp22804912p22804912.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message