{"id":28786,"date":"2015-11-19T15:00:58","date_gmt":"2015-11-19T13:00:58","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=28786"},"modified":"2019-03-04T10:34:55","modified_gmt":"2019-03-04T08:34:55","slug":"jms-client-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/","title":{"rendered":"JMS Client Example"},"content":{"rendered":"<p>The term &#8220;JMS client&#8221; refers to Java components or applications that use the JMS API and a JMS provider to send and receive messages.<\/p>\n<p>JMS supports two styles of messaging: the point\u2212to\u2212point and publis\u2212and\u2212subscribe messaging styles.&nbsp;Before a client can use a JMS provider to send and receive messages, the client must decide which messaging style it wants to use.<\/p>\n<p>A client can consume a message synchronously or asynchronously.<\/p>\n<p>In this article, we will see several examples of JMS Clients.<\/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;\t\n&lt;\/project&gt;\n<\/pre>\n<\/p>\n<h2>2. Starting the JMS Provider<\/h2>\n<p>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\u2019t difficult. You simply need to start up the broker and make sure that it\u2019s capable of accepting connections and sending messages.<\/p>\n<p>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.<\/p>\n<p><span style=\"text-decoration: underline\"><em>BrokerLauncher:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URI;\nimport java.net.URISyntaxException;\n\nimport org.apache.activemq.broker.BrokerFactory;\nimport org.apache.activemq.broker.BrokerService;\n\npublic class BrokerLauncher {\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();\t\t\n\t}\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\\jmsClientExample\\activemq-data\\localhost\\tmp_storage] started\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\jmsClientExample\\activemq-data\\localhost\\KahaDB]\n INFO | KahaDB is version 6\n INFO | Recovering from the journal @1:15633\n INFO | Recovery replayed 62 operations from the journal in 0.016 seconds.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-57384-1447857883439-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-57384-1447857883439-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\\jmsClientExample\\activemq-data\\localhost\\KahaDB only has 37428 mb of usable space - resetting to maximum available disk space: 37428 mb\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsClientExample\\activemq-data\\localhost\\tmp_storage only has 37428 mb of usable space - resetting to maximum available 37428 mb.\n<\/pre>\n<h2>3. ConnectionFactory<\/h2>\n<p>For a client to interact with the JMS provider to needs to get hold of a connection to the broker and a connection represents a logical connection to the JMS provider. In order to obtain this connection each JMS provider provides a connection factory. There are two types of connection factories: one for point\u2212to\u2212point and another for publish\u2212and\u2212subscribe. Based on the desired messaging style, the client obtains the appropriate connection factory and connects to the JMS provider.<\/p>\n<p>In case of ActiveMQ, it provides one ConnectionFactory and internally it implements both <code>QueueConnectionFactory<\/code> and <code>TopicConnectionFactory<\/code>.<\/p>\n<pre class=\"brush:java\">ConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\t\"tcp:\/\/localhost:61616\");\n<\/pre>\n<h2>4. JMS Producer Client<\/h2>\n<p>In our next sections, we will show how to create a connection factory, create a new connection and session, create message producers and consumers which we will then use to send and receive messages. First let\u2019s look at a message producer client. We will use point\u2212to\u2212point messaging style.<\/p>\n<p>We will first obtain a connection factory, which we will then use to create a connection.<\/p>\n<pre class=\"brush:java\">\/\/ Producer\nConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\t\"tcp:\/\/localhost:61616\");\nconnection = connectionFactory.createConnection();\n<\/pre>\n<p>Next, use the connection object to create a queue session.<\/p>\n<pre class=\"brush:java\">Session session = connection.createSession(false,\n\t\t\t\t\tSession.AUTO_ACKNOWLEDGE);\nQueue queue = session.createQueue(\"customerQueue\");\n<\/pre>\n<p>The session object obtained is used to create a producer that will be used to send a message. When the producer is created, it is told which queue to send the messages to.<\/p>\n<pre class=\"brush:java\">MessageProducer producer = session.createProducer(queue);\n<\/pre>\n<p>Next, we create messages and send in a loop.<\/p>\n<pre class=\"brush:java\">for (int i = 0; i &lt; 10; i++) {\n    String payload = task + i;\n    Message msg = session.createTextMessage(payload);\n    System.out.println(\"Sending text '\" + payload + \"'\");\n    producer.send(msg);\n}\n<\/pre>\n<p>Finally, we send message &#8216;END&#8217; to indicate the client that we have sent the last message.<\/p>\n<pre class=\"brush:java\">producer.send(session.createTextMessage(\"END\"));\n<\/pre>\n<p>Finally, close the session and the connections.<\/p>\n<pre class=\"brush:java\">try {\n    ...\n    session.close();\n} finally {\n    if (connection != null) {\n\tconnection.close();\n    }\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>JmsProducerClient:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URISyntaxException;\n\nimport javax.jms.Connection;\nimport javax.jms.ConnectionFactory;\nimport javax.jms.Message;\nimport javax.jms.MessageProducer;\nimport javax.jms.Queue;\nimport javax.jms.Session;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\n\npublic class JmsProducerQueueClient {\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\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\tMessageProducer producer = session.createProducer(queue);\n\t\t\tString task = \"Task\";\n\t\t\tfor (int i = 0; i &lt; 10; i++) {\n\t\t\t\tString payload = task + 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\t\t\tproducer.send(session.createTextMessage(\"END\"));\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}\n\t}\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\">Sending text 'Task0'\nSending text 'Task1'\nSending text 'Task2'\nSending text 'Task3'\nSending text 'Task4'\nSending text 'Task5'\nSending text 'Task6'\nSending text 'Task7'\nSending text 'Task8'\nSending text 'Task9'\n<\/pre>\n<h2>5. JMS Consumer Client<\/h2>\n<p>The consumer is very similar to the producer client. It also needs a connection factory, the connection, the session, and the same queue. In this client program, however, the session is used to create a consumer instead of a producer. This consumer is told which queue to consume messages from when it is created.<\/p>\n<pre class=\"brush:java\">\/\/ Consumer\nMessageConsumer consumer = session.createConsumer(queue);\nconnection.start();\n<\/pre>\n<p>To actually receive a message, the client calls the receive method as follows:<\/p>\n<pre class=\"brush:java\">while (true) {\n    TextMessage textMsg = (TextMessage) consumer.receive();\n    System.out.println(textMsg);\n    System.out.println(\"Received: \" + textMsg.getText());\n    if (textMsg.getText().equals(\"END\")) {\n        break;\n    }\n}\t\n<\/pre>\n<p>As you can see the consumer receives in an infinite loop. If it receives &#8216;END&#8217;, it comes out of the loop. The receive method can be used in several ways to perform a synchronous receive. If you specify no arguments or an argument of 0, the method blocks indefinitely until a message arrives.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JmsSyncReceiveClientExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URISyntaxException;\n\nimport javax.jms.Connection;\nimport javax.jms.ConnectionFactory;\nimport javax.jms.MessageConsumer;\nimport javax.jms.Queue;\nimport javax.jms.Session;\nimport javax.jms.TextMessage;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\n\npublic class JmsSyncReceiveClientExample {\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\n\t\tConnection connection = null;\n\t\tConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\"tcp:\/\/localhost:61616\");\n\t\tconnection = connectionFactory.createConnection();\n\t\tSession session = connection.createSession(false,\n\t\t\t\tSession.AUTO_ACKNOWLEDGE);\n\t\ttry {\n\t\t\tQueue queue = session.createQueue(\"customerQueue\");\n\n\t\t\t\/\/ Consumer\n\t\t\tMessageConsumer consumer = session.createConsumer(queue);\n\t\t\tconnection.start();\n\t\t\twhile (true) {\n\t\t\t\tTextMessage textMsg = (TextMessage) consumer.receive();\n\t\t\t\tSystem.out.println(textMsg);\n\t\t\t\tSystem.out.println(\"Received: \" + textMsg.getText());\n\t\t\t\tif (textMsg.getText().equals(\"END\")) {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\t\t\t\n\t\t} finally {\n\t\t\tif (session != null) {\n\t\t\t\tsession.close();\n\t\t\t}\n\t\t\tif (connection != null) {\n\t\t\t\tconnection.close();\n\t\t\t}\n\t\t}\n\t}\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\">ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931210, arrival = 0, brokerInTime = 1447857931212, brokerOutTime = 1447857977960, 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@6e3c1e69, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task0}\nReceived: Task0\nActiveMQTextMessage {commandId = 6, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:2, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931222, arrival = 0, brokerInTime = 1447857931222, brokerOutTime = 1447857977961, 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@1888ff2c, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task1}\nReceived: Task1\nActiveMQTextMessage {commandId = 7, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:3, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931224, arrival = 0, brokerInTime = 1447857931225, brokerOutTime = 1447857977961, 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@35851384, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task2}\nReceived: Task2\nActiveMQTextMessage {commandId = 8, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:4, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931227, arrival = 0, brokerInTime = 1447857931227, brokerOutTime = 1447857977961, 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@649d209a, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task3}\nReceived: Task3\nActiveMQTextMessage {commandId = 9, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:5, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931230, arrival = 0, brokerInTime = 1447857931230, brokerOutTime = 1447857977961, 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@6adca536, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task4}\nReceived: Task4\nActiveMQTextMessage {commandId = 10, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:6, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931232, arrival = 0, brokerInTime = 1447857931233, brokerOutTime = 1447857977961, 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@357246de, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task5}\nReceived: Task5\nActiveMQTextMessage {commandId = 11, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:7, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931235, arrival = 0, brokerInTime = 1447857931235, brokerOutTime = 1447857977961, 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@28f67ac7, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task6}\nReceived: Task6\nActiveMQTextMessage {commandId = 12, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:8, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931238, arrival = 0, brokerInTime = 1447857931238, brokerOutTime = 1447857977961, 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@256216b3, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task7}\nReceived: Task7\nActiveMQTextMessage {commandId = 13, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:9, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931240, arrival = 0, brokerInTime = 1447857931241, brokerOutTime = 1447857977962, 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@2a18f23c, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task8}\nReceived: Task8\nActiveMQTextMessage {commandId = 14, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:10, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931243, arrival = 0, brokerInTime = 1447857931243, brokerOutTime = 1447857977962, 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@d7b1517, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task9}\nReceived: Task9\nActiveMQTextMessage {commandId = 15, responseRequired = true, messageId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1:11, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-57438-1447857931037-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447857931246, arrival = 0, brokerInTime = 1447857931246, brokerOutTime = 1447857977962, 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@16c0663d, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = END}\nReceived: END\n<\/pre>\n<h2>6. JMS Asynchronous Client Example<\/h2>\n<p>This section describes how to consume messages asynchronously. It uses a message listener in order to consume messages asynchronously.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>In order to make sure the asynchronous consumer doesn&#8217;t run indefinitely, it calls <code>countDown()<\/code> on latch when the message received is &#8216;END&#8217;.<\/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\tprivate JmsAsyncReceiveQueueClientExample asyncReceiveQueueClientExample;\n\t\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\tif (\"END\".equals(textMessage.getText())) {\n\t\t\t\tasyncReceiveQueueClientExample.latchCountDown();\n\t\t\t}\n\t\t} catch (JMSException e) {\t\t\t\n\t\t\te.printStackTrace();\n\t\t}\n\t}\n\n\tpublic void setAsyncReceiveQueueClientExample(\n\t\t\tJmsAsyncReceiveQueueClientExample asyncReceiveQueueClientExample) {\n\t\tthis.asyncReceiveQueueClientExample = asyncReceiveQueueClientExample;\n\t}\t\n}\n<\/pre>\n<p>Just like the synchronous client, it also creates a <code>Connection<\/code>, a <code>Session<\/code>, a <code>MessageConsumer<\/code> and creates an instance of the <code>MessageListener<\/code> class and then registers it as the message listener for the <code>MessageConsumer<\/code>.<\/p>\n<pre class=\"brush:java\">MessageConsumer consumer = session.createConsumer(queue);\nConsumerMessageListener consumerListener = new ConsumerMessageListener(\n\t\t\t\t\t\"Customer\");\nconsumer.setMessageListener(consumerListener);\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>JmsAsyncReceiveQueueClientExample:<\/em><\/span>[ulp id=&#8217;meNHaG2axN7AsWAw&#8217;]<\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URISyntaxException;\nimport java.util.concurrent.CountDownLatch;\n\nimport javax.jms.Connection;\nimport javax.jms.ConnectionFactory;\nimport javax.jms.JMSException;\nimport javax.jms.MessageConsumer;\nimport javax.jms.Queue;\nimport javax.jms.Session;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\n\npublic class JmsAsyncReceiveQueueClientExample {\n\tprivate CountDownLatch latch = new CountDownLatch(1);\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\n\t\tJmsAsyncReceiveQueueClientExample asyncReceiveClient = new JmsAsyncReceiveQueueClientExample();\n\t\tasyncReceiveClient.receiveMessages();\n\t}\n\n\tpublic void receiveMessages() throws JMSException, InterruptedException {\n\t\tConnection connection = null;\n\t\tConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\"tcp:\/\/localhost:61616\");\n\t\tconnection = connectionFactory.createConnection();\n\t\tSession session = connection.createSession(false,\n\t\t\t\tSession.AUTO_ACKNOWLEDGE);\n\t\ttry {\n\t\t\tQueue queue = session.createQueue(\"customerQueue\");\n\n\t\t\t\/\/ Consumer\n\t\t\tMessageConsumer consumer = session.createConsumer(queue);\n\t\t\tConsumerMessageListener consumerListener = new ConsumerMessageListener(\n\t\t\t\t\t\"Customer\");\n\t\t\tconsumer.setMessageListener(consumerListener);\n\t\t\tconsumerListener.setAsyncReceiveQueueClientExample(this);\n\t\t\n\t\t\tconnection.start();\n\t\t\tlatch.await();\n\t\t} finally {\n\t\t\tif (session != null) {\n\t\t\t\tsession.close();\n\t\t\t}\n\t\t\tif (connection != null) {\n\t\t\t\tconnection.close();\n\t\t\t}\n\t\t}\t\t\n\t}\n\n\tpublic void latchCountDown() {\n\t\tlatch.countDown();\n\t}\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\">Customer received Task0\nCustomer received Task1\nCustomer received Task2\nCustomer received Task3\nCustomer received Task4\nCustomer received Task5\nCustomer received Task6\nCustomer received Task7\nCustomer received Task8\nCustomer received Task9\nCustomer received END\n<\/pre>\n<h2>7. JMS Subscriber Client<\/h2>\n<p>Let&#8217;s now look into a client that uses publish\u2212and\u2212subscribe message style. It\u2019s not very different than using the point\u2212to\u2212point style. It also needs a connection factory, connection and a session.<\/p>\n<p>When a publisher sends a message, there may be more than one customer interested in such messages. Publisher broadcasts the message to JMS destination called \u2018topic\u2019. There may be more than one consumer subscribed to the topic. All the active clients subscribed to the topic will receive message and there is no need for the subscriber to poll for the messages. Every active subscriber receives its own copy of each message published to the topic. In this example, we will look into durable subscriber.<\/p>\n<p>So what is a durable subscriber?<\/p>\n<p>When a publisher publishes messages for an inactive subscriber, the messages are persisted and delivered when the subscriber reconnects. For durable subscribers to a topic, each consumer gets a copy of the message. While a durable subscriber is disconnected from the JMS server, it is the responsibility of the server to store messages the subscriber misses. When the durable subscriber reconnects, the message server sends it all the unexpired messages that accumulated.<\/p>\n<p>The <code>createDurableSubscriber()<\/code> method takes two parameters: a topic name, and a subscription name. A durable subscription\u2019s uniqueness is defined by the client ID and the subscription name.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JmsSubscriberClientExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\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.Session;\nimport javax.jms.TextMessage;\nimport javax.jms.Topic;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\n\npublic class JmsSubscriberClientExample {\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\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\tconnection.setClientID(\"DurabilityTest\");\n\t\t\tSession session = connection.createSession(false,\n\t\t\t\t\tSession.AUTO_ACKNOWLEDGE);\n\t\t\tTopic topic = session.createTopic(\"customerTopic\");\n\n\t\t\t\/\/ Publish\n\t\t\tString payload = \"Task\";\n\t\t\tTextMessage msg = session.createTextMessage(payload);\n\t\t\tMessageProducer publisher = session.createProducer(topic);\n\t\t\tSystem.out.println(\"Sending text '\" + payload + \"'\");\n\t\t\tpublisher.send(msg, javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);\n\n\t\t\t\/\/ Consumer1 subscribes to customerTopic\n\t\t\tMessageConsumer consumer1 = session.createDurableSubscriber(topic, \"consumer1\", \"\", false);\t\t\n\n\t\t\t\/\/ Consumer2 subscribes to customerTopic\n\t\t\tMessageConsumer consumer2 = session.createDurableSubscriber(topic, \"consumer2\", \"\", false);\t\n\n\t\t\tconnection.start();\n\t\t\t\n\t\t\tmsg = (TextMessage) consumer1.receive();\n\t\t\tSystem.out.println(\"Consumer1 receives \" + msg.getText());\n\t\t\t\n\t\t\t\n\t\t\tmsg = (TextMessage) consumer2.receive();\n\t\t\tSystem.out.println(\"Consumer2 receives \" + msg.getText());\n\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}\n\t}\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\">Sending text 'Task'\nConsumer1 receives Task\nConsumer2 receives Task\n<\/pre>\n<h2>8. Client Program for the Queue Browser<\/h2>\n<p>We have seen examples of synchronous and asynchronous client. We have also seen clients using point-to-point and publisher-subscriber style of messaging. Let&#8217;s now see how to view the messages sent to a consumer without actually consuming them.<\/p>\n<p>In this example, we will show you how to browse through the pending messages in the queue 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. We create the QueueBrowser 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 Queue object that we are interested to browse. In order to enumerate through the messages, we will call <code>QueueBrowser.getEnumeration()<\/code>. When we are done with the browser we should close it using &lt;codeQueueBrowser.close().<\/p>\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 QueueBrowser object and navigate through the messages. Finally, we call <code>consumer.receive()<\/code> to receive one of the messages from queue.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JmsBrowseQueueClientExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URISyntaxException;\nimport java.util.Enumeration;\n\nimport javax.jms.Connection;\nimport javax.jms.ConnectionFactory;\nimport javax.jms.MessageConsumer;\nimport javax.jms.Queue;\nimport javax.jms.QueueBrowser;\nimport javax.jms.Session;\nimport javax.jms.TextMessage;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\n\npublic class JmsBrowseQueueClientExample {\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\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\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}\n\t}\n\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\">Browse through the elements in queue\nGet [Task0]\nGet [Task1]\nGet [Task2]\nGet [Task3]\nGet [Task4]\nGet [Task5]\nGet [Task6]\nGet [Task7]\nGet [Task8]\nGet [Task9]\nGet [END]\nDone\nActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:INMAA1-L1005-58212-1447859579333-1:1:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-58212-1447859579333-1:1:1:1, destination = queue:\/\/customerQueue, transactionId = null, expiration = 0, timestamp = 1447859579480, arrival = 0, brokerInTime = 1447859579481, brokerOutTime = 1447859586255, 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@28864e92, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Task0}\nReceived: Task0\n<\/pre>\n<h2>9. JMS Client Acknowledge<\/h2>\n<p>Suppose each message that a JMS provider delivers to a consumer need not be acknowledged and is left up to the client consuming the messages to decide when to acknowledge, then we need to create as session by passing in <code>Session.CLIENT_ACKNOWLEDGE<\/code> as the second parameter.<\/p>\n<pre class=\"brush:java\">Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);\n<\/pre>\n<p>If a message is not acknowledged it may be redelivered to the consumer by the JMS provider. The client acknowledges a message by calling the acknowledge method on it.<\/p>\n<pre class=\"brush:java\">Message.acknowledge();\n<\/pre>\n<p>Acknowledging one message actually acknowledges all messages that the session has consumed.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JmsClientAckExample:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package com.javacodegeeks.jms;\n\nimport java.net.URISyntaxException;\n\nimport javax.jms.Connection;\nimport javax.jms.ConnectionFactory;\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;\n\npublic class JmsClientAckExample {\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\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\"vm:\/\/localhost?broker.persistent=false\");\n\t\t\tconnection = connectionFactory.createConnection();\n\t\t\tconnection.start();\n\t\t\tSession session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);\n\t        Queue queue = session.createQueue(\"SomeQueue\");\n\t        MessageProducer producer = session.createProducer(queue);\n\t        producer.send(session.createTextMessage(\"Hello\"));\n\n\t        MessageConsumer consumer = session.createConsumer(queue);\n\t        TextMessage msg = (TextMessage) consumer.receive(1000);\n\t        System.out.println(\"Consume: \" + msg.getText());\n\t        \n\t        \/\/ Reset the session.\n\t        session.close();\n\t        session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);\n\n\t        \/\/ Attempt to Consume the message...\n\t        consumer = session.createConsumer(queue);\n\t        msg = (TextMessage) consumer.receive(1000);\n\t        System.out.println(\"Attempt to consume again. Is message received? \" + (msg != null));\n\t        \n\t        \/\/acknowledge\n\t        msg.acknowledge();\n\n\t\t\t\/\/ Reset the session.\n\t        session.close();\n\t        session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);\n\n\t        \/\/ Attempt to Consume the message...\n\t        consumer = session.createConsumer(queue);\n\t        msg = (TextMessage) consumer.receive(1000);\n\t        System.out.println(\"Attempt to consume again. Is message received? \" + (msg != null));\n\t\t} finally {\n\t\t\tif (connection != null) {\n\t\t\t\tconnection.close();\n\t\t\t}\n\t\t}\n\t}\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\"> INFO | Using Persistence Adapter: MemoryPersistenceAdapter\n WARN | Failed to start JMX connector Cannot bind to URL [rmi:\/\/localhost:1099\/jmxrmi]: javax.naming.NameAlreadyBoundException: jmxrmi [Root exception is java.rmi.AlreadyBoundException: jmxrmi]. Will restart management to re-create JMX connector, trying to remedy this issue.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53531-1447910509729-0:1) is starting\n WARN | Failed to start JMX connector Cannot bind to URL [rmi:\/\/localhost:1099\/jmxrmi]: javax.naming.NameAlreadyBoundException: jmxrmi [Root exception is java.rmi.AlreadyBoundException: jmxrmi]. Will restart management to re-create JMX connector, trying to remedy this issue.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53531-1447910509729-0:1) started\n INFO | For help or more information please see: http:\/\/activemq.apache.org\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsClientExample\\activemq-data\\localhost\\tmp_storage only has 37178 mb of usable space - resetting to maximum available 37178 mb.\n INFO | Connector vm:\/\/localhost started\nConsume: Hello\nAttempt to consume again. Is message received? true\nAttempt to consume again. Is message received? false\n INFO | Connector vm:\/\/localhost stopped\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53531-1447910509729-0:1) is shutting down\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53531-1447910509729-0:1) uptime 1.471 seconds\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53531-1447910509729-0:1) is shutdown\n<\/pre>\n<h2>10. Download the Eclipse Project<\/h2>\n<p>This was an example about JMS Clients.<\/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\/jmsClientExample.zip\"><strong>jmsClientExample.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>The term &#8220;JMS client&#8221; refers to Java components or applications that use the JMS API and a JMS provider to send and receive messages. JMS supports two styles of messaging: the point\u2212to\u2212point and publis\u2212and\u2212subscribe messaging styles.&nbsp;Before a client can use a JMS provider to send and receive messages, the client must decide which messaging style &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-28786","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 Client Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"The term &quot;JMS client&quot; refers to Java components or applications that use the JMS API and a JMS provider to send and receive messages. JMS supports two\" \/>\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-client-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JMS Client Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"The term &quot;JMS client&quot; refers to Java components or applications that use the JMS API and a JMS provider to send and receive messages. JMS supports two\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-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-19T13:00:58+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-04T08:34:55+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=\"20 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-client-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/\"},\"author\":{\"name\":\"Ram Mokkapaty\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8\"},\"headline\":\"JMS Client Example\",\"datePublished\":\"2015-11-19T13:00:58+00:00\",\"dateModified\":\"2019-03-04T08:34:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/\"},\"wordCount\":1233,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-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-client-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/\",\"name\":\"JMS Client Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"datePublished\":\"2015-11-19T13:00:58+00:00\",\"dateModified\":\"2019-03-04T08:34:55+00:00\",\"description\":\"The term \\\"JMS client\\\" refers to Java components or applications that use the JMS API and a JMS provider to send and receive messages. JMS supports two\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-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-client-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 Client 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 Client Example - Java Code Geeks","description":"The term \"JMS client\" refers to Java components or applications that use the JMS API and a JMS provider to send and receive messages. JMS supports two","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-client-example\/","og_locale":"en_US","og_type":"article","og_title":"JMS Client Example - Java Code Geeks","og_description":"The term \"JMS client\" refers to Java components or applications that use the JMS API and a JMS provider to send and receive messages. JMS supports two","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-11-19T13:00:58+00:00","article_modified_time":"2019-03-04T08:34:55+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":"20 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/"},"author":{"name":"Ram Mokkapaty","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8"},"headline":"JMS Client Example","datePublished":"2015-11-19T13:00:58+00:00","dateModified":"2019-03-04T08:34:55+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/"},"wordCount":1233,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-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-client-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/","name":"JMS Client Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","datePublished":"2015-11-19T13:00:58+00:00","dateModified":"2019-03-04T08:34:55+00:00","description":"The term \"JMS client\" refers to Java components or applications that use the JMS API and a JMS provider to send and receive messages. JMS supports two","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-client-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-client-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 Client 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\/28786","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=28786"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28786\/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=28786"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=28786"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=28786"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}