{"id":28348,"date":"2015-11-05T11:00:42","date_gmt":"2015-11-05T09:00:42","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=28348"},"modified":"2019-03-04T10:36:08","modified_gmt":"2019-03-04T08:36:08","slug":"jms-queue-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/","title":{"rendered":"JMS Queue Example"},"content":{"rendered":"<p>JMS Message queue is a destination to which producers send messages. Consumer connects to the broker to receive the message sitting in the queue. Queue is used in point-to-point messaging. In point-to-point messaging, there may be more than one receiver connected to the queue but each message in the queue may only be consumed by one of the queue&#8217;s receivers.<\/p>\n<p>The messages can be sent and received either synchronously or asynchronously.<\/p>\n<p>In this article, we will see some examples of JMS Queue.<\/p>\n<h2>1. Dependencies<\/h2>\n<p>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.<\/p>\n<p><span style=\"text-decoration: underline\"><em>pom.xml:<\/em><\/span><\/p>\n<pre class=\"brush:xml\">&lt;project xmlns=\"http:\/\/maven.apache.org\/POM\/4.0.0\" xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\"\n\txsi:schemaLocation=\"http:\/\/maven.apache.org\/POM\/4.0.0 http:\/\/maven.apache.org\/xsd\/maven-4.0.0.xsd\"&gt;\n\t&lt;modelVersion&gt;4.0.0&lt;\/modelVersion&gt;\n\t&lt;groupId&gt;com.javacodegeeks.jms&lt;\/groupId&gt;\n\t&lt;artifactId&gt;springJmsQueue&lt;\/artifactId&gt;\n\t&lt;version&gt;0.0.1-SNAPSHOT&lt;\/version&gt;\n\t&lt;dependencies&gt;\n\t\t&lt;dependency&gt;\n\t\t\t&lt;groupId&gt;org.apache.activemq&lt;\/groupId&gt;\n\t\t\t&lt;artifactId&gt;activemq-all&lt;\/artifactId&gt;\n\t\t\t&lt;version&gt;5.12.0&lt;\/version&gt;\n\t\t&lt;\/dependency&gt;\n\t&lt;\/dependencies&gt;\n\t\n&lt;\/project&gt;\n<\/pre>\n<\/p>\n<h2>2. Creating a Queue<\/h2>\n<p>First let&#8217;s see how to create a queue.<\/p>\n<p>In order to create a queue object, you need to first create a session and then call <code>createQueue()<\/code> on the session object. You need to pass the queue name to it.<\/p>\n<pre class=\"brush:java\">Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);\nQueue queue = session.createQueue(\"customerQueue\");\n<\/pre>\n<p>The queue stores all messages until they\u2019re delivered or until they expire.<\/p>\n<h2>3. Sending message to a Queue<\/h2>\n<p>Now that we have a queue object, let&#8217;s send a message to it.<\/p>\n<pre class=\"brush:java\">MessageProducer producer = session.createProducer(queue);\nproducer.send(msg);\n<\/pre>\n<p>As you can see from above, a producer sends a message to the queue.<\/p>\n<h2>4. Receive message from Queue<\/h2>\n<p>Each message received on the queue is delivered once and only once to a single consumer which is why this style of messaging is called point-to-point messaging. Consumer will first connect to the broker to receive the message from the queue. Just like the producer, consumer also needs a session using which it will connect to the queue.<\/p>\n<pre class=\"brush:java\">MessageConsumer consumer = session.createConsumer(queue);\nconnection.start();\n<\/pre>\n<p>Note that connection is started so that any message listener registered will get the notification as soon as a message lands in the queue.<\/p>\n<p>Consumer receives the message using <code>MessageConsumer.receive()<\/code> method or asynchronously by registering a <code>MessageListener<\/code> implementation using the <code>MessageConsumer.setMessageListener()<\/code> method. Multiple consumers can be registered on a single queue but only one consumer will receive a given message.<\/p>\n<pre class=\"brush:java\">TextMessage textMsg = (TextMessage) consumer.receive();\nSystem.out.println(textMsg);\nSystem.out.println(\"Received: \" + textMsg.getText());\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>JmsMessageQueueExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URI;\nimport java.net.URISyntaxException;\n\nimport javax.jms.Connection;\nimport javax.jms.ConnectionFactory;\nimport javax.jms.Message;\nimport javax.jms.MessageConsumer;\nimport javax.jms.MessageProducer;\nimport javax.jms.Queue;\nimport javax.jms.Session;\nimport javax.jms.TextMessage;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\nimport org.apache.activemq.broker.BrokerFactory;\nimport org.apache.activemq.broker.BrokerService;\n\npublic class JmsMessageQueueExample {\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\n\t\tBrokerService broker = BrokerFactory.createBroker(new URI(\n\t\t\t\t\"broker:(tcp:\/\/localhost:61616)\"));\n\t\tbroker.start();\n\t\tConnection connection = null;\n\t\ttry {\n\t\t\t\/\/ Producer\n\t\t\tConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\t\"tcp:\/\/localhost:61616\");\n\t\t\tconnection = connectionFactory.createConnection();\n\t\t\tSession session = connection.createSession(false,\n\t\t\t\t\tSession.AUTO_ACKNOWLEDGE);\n\t\t\tQueue queue = session.createQueue(\"customerQueue\");\n\t\t\tString payload = \"Important Task\";\n\t\t\tMessage msg = session.createTextMessage(payload);\n\t\t\tMessageProducer producer = session.createProducer(queue);\n\t\t\tSystem.out.println(\"Sending text '\" + payload + \"'\");\n\t\t\tproducer.send(msg);\n\n\t\t\t\/\/ Consumer\n\t\t\tMessageConsumer consumer = session.createConsumer(queue);\n\t\t\tconnection.start();\n\t\t\tTextMessage textMsg = (TextMessage) consumer.receive();\n\t\t\tSystem.out.println(textMsg);\n\t\t\tSystem.out.println(\"Received: \" + textMsg.getText());\n\t\t\tsession.close();\n\t\t} finally {\n\t\t\tif (connection != null) {\n\t\t\t\tconnection.close();\n\t\t\t}\n                        broker.stop();\n\t\t}\n\t}\n\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\"> INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage] started\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\KahaDB]\n INFO | KahaDB is version 6\n INFO | Recovering from the journal @1:169756\n INFO | Recovery replayed 1 operations from the journal in 0.011 seconds.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-57715-1446468253396-0:1) is starting\n INFO | Listening for connections at: tcp:\/\/127.0.0.1:61616\n INFO | Connector tcp:\/\/127.0.0.1:61616 started\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-57715-1446468253396-0:1) started\n INFO | For help or more information please see: http:\/\/activemq.apache.org\n WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\KahaDB only has 34512 mb of usable space - resetting to maximum available disk space: 34512 mb\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage only has 34512 mb of usable space - resetting to maximum available 34512 mb.\nSending text 'Important Task'\nActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:INMAA1-L1005-57715-1446468253396-3:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57715-1446468253396-3:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1446468253638, arrival = 0, brokerInTime = 1446468253639, brokerOutTime = 1446468253663, 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@77be656f, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Important Task}\nReceived: Important Task\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-57715-1446468253396-0:1) is shutting down\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage] stopped\n INFO | Stopping async queue tasks\n INFO | Stopping async topic tasks\n INFO | Stopped KahaDB\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-57715-1446468253396-0:1) uptime 0.906 seconds\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-57715-1446468253396-0:1) is shutdown\n<\/pre>\n<h2>5. Receiving a message Asynchronously<\/h2>\n<p>In our last example, we have seen consumer receiving message explicitly using MessageConsumer.receive(). In in this section, we will see ow a consumer can register a message listener. Instead of explicitly receiving the message, consumer just registers a message listener. Moment a message lands in the queue, the broker passes on the message to one of the message listeners.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Let&#8217;s first create a message listener.<\/p>\n<p>A message listener is created by implementing <code>javax.jms.MessageListener<\/code> and implementing <code>onMessage(Message)<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>ConsumerMessageListener:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport javax.jms.JMSException;\nimport javax.jms.Message;\nimport javax.jms.MessageListener;\nimport javax.jms.TextMessage;\n\npublic class ConsumerMessageListener implements MessageListener {\n\tprivate String consumerName;\n\tpublic ConsumerMessageListener(String consumerName) {\n\t\tthis.consumerName = consumerName;\n\t}\n\n\tpublic void onMessage(Message message) {\n\t\tTextMessage textMessage = (TextMessage) message;\n\t\ttry {\n\t\t\tSystem.out.println(consumerName + \" received \" + textMessage.getText());\n\t\t} catch (JMSException e) {\t\t\t\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n}\n<\/pre>\n<p>Consumer will register its own message listener. It will pass a name to it so we know which consumer is consuming the message.<\/p>\n<pre class=\"brush:java\">\/\/ Consumer\nMessageConsumer consumer = session.createConsumer(queue);\nconsumer.setMessageListener(new ConsumerMessageListener(\"Consumer\"));\n<\/pre>\n<p>Next, we need to make sure <code>start()<\/code> is called on connection object. This is an important step for the broker to make sure the message is passed on to one of the listeners.<\/p>\n<pre class=\"brush:java\">connection.start();\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>JmsMessageAsynchronousQueueExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URI;\nimport java.net.URISyntaxException;\n\nimport javax.jms.Connection;\nimport javax.jms.ConnectionFactory;\nimport javax.jms.Message;\nimport javax.jms.MessageConsumer;\nimport javax.jms.MessageProducer;\nimport javax.jms.Queue;\nimport javax.jms.Session;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\nimport org.apache.activemq.broker.BrokerFactory;\nimport org.apache.activemq.broker.BrokerService;\n\npublic class JmsMessageAsynchronousQueueExample {\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\n\t\tBrokerService broker = BrokerFactory.createBroker(new URI(\n\t\t\t\t\"broker:(tcp:\/\/localhost:61616)\"));\n\t\tbroker.start();\n\t\tConnection connection = null;\n\t\ttry {\n\t\t\t\/\/ Producer\n\t\t\tConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\t\"tcp:\/\/localhost:61616\");\n\t\t\tconnection = connectionFactory.createConnection();\n\t\t\tSession session = connection.createSession(false,\n\t\t\t\t\tSession.AUTO_ACKNOWLEDGE);\n\t\t\tQueue queue = session.createQueue(\"customerQueue\");\n\t\t\tString payload = \"Important Task\";\n\t\t\tMessage msg = session.createTextMessage(payload);\n\t\t\tMessageProducer producer = session.createProducer(queue);\n\t\t\tSystem.out.println(\"Sending text '\" + payload + \"'\");\n\t\t\tproducer.send(msg);\n\n\t\t\t\/\/ Consumer\n\t\t\tMessageConsumer consumer = session.createConsumer(queue);\n\t\t\tconsumer.setMessageListener(new ConsumerMessageListener(\"Consumer\"));\n\t\t\tconnection.start();\n\t\t\tThread.sleep(1000);\n\t\t\tsession.close();\n\t\t} finally {\n\t\t\tif (connection != null) {\n\t\t\t\tconnection.close();\n\t\t\t}\n\t\t\tbroker.stop();\n\t\t}\n\t}\n\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\"> INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage] started\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\KahaDB]\n INFO | KahaDB is version 6\n INFO | Recovering from the journal @1:153817\n INFO | Recovery replayed 1 operations from the journal in 0.011 seconds.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56230-1446467650870-0:1) is starting\n INFO | Listening for connections at: tcp:\/\/127.0.0.1:61616\n INFO | Connector tcp:\/\/127.0.0.1:61616 started\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56230-1446467650870-0:1) started\n INFO | For help or more information please see: http:\/\/activemq.apache.org\n WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\KahaDB only has 34515 mb of usable space - resetting to maximum available disk space: 34515 mb\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage only has 34515 mb of usable space - resetting to maximum available 34515 mb.\nSending text 'Important Task'\nConsumer received Important Task\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56230-1446467650870-0:1) is shutting down\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage] stopped\n INFO | Stopping async queue tasks\n INFO | Stopping async topic tasks\n INFO | Stopped KahaDB\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56230-1446467650870-0:1) uptime 1.928 seconds\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56230-1446467650870-0:1) is shutdown\n<\/pre>\n<h2>6. Multiple Consumers<\/h2>\n<p>The workload of message processing can be distributed among more than one consumer. When multiple receivers are attached to a queue, each message in the queue is delivered to one receiver. The absolute order of messages cannot be guaranteed, since one receiver may process messages faster than another.<\/p>\n<p>Storage for queue is on the basis of first in, first out order (FIFO). One message is dispatched to a single consumer at a time. Only when that message has been consumed and acknowledged, it is deleted from the queue.<br \/>\nIn the below example, we create multiple consumers, each one registered with a message listener. Next, we create a producer and make it send multiple messages. Each message is received by just one consumer and the order in which the messages are received is according to FIFO.<\/p>\n<p>Each consumer will register its own message listener. It will pass a name to it so we know which consumer is consuming the message.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JmsMultipleCustomersMessageQueueExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URI;\nimport java.net.URISyntaxException;\n\nimport javax.jms.Connection;\nimport javax.jms.ConnectionFactory;\nimport javax.jms.Message;\nimport javax.jms.MessageConsumer;\nimport javax.jms.MessageProducer;\nimport javax.jms.Queue;\nimport javax.jms.Session;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\nimport org.apache.activemq.broker.BrokerFactory;\nimport org.apache.activemq.broker.BrokerService;\n\npublic class JmsMultipleCustomersMessageQueueExample {\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\n\t\tBrokerService broker = BrokerFactory.createBroker(new URI(\n\t\t\t\t\"broker:(tcp:\/\/localhost:61616)\"));\n\t\tbroker.start();\n\t\tConnection connection = null;\n\t\ttry {\n\t\t\t\/\/ Producer\n\t\t\tConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\t\"tcp:\/\/localhost:61616\");\n\t\t\tconnection = connectionFactory.createConnection();\n\t\t\tSession session = connection.createSession(false,\n\t\t\t\t\tSession.AUTO_ACKNOWLEDGE);\n\t\t\tQueue queue = session.createQueue(\"customerQueue\");\n\n\t\t\t\/\/ Consumer\n\t\t\tfor (int i = 0; i &lt; 4; i++) {\n\t\t\t\tMessageConsumer consumer = session.createConsumer(queue);\n\t\t\t\tconsumer.setMessageListener(new ConsumerMessageListener(\n\t\t\t\t\t\t\"Consumer \" + i));\n\t\t\t}\n\t\t\tconnection.start();\n\n\t\t\tString basePayload = \"Important Task\";\n\t\t\tMessageProducer producer = session.createProducer(queue);\n\t\t\tfor (int i = 0; i &lt; 10; i++) {\n\t\t\t\tString payload = basePayload + i;\n\t\t\t\tMessage msg = session.createTextMessage(payload);\n\t\t\t\tSystem.out.println(\"Sending text '\" + payload + \"'\");\n\t\t\t\tproducer.send(msg);\n\t\t\t}\n\n\t\t\tThread.sleep(1000);\n\t\t\tsession.close();\n\t\t} finally {\n\t\t\tif (connection != null) {\n\t\t\t\tconnection.close();\n\t\t\t}\n\t\t\tbroker.stop();\n\t\t}\n\t}\n\n}\n<\/pre>\n<p>You can see from output,&nbsp;the messages are delivered in a round-robin fashion between all the message consumers.[ulp id=&#8217;meNHaG2axN7AsWAw&#8217;]<\/p>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\"> INFO | PListStore:[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage] started\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\KahaDB]\n INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\n INFO | KahaDB is version 6\n INFO | Recovering from the journal @1:173161\n INFO | Recovery replayed 1 operations from the journal in 0.012 seconds.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-62099-1446469937715-0:1) is starting\n INFO | Listening for connections at: tcp:\/\/127.0.0.1:61616\n INFO | Connector tcp:\/\/127.0.0.1:61616 started\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-62099-1446469937715-0:1) started\n INFO | For help or more information please see: http:\/\/activemq.apache.org\n WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\KahaDB only has 34555 mb of usable space - resetting to maximum available disk space: 34556 mb\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage only has 34555 mb of usable space - resetting to maximum available 34555 mb.\nSending text 'Important Task0'\nConsumer 0 received Important Task0\nSending text 'Important Task1'\nConsumer 1 received Important Task1\nSending text 'Important Task2'\nConsumer 2 received Important Task2\nSending text 'Important Task3'\nConsumer 3 received Important Task3\nSending text 'Important Task4'\nConsumer 0 received Important Task4\nSending text 'Important Task5'\nConsumer 1 received Important Task5\nSending text 'Important Task6'\nConsumer 2 received Important Task6\nSending text 'Important Task7'\nConsumer 3 received Important Task7\nSending text 'Important Task8'\nConsumer 0 received Important Task8\nSending text 'Important Task9'\nConsumer 1 received Important Task9\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-62099-1446469937715-0:1) is shutting down\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage] stopped\n INFO | Stopping async queue tasks\n INFO | Stopping async topic tasks\n INFO | Stopped KahaDB\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-62099-1446469937715-0:1) uptime 2.009 seconds\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-62099-1446469937715-0:1) is shutdown\n<\/pre>\n<h2>7. Creating a Temporary Queue<\/h2>\n<p>A temporary queue is a queue which can only be consumed by the JMS client that created it. It is created using the <code>createTemporaryQueue()<\/code> method on <code>QueueSession\/code&gt; object.<\/code><\/p>\n<pre class=\"brush:java\">QueueSession.createTemporaryQueue();\n<\/pre>\n<h2>8. Browsing a Queue<\/h2>\n<p>JMS allows you to peek ahead at pending messages on a Queue without actually consuming them using <code>QueueBrowser<\/code> object. Since we can browse through the messages without actually consuming them, this is very unique and important feature to point-to-point messaging.<\/p>\n<p>We create the <code>QueueBrowser<\/code> object using the below statement on session object.<\/p>\n<pre class=\"brush:java\">QueueBrowser browser = session.createBrowser(queue);\n<\/pre>\n<p>As you can see <code>createBrowser()<\/code> takes the <code>Queue<\/code> object that we are interested to browse.<\/p>\n<p>To enumerate through the messages, we will call <code>QueueBrowser.getEnumeration()<\/code>.<\/p>\n<pre class=\"brush:java\">Enumeration e = browser.getEnumeration();\nwhile (e.hasMoreElements()) {\n    TextMessage message = (TextMessage) e.nextElement();\n    System.out.println(\"Get [\" + message.getText() + \"]\");\n}\n<\/pre>\n<p>When we are done with the browser we should close it.<\/p>\n<pre class=\"brush:java\">QueueBrowser.close();\n<\/pre>\n<p>In the below example, we create a producer and post a bunch of messages to a queue. Next we create a consumer. In order to browse, we create a <code>QueueBrowser<\/code> object and navigate through the messages.<\/p>\n<p>Finally, we call <code>consumer.receive()<\/code> to receive one of the messages from queue.<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URI;\nimport java.net.URISyntaxException;\nimport java.util.Enumeration;\n\nimport javax.jms.Connection;\nimport javax.jms.ConnectionFactory;\nimport javax.jms.Message;\nimport javax.jms.MessageConsumer;\nimport javax.jms.MessageProducer;\nimport javax.jms.Queue;\nimport javax.jms.QueueBrowser;\nimport javax.jms.Session;\nimport javax.jms.TextMessage;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\nimport org.apache.activemq.broker.BrokerFactory;\nimport org.apache.activemq.broker.BrokerService;\n\npublic class JmsBrowseQueueExample {\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\n\t\tBrokerService broker = BrokerFactory.createBroker(new URI(\n\t\t\t\t\"broker:(tcp:\/\/localhost:61616)\"));\n\t\tbroker.start();\n\t\tConnection connection = null;\n\t\ttry {\n\t\t\t\/\/ Producer\n\t\t\tConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\t\"tcp:\/\/localhost:61616\");\n\t\t\tconnection = connectionFactory.createConnection();\n\t\t\tSession session = connection.createSession(false,\n\t\t\t\t\tSession.AUTO_ACKNOWLEDGE);\n\t\t\tQueue queue = session.createQueue(\"browseQueue\");\n\n\t\t\tString basePayload = \"A\";\n\t\t\tMessageProducer producer = session.createProducer(queue);\n\t\t\tfor (int i = 0; i &lt; 4; i++) {\n\t\t\t\tString payload = basePayload + i;\n\t\t\t\tMessage msg = session.createTextMessage(payload);\n\t\t\t\tSystem.out.println(\"Sending text '\" + payload + \"'\");\n\t\t\t\tproducer.send(msg);\n\t\t\t}\n\n\t\t\tMessageConsumer consumer = session.createConsumer(queue);\n\t\t\tconnection.start();\n\t\t\t\n\t\t\tSystem.out.println(\"Browse through the elements in queue\");\n\t\t\tQueueBrowser browser = session.createBrowser(queue);\n\t\t\tEnumeration e = browser.getEnumeration();\n\t\t\twhile (e.hasMoreElements()) {\n\t\t\t\tTextMessage message = (TextMessage) e.nextElement();\n\t\t\t\tSystem.out.println(\"Get [\" + message.getText() + \"]\");\n\t\t\t}\n\t\t\tSystem.out.println(\"Done\");\n\t\t\tbrowser.close();\n\t\t\t\n\t\t\tTextMessage textMsg = (TextMessage) consumer.receive();\n\t\t\tSystem.out.println(textMsg);\n\t\t\tSystem.out.println(\"Received: \" + textMsg.getText());\n\t\t\tsession.close();\n\t\t} finally {\n\t\t\tif (connection != null) {\n\t\t\t\tconnection.close();\n\t\t\t}\n\t\t\tbroker.stop();\n\t\t}\n\t}\n\n}\n<\/pre>\n<p>Messages obtained from a QueueBrowser are copies of messages contained in the queue and are not considered to be consumed as they are merely for browsing. Below is the output.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\"> INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage] started\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\KahaDB]\n INFO | KahaDB is version 6\n INFO | Recovering from the journal @1:260856\n INFO | Recovery replayed 1 operations from the journal in 0.012 seconds.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53401-1446474681874-0:1) is starting\n INFO | Listening for connections at: tcp:\/\/127.0.0.1:61616\n INFO | Connector tcp:\/\/127.0.0.1:61616 started\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53401-1446474681874-0:1) started\n INFO | For help or more information please see: http:\/\/activemq.apache.org\n WARN | Store limit is 102400 mb (current store usage is 0 mb). The data directory: C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\KahaDB only has 34326 mb of usable space - resetting to maximum available disk space: 34327 mb\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage only has 34326 mb of usable space - resetting to maximum available 34326 mb.\nSending text 'A0'\nSending text 'A1'\nSending text 'A2'\nSending text 'A3'\nBrowse through the elements in queue\nGet [A0]\nGet [A1]\nGet [A2]\nGet [A3]\nDone\nActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:INMAA1-L1005-53401-1446474681874-3:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-53401-1446474681874-3:1:1:1, destination = queue:\/\/browseQueue, transactionId = null, expiration = 0, timestamp = 1446474682340, arrival = 0, brokerInTime = 1446474682341, brokerOutTime = 1446474682383, 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@ba8d91c, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = A0}\nReceived: A0\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53401-1446474681874-0:1) is shutting down\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsMessageTypesExample\\activemq-data\\localhost\\tmp_storage] stopped\n INFO | Stopping async queue tasks\n INFO | Stopping async topic tasks\n INFO | Stopped KahaDB\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53401-1446474681874-0:1) uptime 1.446 seconds\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53401-1446474681874-0:1) is shutdown\n<\/pre>\n<h2>9. Download the Eclipse Project<\/h2>\n<p>This was an example about JMS Queue.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/11\/jmsMessageQueueExample.zip\"><strong>jmsMessageQueueExample.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>JMS Message queue is a destination to which producers send messages. Consumer connects to the broker to receive the message sitting in the queue. Queue is used in point-to-point messaging. In point-to-point messaging, there may be more than one receiver connected to the queue but each message in the queue may only be consumed by &hellip;<\/p>\n","protected":false},"author":38,"featured_media":1240,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19],"tags":[],"class_list":["post-28348","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-jms"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>JMS Queue Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"JMS Message queue is a destination to which producers send messages. Consumer connects to the broker to receive the message sitting in the queue. Queue is\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JMS Queue Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"JMS Message queue is a destination to which producers send messages. Consumer connects to the broker to receive the message sitting in the queue. Queue is\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2015-11-05T09:00:42+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-04T08:36:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ram Mokkapaty\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ram Mokkapaty\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"15 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/\"},\"author\":{\"name\":\"Ram Mokkapaty\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8\"},\"headline\":\"JMS Queue Example\",\"datePublished\":\"2015-11-05T09:00:42+00:00\",\"dateModified\":\"2019-03-04T08:36:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/\"},\"wordCount\":883,\"commentCount\":4,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"articleSection\":[\"jms\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/\",\"name\":\"JMS Queue Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"datePublished\":\"2015-11-05T09:00:42+00:00\",\"dateModified\":\"2019-03-04T08:36:08+00:00\",\"description\":\"JMS Message queue is a destination to which producers send messages. Consumer connects to the broker to receive the message sitting in the queue. Queue is\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"jms\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jms\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"JMS Queue Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8\",\"name\":\"Ram Mokkapaty\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Ram-Mokkapaty-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Ram-Mokkapaty-96x96.jpg\",\"caption\":\"Ram Mokkapaty\"},\"description\":\"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.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\/\",\"https:\/\/in.linkedin.com\/pub\/ram-satish-mokkapaty\/18\/123\/52b\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/ram-mokkapaty\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"JMS Queue Example - Java Code Geeks","description":"JMS Message queue is a destination to which producers send messages. Consumer connects to the broker to receive the message sitting in the queue. Queue is","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/","og_locale":"en_US","og_type":"article","og_title":"JMS Queue Example - Java Code Geeks","og_description":"JMS Message queue is a destination to which producers send messages. Consumer connects to the broker to receive the message sitting in the queue. Queue is","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-11-05T09:00:42+00:00","article_modified_time":"2019-03-04T08:36:08+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","type":"image\/jpeg"}],"author":"Ram Mokkapaty","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ram Mokkapaty","Est. reading time":"15 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/"},"author":{"name":"Ram Mokkapaty","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8"},"headline":"JMS Queue Example","datePublished":"2015-11-05T09:00:42+00:00","dateModified":"2019-03-04T08:36:08+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/"},"wordCount":883,"commentCount":4,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","articleSection":["jms"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/","name":"JMS Queue Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","datePublished":"2015-11-05T09:00:42+00:00","dateModified":"2019-03-04T08:36:08+00:00","description":"JMS Message queue is a destination to which producers send messages. Consumer connects to the broker to receive the message sitting in the queue. Queue is","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-queue-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"jms","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/jms\/"},{"@type":"ListItem","position":5,"name":"JMS Queue Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8","name":"Ram Mokkapaty","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Ram-Mokkapaty-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2014\/12\/Ram-Mokkapaty-96x96.jpg","caption":"Ram Mokkapaty"},"description":"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.","sameAs":["http:\/\/www.javacodegeeks.com\/","https:\/\/in.linkedin.com\/pub\/ram-satish-mokkapaty\/18\/123\/52b"],"url":"https:\/\/examples.javacodegeeks.com\/author\/ram-mokkapaty\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=28348"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28348\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1240"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=28348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=28348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=28348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}