[jboss-dev-forums] [Design of JBoss Remoting, Unified Invokers] - Message Selectors on QueueBrowser and MessageConsumer

shuffler16 do-not-reply at jboss.com
Sun Mar 29 19:16:45 EDT 2009


Hi all,

We are using JBoss AS 4.0.5 and JBossMQ. Currently we are using spring to consume and browse a JMS Queue.

The problem is when we are using selectors on QueueBrowser, messages are returned properly while when using MessageConsumer, none is returned.

Here is the snippet for QueueBrowser and MessageConsumer, jmsTemplate is used on both.

// selector type
final String selector = "documentType = 'text'";

// QueueBrowser
jmsTemplate.execute(new SessionCallback() {
			@SuppressWarnings("unchecked")
			public Object doInJms(Session queueSession) throws JMSException {

				QueueBrowser browser = queueSession.createBrowser(queue, selector);
				try {
					Enumeration enumeration = browser.getEnumeration();
					while(enumeration.hasMoreElements()) {
						TextMessage textMessage = (TextMessage)enumeration.nextElement();
						System.out.println(textMessage.getStringProperty("documentType") + "-" + textMessage.getText());
					}
				} catch(Exception ex) {
					System.out.println(ex.getMessage());
					ex.printStackTrace();
				} finally {
					browser.close();
				}
				return null;
			}
		});

// MessageConsumer
jmsTemplate.execute(new SessionCallback() {
			@SuppressWarnings("unchecked")
			public Object doInJms(Session queueSession) throws JMSException {	
				
				MessageConsumer consumer = queueSession.createConsumer(queue, selector);
				try {
					Message message = null;
					while((message = consumer.receive(1000)) != null) {
						System.out.println(((TextMessage)message).getText());
					}
				} finally {
					consumer.close();
				}
				
				
		});

Thanks..

View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=4221798#4221798

Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=4221798



More information about the jboss-dev-forums mailing list