JMS Publish Subscribe Application

JMS Publish Subscribe Application

In previous tutorials you saw how to create Queue and Topic standalone application using JBoss JMS. In this demo you will see how to create publish subscribe application where publisher will publish message on the topic and subscriber will consume message from same topic.

Tools needed:

  • JBoss application server jboss-6.1.0.Final community version (You can use any version of JBoss application server which you could download from here). If you are using version other than jboss-6.1.0.Final community version only JMS configuration will be different and use this tutorial to configure Queue and topic.
  • Eclipse Kepler (You could use any version of eclipse above 4.2)

Steps:

  • Configure JMS Topic destination on jboss-6.1.0.Final application server: Go to jboss-6.1.0.Final\server\default\deploy\hornetq\hornetq-jms.xml and add below topic:

JBoss JMS Topic standalone application example

  • Create maven project name: JBossJMSPublishSubscribe and below is final project structure:

JMS Publish Subscribe Application

  • Configure JBoss application server in eclipse using this tutorial
  • Add server run time to include all JBoss related jars to class path as shown below:

JMS Publish Subscribe Application

JBoss JMS Queue standalone application

  • pom.xml:

  • Create class JBossJMSTopicPublisher.java which will publish message on Topic name: “javahonk/topic”:

  • Create class JBossJMSTopicSubscriber.java which will consume message from the topic name “javahonk/topic”. Whenever publisher publish the message on topic subscriber will consume and print message on console:

  • Start JBoss server: Go to %JBOSS_HOME%/bin –> Double click run.bat to start the server. Once server is started it will pick up configured topic automatically. If you want to verify if topic nametestTopic deployed or not check on console you will see below:

JMS Publish Subscribe Application

  • Our all configuration been done and we are ready to start our JMS publish subscribe application. Start publisher and subscriber separately as you see above both class have main method. To start right click publisher and subscriber class –> Run As –> Java Application in eclipse. You will two console in eclipse one is for subscriber and another one is for publisher as below and both are ready to publish and consume the message:

JMS Publish Subscribe Application

JMS Publish Subscribe Application

  • Now go to JBossJMSTopicPublisher console, write any message and hit enter to publish message on topic:

JMS Publish Subscribe Application

  • Go to JBossJMSTopicSubscriber console where message will be consume from the topic and same message you will see as below:

JMS Publish Subscribe Application

  • That’s it JMS Publish Subscribe Application completed. For more information please visit JBoss documentation here

download  Download Project:  JBossJMSPublishSubscribe

Leave a Reply

Your email address will not be published. Required fields are marked *