Create JMS Topic with JBoss 5.1 GA and Java 6

Send message with JMS and JBoss 5.1 GA

This example will show how to produce an async JMS message after a success update operation.

The source code is based on the previous article on how to set up a restful webapp that uses ejb3 and jpa technology.

So the minimum requirements for this example are:

  • Java J2ee 6.0
  • JPA 1
  • EJB 3.x
  • JBoss 5.1 GA
  • Jersey 2.6

Topic configuration on JBoss

Under {JBOSS_HOME}/server/default/deploy directory, create a “topic” folder and add a file named MyTopic-service.xml, then write in the following content:

Notice it is also possible to put the content above on the already existent file destination-service.xml.

Send message topic from JBoss

Take the sample-ejb project of the previous article and edit the classes as described below:

PersonLocal.java and PersonRemote.java

PersonBean.java

PersonBean EJB now expose the create and update method.

Execute the following command from the Windows prompt:

 

Expose Restful methods for create and update

Take the sample-web project of the previous article and edit the classes as described below:

PersonService.java

 

Execute the following command from the Windows prompt:

Create a simple app client for subscribe to Topic

Create a simple app project archetype by executing the maven command

Edit pom.xml in this way:

Under src/main/resources, place a file named jndi.properties with the following content:

 

Edit App.java

Run the app, it will wait for a message.

From a restclient like Postman or RestClient , set the request body in this way:

Set Content-Type on request headers with value “application/json

On the address bar, type the following with PUT method

put_request_data

 

From the app client console, a log message should display something like this