JMS Publish Subscribe Chat Application

JMS Publish Subscribe Chat Application

In previous tutorials you saw how to create Queue and Topic standalone application, publish subscribe topic application etc… using JBoss JMS. Today we will create simple chat application using topic where we will publish message and subscriber will consume message from it. 

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:

JMS Publish Subscribe Chat Application

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

JMS Publish Subscribe Chat Application

  • Configure JBoss application server in eclipse using this tutorial
  • To include include all JBoss related jars to to class path: right click project –> properties –> Java build path –> on library tab click add library… –> Server runtime –> if you configured Jboss in eclipse you will see JBoss Runtime server choose it –> click finish.
  • pom.xml:

  • Now create class name ChatJMSApplicaiton is main class where we will create connection, session, publisher, subscriber and send receive message from topic as below:

  • 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.
  • To run chat application right click ChatJMSApplication.java –> Run As –> Java Application you will see console and its ready for message. Below is example:

JMS Publish Subscribe Chat Application

download  Download Project:  JMSChatApplicaiton

Leave a Reply

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