Home » Enterprise Java » jms » JMS QueueBrowser Example

About Ram Mokkapaty

Ram Mokkapaty
Ram holds a master's degree in Machine Design from IT B.H.U. His expertise lies in test driven development and re-factoring. He is passionate about open source technologies and actively blogs on various java and open-source technologies like spring. He works as a principal Engineer in the logistics domain.

JMS QueueBrowser Example

A point-to-point messaging queue contains messages to be consumed by clients interested in the specific destination queue. If one wants to simply monitor the messages without actually consuming them then getting hold of QueueObject will allow one to peek ahead at the pending messages.

In this article, we will see an examples of QueueBrowser object.

1. Dependencies

In order to send and receive JMS messages to and from a JMS message broker, we need to include the message service library. In this example we are using activeMq so our pom.xml will have dependencies related to spring as well as activeMQ.

pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.javacodegeeks.jms</groupId>
	<artifactId>springJmsQueue</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<dependencies>
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-all</artifactId>
			<version>5.12.0</version>
		</dependency>
	</dependencies>
	
</project>

2. Starting the JMS Provider

JMS is a specification and not an actual product. A JMS provider such as ActiveMQ, IBM, Progress Software, or even Sun provides a messaging product that implements the specification. In our examples, we will be using ActiveMQ as JMS Provider. Getting started with ActiveMQ isn’t difficult. You simply need to start up the broker and make sure that it’s capable of accepting connections and sending messages.

In the below example, the broker is started as a server listening on port 61616. The JMS Clients willing to connect to the broker will be using the TCP protocol (tcp://localhost:61616). Since the broker and JMS clients are running in the same machine, we have used localhost.

BrokerLauncehr:

package com.javacodegeeks.jms;

import java.net.URI;
import java.net.URISyntaxException;

import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;

public class BrokerLauncher {
	public static void main(String[] args) throws URISyntaxException, Exception {
		BrokerService broker = BrokerFactory.createBroker(new URI(
				"broker:(tcp://localhost:61616)"));
		broker.start();		
	}
}

Output:

 INFO | JMX consoles can connect to service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi
 INFO | PListStore:[C:\javacodegeeks_ws\jmsQueueBrowserExample\activemq-data\localhost\tmp_storage] started
 INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\javacodegeeks_ws\jmsQueueBrowserExample\activemq-data\localhost\KahaDB]
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-57531-1450761099016-0:1) is starting
 INFO | Listening for connections at: tcp://127.0.0.1:61616
 INFO | Connector tcp://127.0.0.1:61616 started
 INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-57531-1450761099016-0:1) started
 INFO | For help or more information please see: http://activemq.apache.org
 WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: C:\javacodegeeks_ws\jmsQueueBrowserExample\activemq-data\localhost\KahaDB only has 30295 mb of usable space - resetting to maximum available disk space: 30295 mb
 WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\javacodegeeks_ws\jmsQueueBrowserExample\activemq-data\localhost\tmp_storage only has 30295 mb of usable space - resetting to maximum available 30295 mb.

3. Creating QueueBrowser

A QueueBrowser can be useful for monitoring the contents of a queue from an administration tool, or for browsing through multiple messages to locate a specific message that one is interested in.

A QueueBrowser is created using createBrowser() methods in Session object. It needs the Queue object which needs to be browsed. If one wants to further filter then a message selector can also be passed in.

A message selector holds an expression meant for filtering messages. Only those messages will be delivered whose properties match the message selector expression.

Session:

public interface Session extends Runnable {
...
    QueueBrowser createBrowser(Queue queue) throws JMSException;

    QueueBrowser createBrowser(Queue queue, String messageSelector)
        throws JMSException;
...
}
QueueBrowser browser = session.createBrowser(queue);

4. QueueBrowser API

A queue browser implements the QueueBrowser interface.

QueueBrowser:

public interface QueueBrowser {
    Queue getQueue() throws JMSException;
    String getMessageSelector() throws JMSException;
    Enumeration getEnumeration() throws JMSException;
    void close() throws JMSException;
}
  1. getQueue() – returns the queue that needs to be browsed
  2. getMessageSelector() – returns the message selector expression that is used to filter the messages in queue.
  3. getEnumeration() returns the enumeration object that will be used to iterate through the queue
  4. close() – close method should be
    called whenever a browser is no longer needed to free any resources that the JMS provider may
    have allocated on behalf of this browser.

5. QueueBrowser Example

In order to browse the messages, we need to call createQueueBrowser( ) on Session object. We passed in the Queue object that needs to be browsed.

The QueueBrowser object contains a java.util.Enumeration which is used to iterate through the queue.

We will send some message to the queue and then create a queue browser object to enumerate through the messages. Next, we will close the queue browser object. Finally, we will receive all the messages from the queue.

JmsQueueBrowseExample:

package com.javacodegeeks.jms;

import java.net.URISyntaxException;
import java.util.Enumeration;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

public class JmsQueueBrowseExample {
	public static void main(String[] args) throws URISyntaxException, Exception {
		Connection connection = null;
		try {
			// Producer
			ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
					"tcp://localhost:61616");
			connection = connectionFactory.createConnection();
			Session session = connection.createSession(false,
					Session.AUTO_ACKNOWLEDGE);
			Queue queue = session.createQueue("browseQueue");
			MessageProducer producer = session.createProducer(queue);
			String task = "Task";
			for (int i = 0; i < 10; i++) {
				String payload = task + i;
				Message msg = session.createTextMessage(payload);
				System.out.println("Sending text '" + payload + "'");
				producer.send(msg);
			}

			MessageConsumer consumer = session.createConsumer(queue);
			connection.start();

			System.out.println("Browse through the elements in queue");
			QueueBrowser browser = session.createBrowser(queue);
			Enumeration e = browser.getEnumeration();
			while (e.hasMoreElements()) {
				TextMessage message = (TextMessage) e.nextElement();
				System.out.println("Browse [" + message.getText() + "]");
			}
			System.out.println("Done");
			browser.close();

			for (int i = 0; i < 10; i++) {
				TextMessage textMsg = (TextMessage) consumer.receive();
				System.out.println(textMsg);
				System.out.println("Received: " + textMsg.getText());
			}
			session.close();
		} finally {
			if (connection != null) {
				connection.close();
			}
		}
	}

}

Output:

Sending text 'Task0'
Sending text 'Task1'
Sending text 'Task2'
Sending text 'Task3'
Sending text 'Task4'
Sending text 'Task5'
Sending text 'Task6'
Sending text 'Task7'
Sending text 'Task8'
Sending text 'Task9'
Browse through the elements in queue
Browse [Task0]
Browse [Task1]
Browse [Task2]
Browse [Task3]
Browse [Task4]
Browse [Task5]
Browse [Task6]
Browse [Task7]
Browse [Task8]
Browse [Task9]
Done
ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226017, arrival = 0, brokerInTime = 1450762226018, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@6b71769e, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task0}
Received: Task0
ActiveMQTextMessage {commandId = 6, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:2, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226025, arrival = 0, brokerInTime = 1450762226025, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@2752f6e2, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task1}
Received: Task1
ActiveMQTextMessage {commandId = 7, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:3, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226027, arrival = 0, brokerInTime = 1450762226028, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@e580929, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task2}
Received: Task2
ActiveMQTextMessage {commandId = 8, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:4, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226030, arrival = 0, brokerInTime = 1450762226030, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@1cd072a9, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task3}
Received: Task3
ActiveMQTextMessage {commandId = 9, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:5, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226033, arrival = 0, brokerInTime = 1450762226033, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@7c75222b, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task4}
Received: Task4
ActiveMQTextMessage {commandId = 10, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:6, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226036, arrival = 0, brokerInTime = 1450762226036, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@4c203ea1, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task5}
Received: Task5
ActiveMQTextMessage {commandId = 11, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:7, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226039, arrival = 0, brokerInTime = 1450762226039, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@27f674d, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task6}
Received: Task6
ActiveMQTextMessage {commandId = 12, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:8, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226042, arrival = 0, brokerInTime = 1450762226042, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@1d251891, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task7}
Received: Task7
ActiveMQTextMessage {commandId = 13, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:9, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226045, arrival = 0, brokerInTime = 1450762226045, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@48140564, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task8}
Received: Task8
ActiveMQTextMessage {commandId = 14, responseRequired = true, messageId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1:10, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58661-1450762225866-1:1:1:1, destination = queue://browseQueue, transactionId = null, expiration = 0, timestamp = 1450762226047, arrival = 0, brokerInTime = 1450762226047, brokerOutTime = 1450762226054, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@58ceff1, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task9}
Received: Task9

6. QueueBrowser Example with Message Selector

In this example we will see the overloaded version of createQueueBrowser() method that takes in Queue as well as messageSelector.

A message selector holds an expression meant for filtering messages. Only those messages will be delivered whose properties match the message selector expression.

For example sake, we will set ‘sequence’ property to ‘even’ for the even sequenced messages.

for (int i = 0; i < 10; i++) {
				String payload = task + i;
				Message msg = session.createTextMessage(payload);
				System.out.println("Sending text '" + payload + "'");
				if (i % 2 == 0) {
					msg.setStringProperty("sequence", "even");
				}
				producer.send(msg);
			}

Suppose we only want to browse the even sequenced messages then the message selector would be "sequence = 'even'".

We will create QueueBrowser using this message selector.

QueueBrowser browser = session.createBrowser(queue,
					"sequence = 'even'");

JmsBrowseQueueMessageSelectorExample:

package com.javacodegeeks.jms;

import java.net.URISyntaxException;
import java.util.Enumeration;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

public class JmsQueueBrowserWithMessageSelectorExample {
	public static void main(String[] args) throws URISyntaxException, Exception {
		Connection connection = null;
		try {
			// Producer
			ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(
					"tcp://localhost:61616");
			connection = connectionFactory.createConnection();
			Session session = connection.createSession(false,
					Session.AUTO_ACKNOWLEDGE);
			Queue queue = session.createQueue("customerQueue");

			MessageProducer producer = session.createProducer(queue);
			String task = "Task";
			for (int i = 0; i < 10; i++) {
				String payload = task + i;
				Message msg = session.createTextMessage(payload);
				System.out.println("Sending text '" + payload + "'");
				if (i % 2 == 0) {
					msg.setStringProperty("sequence", "even");
				}
				producer.send(msg);
			}

			MessageConsumer consumer = session.createConsumer(queue);
			connection.start();

			System.out.println("Browse through the elements in queue");
			QueueBrowser browser = session.createBrowser(queue,
					"sequence = 'even'");
			Enumeration e = browser.getEnumeration();
			while (e.hasMoreElements()) {
				TextMessage message = (TextMessage) e.nextElement();
				System.out.println("Browse [" + message.getText() + "]");
			}
			System.out.println("Done");
			browser.close();

			for (int i = 0; i < 10; i++) {
				TextMessage textMsg = (TextMessage) consumer.receive();
				System.out.println(textMsg);
				System.out.println("Received: " + textMsg.getText());
			}
			session.close();
		} finally {
			if (connection != null) {
				connection.close();
			}
		}
	}

}

A you can see only the even sequenced messages show up in the enumeration object.

Output:

Sending text 'Task0'
Sending text 'Task1'
Sending text 'Task2'
Sending text 'Task3'
Sending text 'Task4'
Sending text 'Task5'
Sending text 'Task6'
Sending text 'Task7'
Sending text 'Task8'
Sending text 'Task9'
Browse through the elements in queue
Browse [Task0]
Browse [Task2]
Browse [Task4]
Browse [Task6]
Browse [Task8]
Done
ActiveMQTextMessage {commandId = 7, responseRequired = true, messageId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1:3, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761421106, arrival = 0, brokerInTime = 1450761421106, brokerOutTime = 1450761525026, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@5ebec15, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task2}
Received: Task2
ActiveMQTextMessage {commandId = 8, responseRequired = true, messageId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1:4, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761421109, arrival = 0, brokerInTime = 1450761421109, brokerOutTime = 1450761525026, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@21bcffb5, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task3}
Received: Task3
ActiveMQTextMessage {commandId = 9, responseRequired = true, messageId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1:5, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761421111, arrival = 0, brokerInTime = 1450761421112, brokerOutTime = 1450761525027, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@380fb434, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task4}
Received: Task4
ActiveMQTextMessage {commandId = 10, responseRequired = true, messageId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1:6, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761421114, arrival = 0, brokerInTime = 1450761421114, brokerOutTime = 1450761525027, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@668bc3d5, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task5}
Received: Task5
ActiveMQTextMessage {commandId = 11, responseRequired = true, messageId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1:7, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761421117, arrival = 0, brokerInTime = 1450761421117, brokerOutTime = 1450761525027, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@3cda1055, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task6}
Received: Task6
ActiveMQTextMessage {commandId = 12, responseRequired = true, messageId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1:8, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761421120, arrival = 0, brokerInTime = 1450761421120, brokerOutTime = 1450761525028, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@7a5d012c, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task7}
Received: Task7
ActiveMQTextMessage {commandId = 13, responseRequired = true, messageId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1:9, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761421123, arrival = 0, brokerInTime = 1450761421123, brokerOutTime = 1450761525028, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@3fb6a447, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task8}
Received: Task8
ActiveMQTextMessage {commandId = 14, responseRequired = true, messageId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1:10, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57862-1450761420954-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761421126, arrival = 0, brokerInTime = 1450761421126, brokerOutTime = 1450761525028, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@79b4d0f, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task9}
Received: Task9
ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:INMAA1-L1005-57943-1450761507228-1:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57943-1450761507228-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761507375, arrival = 0, brokerInTime = 1450761507376, brokerOutTime = 1450761525028, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@5f2050f6, marshalledProperties = org.apache.activemq.util.ByteSequence@3b81a1bc, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {sequence=even}, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task0}
Received: Task0
ActiveMQTextMessage {commandId = 6, responseRequired = true, messageId = ID:INMAA1-L1005-57943-1450761507228-1:1:1:1:2, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57943-1450761507228-1:1:1:1, destination = queue://customerQueue, transactionId = null, expiration = 0, timestamp = 1450761507380, arrival = 0, brokerInTime = 1450761507380, brokerOutTime = 1450761525028, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@64616ca2, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task1}
Received: Task1

7. Download the Eclipse Project

This was an example about JMS QueueBrowser object.

Download
You can download the full source code of this example here: jmsQueueBrowserExample.zip
(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of