{"id":28601,"date":"2015-11-12T11:18:57","date_gmt":"2015-11-12T09:18:57","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=28601"},"modified":"2019-03-04T10:35:29","modified_gmt":"2019-03-04T08:35:29","slug":"jms-topic-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/","title":{"rendered":"JMS Topic Example"},"content":{"rendered":"<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 &#8216;topic&#8217;. There may be more than one consumer subscribed to the topic.<\/p>\n<p>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.<\/p>\n<p>In this article, we will see some examples of JMS Topic.<\/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 Topic<\/h2>\n<p>Our first example consists of a publisher sending a message to a topic. We have two consumers subscribed to the topic. Both the consumers have registered a listener to consume messages from topic in an asynchronous way.<\/p>\n<p>If you notice, the consumers first subscribe to the topic and then the publisher publishes the message, this is because the consumers are not durable so they must be online.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JmsTopicExample:<\/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.Session;\nimport javax.jms.Topic;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\nimport org.apache.activemq.broker.BrokerFactory;\nimport org.apache.activemq.broker.BrokerService;\n\npublic class JmsTopicExample {\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\tTopic topic = session.createTopic(\"customerTopic\");\t\t\n\t\t\t\n\t\t\t\/\/ Consumer1 subscribes to customerTopic\n\t\t\tMessageConsumer consumer1 = session.createConsumer(topic);\n\t\t\tconsumer1.setMessageListener(new ConsumerMessageListener(\"Consumer1\"));\n\t\t\t\n\t\t\t\/\/ Consumer2 subscribes to customerTopic\n\t\t    MessageConsumer consumer2 = session.createConsumer(topic);\n\t\t    consumer2.setMessageListener(new ConsumerMessageListener(\"Consumer2\"));\n\t\t    \n\t\t\tconnection.start();\t\t\n\t\t\t\n\t\t\t\/\/ Publish\n\t\t\tString payload = \"Important Task\";\n\t\t\tMessage msg = session.createTextMessage(payload);\n\t\t\tMessageProducer producer = session.createProducer(topic);\n\t\t\tSystem.out.println(\"Sending text '\" + payload + \"'\");\n\t\t\tproducer.send(msg);\n\t\t\t\n\t\t\tThread.sleep(3000);\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<\/pre>\n<h2>3. Consuming messages from Topic using MessageListener<\/h2>\n<p>The message listener implements <code>MessageListener<\/code>. The constructor takes in the consumer name so we know which consumer is consuming the message.<\/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>Now lets&#8217; run our example with the above message listener.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash\"> INFO | PListStore:[C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\tmp_storage] started\n INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\KahaDB]\n INFO | KahaDB is version 6\n INFO | Recovering from the journal @1:295312\n INFO | Recovery replayed 1 operations from the journal in 0.013 seconds.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56907-1447237470288-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-56907-1447237470288-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\\jmsTopicExample\\activemq-data\\localhost\\KahaDB only has 29578 mb of usable space - resetting to maximum available disk space: 29579 mb\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\tmp_storage only has 29578 mb of usable space - resetting to maximum available 29578 mb.\nSending text 'Important Task'\nConsumer1 received Important Task\nConsumer2 received Important Task\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56907-1447237470288-0:1) is shutting down\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsTopicExample\\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-56907-1447237470288-0:1) uptime 3.917 seconds\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-56907-1447237470288-0:1) is shutdown\n<\/pre>\n<p>The same example can be re-written using topic specific objects.<\/p>\n<h2>4. Topic Specific APIs<\/h2>\n<p>In this example, we will use Topic specific APIs. We use in this example below topic specific objects.<\/p>\n<ol>\n<li>TopicConnectionFactory<\/li>\n<li>TopicConnection<\/li>\n<li>TopicSession<\/li>\n<li>TopicPublisher<\/li>\n<\/ol>\n<p><span style=\"text-decoration: underline\"><em>JmsTopicConnectionExample:<\/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.Message;\nimport javax.jms.MessageConsumer;\nimport javax.jms.Session;\nimport javax.jms.Topic;\nimport javax.jms.TopicConnection;\nimport javax.jms.TopicConnectionFactory;\nimport javax.jms.TopicPublisher;\nimport javax.jms.TopicSession;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\nimport org.apache.activemq.broker.BrokerFactory;\nimport org.apache.activemq.broker.BrokerService;\n\npublic class JmsTopicConnectionExample {\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.setPersistent(true);\n\t\tbroker.start();\n\t\tTopicConnection topicConnection = null;\n\t\ttry {\n\t\t\t\/\/ Producer\n\t\t\tTopicConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\t\"tcp:\/\/localhost:61616\");\n\t\t\ttopicConnection = connectionFactory.createTopicConnection();\t\n\t\t\ttopicConnection.setClientID(\"JMSTOPIC\");\n\n\t\t\tTopicSession topicConsumerSession = topicConnection.createTopicSession(\n\t\t\t\t\tfalse, Session.AUTO_ACKNOWLEDGE);\t\t\t\n\t\t\tTopic topic = topicConsumerSession.createTopic(\"customerTopic\");\n\t\t\t\n\t\t\t\/\/ Consumer1 subscribes to customerTopic\n\t\t\tMessageConsumer consumer1 = topicConsumerSession.createSubscriber(topic);\n\t\t\tconsumer1.setMessageListener(new ConsumerMessageListener(\n\t\t\t\t\t\"Consumer1\"));\n\n\t\t\t\/\/ Consumer2 subscribes to customerTopic\n\t\t\tMessageConsumer consumer2 = topicConsumerSession.createSubscriber(topic);\n\t\t\tconsumer2.setMessageListener(new ConsumerMessageListener(\n\t\t\t\t\t\"Consumer2\"));\n\n\t\t\ttopicConnection.start();\n\t\t\t\n\t\t\t\/\/ Publish\n\t\t\tTopicSession topicPublisherSession = topicConnection.createTopicSession(\n\t\t\t\t\tfalse, Session.AUTO_ACKNOWLEDGE);\n\t\t\tString payload = \"Important Task\";\n\t\t\tMessage msg = topicPublisherSession.createTextMessage(payload);\n\t\t\tTopicPublisher publisher = topicPublisherSession.createPublisher(topic);\n\t\t\tSystem.out.println(\"Sending text '\" + payload + \"'\");\n\t\t\tpublisher.publish(msg);\n\n\n\t\t\tThread.sleep(3000);\n\t\t\ttopicPublisherSession.close();\n\t\t\ttopicConsumerSession.close();\n\t\t} finally {\n\t\t\tif (topicConnection != null) {\n\t\t\t\ttopicConnection.close();\n\t\t\t}\n\t\t\tbroker.stop();\n\t\t}\n\t}\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:bash\"> INFO | PListStore:[C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\tmp_storage] started\n INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\KahaDB]\n INFO | KahaDB is version 6\n INFO | Recovering from the journal @1:344608\n INFO | Recovery replayed 1 operations from the journal in 0.014 seconds.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-61121-1447245012885-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-61121-1447245012885-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\\jmsTopicExample\\activemq-data\\localhost\\KahaDB only has 29598 mb of usable space - resetting to maximum available disk space: 29598 mb\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\tmp_storage only has 29598 mb of usable space - resetting to maximum available 29598 mb.\nSending text 'Important Task'\nConsumer1 received Important Task\nConsumer2 received Important Task\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-61121-1447245012885-0:1) is shutting down\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsTopicExample\\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-61121-1447245012885-0:1) uptime 3.915 seconds\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-61121-1447245012885-0:1) is shutdown\n<\/pre>\n<h2>5. Durable Subscriber<\/h2>\n<p>Durable subscribers can receive already published messages when they are back online. A durable subscription saves messages for an inactive subscriber and delivers these saved messages when the subscriber reconnects. For durable subscribers to a topic, each consumer gets a copy of the message.<\/p>\n<p>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&#8217;s uniqueness is defined by the client ID and the subscription name.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JmsDurableSubscriberExample:<\/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.Session;\nimport javax.jms.TextMessage;\nimport javax.jms.Topic;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\nimport org.apache.activemq.broker.BrokerFactory;\nimport org.apache.activemq.broker.BrokerService;\n\npublic class JmsDurableSubscriberExample {\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\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 = \"Important 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\tbroker.stop();\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 | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\tmp_storage] started\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\KahaDB]\n INFO | KahaDB is version 6\n INFO | Recovering from the journal @1:385534\n INFO | Recovery replayed 1 operations from the journal in 0.012 seconds.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53592-1447268104050-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-53592-1447268104050-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\\jmsTopicExample\\activemq-data\\localhost\\KahaDB only has 29545 mb of usable space - resetting to maximum available disk space: 29546 mb\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\tmp_storage only has 29545 mb of usable space - resetting to maximum available 29545 mb.\nSending text 'Important Task'\nConsumer1 receives Important Task\nConsumer2 receives Important Task\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53592-1447268104050-0:1) is shutting down\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsTopicExample\\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-53592-1447268104050-0:1) uptime 0.913 seconds\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-53592-1447268104050-0:1) is shutdown\n<\/pre>\n<h2>6. Publishing Message Using Persistent Mode<\/h2>\n<p>In the above example, the publisher publishes the message using the persistent delivery mode:<\/p>\n<pre class=\"brush:java\">publisher.send(msg, javax.jms.DeliveryMode.PERSISTENT, javax.jms.Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);\n<\/pre>\n<p>Note the use of the overloaded publish( ) method, with parameters that specify delivery mode, priority, and message expiration.<\/p>\n<h2>7. MessageConsumer.receive()<\/h2>\n<p>We receive the message using <code>MessageConsumer.receive()<\/code> method rather than passively receiving it through the <code>onMessage()<\/code> callback. The default behavior of the <code>receive()<\/code> method is to block program execution until a message is retrieved from the message server. You can always sepcify a timeout though. The <code>receive()<\/code> method follows &#8220;pull&#8221; model instead of &#8220;push&#8221; model which is the way of <code>onMessage()<\/code>. From the client&#8217;s perspective, you can think of this as a polling mechanism.[ulp id=&#8217;meNHaG2axN7AsWAw&#8217;]<\/p>\n<h2>8. Temporary Topics<\/h2>\n<p>Temporary topics are a mechanism for JMS clients to create topics dynamically. Its lifetime will be that of the <code>Connection<\/code> unless it is deleted earlier.<\/p>\n<p>A temporary topic is a topic that is dynamically created by the JMS provider, using the <code>createTemporaryTopic()<\/code> method of the <code>TopicSession<\/code> object. A temporary topic is associated with the connection that belongs to the TopicSession that created it. It is only active for the duration of the connection, and it is guaranteed to be unique across all connections. Since it is temporary, it can&#8217;t be durable: it lasts only as long as its associated client connection is active. The topic identity is transferred using the <code>JMSReplyTo<\/code> header.<\/p>\n<h2>9.&nbsp;Request and Reply<\/h2>\n<p>In the below example, the server connection is listening for queries on &#8216;SomeTopic&#8217;. Client sends a request query to server&#8217;s &#8216;SomeTopic&#8217; and expects an answer from it on a temporary topic created dynamically just for this connection. It sets the temporary topic in <code>JMSReplyTo<\/code>. Server receives the message and sends response to topic found in <code>JMSReplyTo<\/code>. The client then receives the response using <code>MessageConsumer.receive(5000)<\/code>.<\/p>\n<p><span style=\"text-decoration: underline\"><em>JmsTopicExample:<\/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.Destination;\nimport javax.jms.JMSException;\nimport javax.jms.Message;\nimport javax.jms.MessageConsumer;\nimport javax.jms.MessageListener;\nimport javax.jms.MessageProducer;\nimport javax.jms.Session;\nimport javax.jms.TextMessage;\nimport javax.jms.Topic;\n\nimport org.apache.activemq.ActiveMQConnectionFactory;\nimport org.apache.activemq.broker.BrokerFactory;\nimport org.apache.activemq.broker.BrokerService;\n\npublic class JmsTopicExample implements MessageListener {\n\tprivate Session serverSession;\n\tprivate MessageProducer replyProducer;\n\n\tpublic static void main(String[] args) throws URISyntaxException, Exception {\n\t\tJmsTopicExample jmsTopicExample = new JmsTopicExample();\n\t\tjmsTopicExample.sendReqOnTempTopic();\n\t}\n\t\n\tpublic void sendReqOnTempTopic() 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 serverConnection = null;\n\t\tConnection clientConnection = null;\n\t\ttry {\n\t\t\tConnectionFactory connectionFactory = new ActiveMQConnectionFactory(\n\t\t\t\t\t\"tcp:\/\/localhost:61616\");\n\n\t\t\tserverConnection = connectionFactory.createConnection();\n\t\t\tserverConnection.setClientID(\"serverTempTopic\");\n\t\t\tserverSession = serverConnection.createSession(false,\n\t\t\t\t\tSession.AUTO_ACKNOWLEDGE);\n\n\t\t\treplyProducer = serverSession.createProducer(null);\n\t\t\tTopic requestDestination = serverSession.createTopic(\"SomeTopic\");\n\t\t\t\n\t\t\t\/\/Server is listening for queries\n\t\t\tfinal MessageConsumer requestConsumer = serverSession\n\t\t\t\t\t.createConsumer(requestDestination);\n\t\t\trequestConsumer.setMessageListener(this);\n\t\t\tserverConnection.start();\n\n\t\t\t\/\/ Client sends a query to topic 'SomeTopic'\n\t\t\tclientConnection = connectionFactory.createConnection();\n\t        clientConnection.setClientID(\"clientTempTopic\");\n\t        Session clientSession = clientConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);\n\t        clientConnection.start();\n\t        Destination replyDestination = clientSession.createTemporaryTopic();\n\n\t        MessageProducer requestProducer = clientSession.createProducer(requestDestination);\n\t        \/\/Create a client listener on the temporary topic\n\t        MessageConsumer replyConsumer = clientSession.createConsumer(replyDestination);\n\n\t        TextMessage requestMessage = clientSession.createTextMessage(\"Client: Important Query\");\n\t        \/\/Server is going to send the reply to the temporary topic\n\t        requestMessage.setJMSReplyTo(replyDestination);\n\t        requestProducer.send(requestMessage);\n\n\t        System.out.println(\"Sent request \" + requestMessage.toString());\n\n\t        \/\/Read the answer from temporary queue.\n\t        Message msg = replyConsumer.receive(5000);\n\t        TextMessage replyMessage = (TextMessage)msg;\n            System.out.println(\"Received reply \" + replyMessage.toString());\n            System.out.println(\"Received answer: \" + replyMessage.getText());\n            \n\t        replyConsumer.close();\n\t        \n\t\t\tclientSession.close();\n\t\t\tserverSession.close();\n\t\t} finally {\n\t\t\tif (clientConnection != null) {\n\t\t\t\tclientConnection.close();\n\t\t\t}\n\t\t\tif (serverConnection != null) {\n\t\t\t\tserverConnection.close();\n\t\t\t}\n\t\t\tbroker.stop();\n\t\t}\n\t}\n\n\t\/\/Server receives a query and sends reply to temporary topic set in JMSReplyTo\n\tpublic void onMessage(Message message) {\n\t\t try {\n\t            TextMessage requestMessage = (TextMessage)message;\n\n\t            System.out.println(\"Received request.\" + requestMessage.toString());\n\n\t            Destination replyDestination = requestMessage.getJMSReplyTo();\n\t            TextMessage replyMessage = serverSession.createTextMessage(\"Server: This is my answer to \" + requestMessage.getText());\n\n\t            replyMessage.setJMSCorrelationID(requestMessage.getJMSMessageID());\n\n\t            replyProducer = serverSession.createProducer(replyDestination);\n                replyProducer.send(replyMessage);\n                \n                System.out.println(\"Sent reply.\");\n                System.out.println(replyMessage.toString());\n\t        } catch (JMSException e) {\n\t        \tSystem.out.println(e);\n\t        }\n\t}\n}\n<\/pre>\n<p><span style=\"text-decoration: underline\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:java\"> INFO | PListStore:[C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\tmp_storage] started\n INFO | JMX consoles can connect to service:jmx:rmi:\/\/\/jndi\/rmi:\/\/localhost:1099\/jmxrmi\n INFO | Using Persistence Adapter: KahaDBPersistenceAdapter[C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\KahaDB]\n INFO | KahaDB is version 6\n INFO | Recovering from the journal @1:379942\n INFO | Recovery replayed 1 operations from the journal in 0.015 seconds.\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-51557-1447266194175-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-51557-1447266194175-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\\jmsTopicExample\\activemq-data\\localhost\\KahaDB only has 29549 mb of usable space - resetting to maximum available disk space: 29550 mb\n WARN | Temporary Store limit is 51200 mb, whilst the temporary data directory: C:\\javacodegeeks_ws\\jmsTopicExample\\activemq-data\\localhost\\tmp_storage only has 29549 mb of usable space - resetting to maximum available 29549 mb.\nSent request ActiveMQTextMessage {commandId = 0, responseRequired = false, messageId = ID:INMAA1-L1005-51557-1447266194175-3:2:1:1:1, originalDestination = null, originalTransactionId = null, producerId = null, destination = topic:\/\/SomeTopic, transactionId = null, expiration = 0, timestamp = 1447266194427, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = null, replyTo = temp-topic:\/\/ID:INMAA1-L1005-51557-1447266194175-3:2:1, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = false, readOnlyBody = false, droppable = false, jmsXGroupFirstForConsumer = false, text = Client: Important Query}\nReceived request.ActiveMQTextMessage {commandId = 7, responseRequired = true, messageId = ID:INMAA1-L1005-51557-1447266194175-3:2:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-51557-1447266194175-3:2:1:1, destination = topic:\/\/SomeTopic, transactionId = null, expiration = 0, timestamp = 1447266194427, arrival = 0, brokerInTime = 1447266194427, brokerOutTime = 1447266194427, correlationId = null, replyTo = temp-topic:\/\/ID:INMAA1-L1005-51557-1447266194175-3:2:1, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@5a2f3f16, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Client: Important Query}\nSent reply.\nActiveMQTextMessage {commandId = 0, responseRequired = false, messageId = ID:INMAA1-L1005-51557-1447266194175-3:1:1:2:1, originalDestination = null, originalTransactionId = null, producerId = null, destination = temp-topic:\/\/ID:INMAA1-L1005-51557-1447266194175-3:2:1, transactionId = null, expiration = 0, timestamp = 1447266194430, arrival = 0, brokerInTime = 0, brokerOutTime = 0, correlationId = ID:INMAA1-L1005-51557-1447266194175-3:2:1:1:1, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = false, readOnlyBody = false, droppable = false, jmsXGroupFirstForConsumer = false, text = Server: This is my answer to Client: Important Query}\nReceived reply ActiveMQTextMessage {commandId = 7, responseRequired = true, messageId = ID:INMAA1-L1005-51557-1447266194175-3:1:1:2:1, originalDestination = null, originalTransactionId = null, producerId = ID:INMAA1-L1005-51557-1447266194175-3:1:1:2, destination = temp-topic:\/\/ID:INMAA1-L1005-51557-1447266194175-3:2:1, transactionId = null, expiration = 0, timestamp = 1447266194430, arrival = 0, brokerInTime = 1447266194430, brokerOutTime = 1447266194430, correlationId = ID:INMAA1-L1005-51557-1447266194175-3:2:1:1:1, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@491666ad, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = Server: This is my answer to Client: Important Query}\nReceived answer: Server: This is my answer to Client: Important Query\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-51557-1447266194175-0:1) is shutting down\n INFO | Connector tcp:\/\/127.0.0.1:61616 stopped\n INFO | PListStore:[C:\\javacodegeeks_ws\\jmsTopicExample\\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-51557-1447266194175-0:1) uptime 0.971 seconds\n INFO | Apache ActiveMQ 5.12.0 (localhost, ID:INMAA1-L1005-51557-1447266194175-0:1) is shutdown\n<\/pre>\n<h2>10. Download the Eclipse Project<\/h2>\n<p>This was an example about JMS Topic.<\/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\/jmsTopicExample.zip\"><strong>jmsTopicExample.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<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 &#8216;topic&#8217;. 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 &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-28601","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 Topic Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"When a publisher sends a message, there may be more than one customer interested in such messages. Publisher broadcasts the message to JMS destination\" \/>\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-topic-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JMS Topic Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"When a publisher sends a message, there may be more than one customer interested in such messages. Publisher broadcasts the message to JMS destination\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-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-12T09:18:57+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-03-04T08:35:29+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=\"16 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-topic-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/\"},\"author\":{\"name\":\"Ram Mokkapaty\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8\"},\"headline\":\"JMS Topic Example\",\"datePublished\":\"2015-11-12T09:18:57+00:00\",\"dateModified\":\"2019-03-04T08:35:29+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/\"},\"wordCount\":713,\"commentCount\":2,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-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-topic-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/\",\"name\":\"JMS Topic Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg\",\"datePublished\":\"2015-11-12T09:18:57+00:00\",\"dateModified\":\"2019-03-04T08:35:29+00:00\",\"description\":\"When a publisher sends a message, there may be more than one customer interested in such messages. Publisher broadcasts the message to JMS destination\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-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-topic-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 Topic 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 Topic Example - Java Code Geeks","description":"When a publisher sends a message, there may be more than one customer interested in such messages. Publisher broadcasts the message to JMS destination","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-topic-example\/","og_locale":"en_US","og_type":"article","og_title":"JMS Topic Example - Java Code Geeks","og_description":"When a publisher sends a message, there may be more than one customer interested in such messages. Publisher broadcasts the message to JMS destination","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2015-11-12T09:18:57+00:00","article_modified_time":"2019-03-04T08:35:29+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":"16 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/"},"author":{"name":"Ram Mokkapaty","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/7b1823eb5bd673bd375f8bee33b70cd8"},"headline":"JMS Topic Example","datePublished":"2015-11-12T09:18:57+00:00","dateModified":"2019-03-04T08:35:29+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/"},"wordCount":713,"commentCount":2,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-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-topic-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/","name":"JMS Topic Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/enterprise-java-logo.jpg","datePublished":"2015-11-12T09:18:57+00:00","dateModified":"2019-03-04T08:35:29+00:00","description":"When a publisher sends a message, there may be more than one customer interested in such messages. Publisher broadcasts the message to JMS destination","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/jms\/jms-topic-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-topic-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 Topic 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\/28601","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=28601"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/28601\/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=28601"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=28601"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=28601"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}