Free Online Courses for Software Developers - MrBool
× Please, log in to give us a feedback. Click here to login
×

You must be logged to download. Click here to login

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

×

MrBool is totally free and you can help us to help the Developers Community around the world

Yes, I'd like to help the MrBool and the Developers Community before download

No, I'd like to download without make the donation

Java Message Service (JMS)

Java Message Service (JMS) is an API which basically provides the framework in order to enable the enterprise level applications that are message driven, efficient and portable.

JMS is a standard of messaging which allows the components of an application in order to create, read, send and receive the messages in a respective manner. The elements of JMS include JMS message, JMS queue, JMS provider, JMS client, JMS producer or publisher, JMS consumer or subscriber and the JMS topic. The two models of JMS API includes point to point model and other one is publish / subscribe model. In point to point model, the publisher basically send the message to the particular destination and the subscriber is the actual target and this destination at which the message is present is actually known as a queue. The multiple subscribers are able to send different messages to that queue. The JMS queue makes it clear that each message present in the queue is processed only one time by one consumer only.

Queue keeps the messages till the time the particular messages are not consumed by the consumer and at a specific time one consumer can consume the available message to which that message has been delivered. In the publish / subscribe model, the publisher basically publishes the particular message to a destination that is known as topic in this case while in the case of point to point model this destination was known as the queue. The subscriber who has the interest in order to get that message first registers by subscribing to that respective topic that was published by the publisher. Many publishers at a time are allowed to publish the message to the topic and in the same manner in this case the multiple subscribers are allowed to subscribe to that published topic respectively. The subscriber and the publisher do not know about any information of each other and both of them just need to know the format of message and the destination.The method of communication through which the applications and systems communicate with each other is known as messaging.

The system of messaging is the facility though which clients send and receive messages without the involvement of server which means that it is a peer-to-peer activity.In order to solve the computing problems of an enterprise level application, the JMS API is used because the reliable enterprise messaging is done in a respective and an effective manner. JMS is a message oriented middleware (MOM) that basically allows the message in order to send and receive between the distributed systems and this provides the way to the programs written in Java in order to create, read, send and receive the messages of an enterprise messaging system.

The messages are objects which communicate the information between different clients of JMS.The JMS clients are the programs written in Java which basically have an ability to produce and consume messages in an effective manner.

Overview:

The message of JMS can be built using the three parts including the header, properties and body respectively. Header is always required and is a part of message in JMS message and it is used in order to keep the route of sent message and identify the respective message. The properties in JMS message are an optional header fields and can be added by the client side and the property can be either specific to application or specific to provider and it depends on the type of message.In a message driven bean, there is no need of home or remote interface but in enterprise beans there is a need of these interfaces.

The JMS provider is a system of messaging which basically implements the JMS interfaces and this provider is responsible in order to provide the administrative and control features. There is a need of JMS provider in order to use JMS for the management of sessions and queues. In order to access the classes and use the required functionality, the package of javax,jms.* is required to be imported in an application. The basic items of a JMS application includes administered objects which contains the connection factories and destinations, connections, sessions, producers of message, consumers of message and the messages.

Importance of JMS:

A synchronous message is that in which the communication is done between the two applications or the systems and in which the system puts the message in an event queue and then system continues to wait for the response of that sent message respectively while in an asynchronous message the system does not wait for the response of the sent message and the process continues in a respective manner. The session beans and entity beans allows the user in order to send and receive the messages in a synchronous manner. There is a type of Enterprise JavaBeans (EJB) that is known as message driven beans and this type allows the enterprise level applications in order to process the messages of JMS in an asynchronous manner.The API of JMS enables the asynchronous and reliable communication.

In order to use the API of JMS, the business model of application allows the component in order to send the information containing message to others and continue the process without any interruption and without even receiving the response of the respective message. With the API of JMS, the client of application level, EJB components, components of web are now able to send and synchronously receive the JMS message in a respective manner. The application clients are also able to receive the messages of JMS in an asynchronous manner. The messages sent and received are able to take part Java Transactions API (JTA) and EJB container architecture enhances the API of JMS in order to provide the support for different distributed transactions.

Screenshots:

The Figure 1 shows the total projects and the related files after adding all the required resources in order to complete the work of JMS in a successful manner.

Projects and Inside Files

Figure 1: Projects and Inside Files

The Figure 2 shows the work being done in the project.

JMS_Work_Client

Figure 2: JMS_Work_Client

The Figure 3 shows the work of EJB module and the highlighted portion shows the work being done and in the class named as NewMessageBean.java respectively. Work done in the EJB module of JMS

Figure 3: Work done in the EJB module of JMS

Project Name: JMS_Work-ejb

This project is present inside the enterprise edition of the project and this JMS_Work-ejb is the EJB module of the project and contains a class named as NewMessageBean.java to do the work of JMS respectively.

Listing 1: NewMessageBean.java

packagecom.source.packaga.message.driven.bean;
importjavax.ejb.ActivationConfigProperty;
importjavax.ejb.MessageDriven;
importjavax.jms.Message;
importjavax.jms.MessageListener;
importjavax.jms.TextMessage;
@MessageDriven(mappedName = "jms/myJMSQueue", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue")
})
public class NewMessageBean implements MessageListener {
publicNewMessageBean() {
    }
    @Override
public void onMessage(Message message) {
TextMessage tm=(TextMessage) message;
try{
System.out.println("The message: "+tm.getText());
}catch(Exception e){
e.getMessage();
        }}}

This code is generated automatically when the configurations work and related projects are attached in the required projects as shown in the Figure 1.

Project Name: JMS_Work_Client

Listing 2: glassfish-resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<admin-object-resource enabled="true" jndi-name="jms/myJMSQueue" object-type="user" res-adapter="jmsra" res-type="javax.jms.Queue">
<description/>
<property name="Name" value="myJMSQueue"/>
</admin-object-resource>
<connector-resource enabled="true" jndi-name="jms/myJMSQueueConnectionFactory" object-type="user" pool-name="jms/myJMSQueueConnectionFactory-Connection-Pool">
<description/>
</connector-resource>
<connector-connection-pool associate-with-thread="false" connection-creation-retry-attempts="0" connection-creation-retry-interval-in-seconds="10" connection-definition-name="javax.jms.QueueConnectionFactory" connection-leak-reclaim="false" connection-leak-timeout-in-seconds="0" fail-all-connections="false" idle-timeout-in-seconds="300" is-connection-validation-required="false" lazy-connection-association="false" lazy-connection-enlistment="false" match-connections="true" max-connection-usage-count="0" max-pool-size="32" max-wait-time-in-millis="60000" name="jms/myJMSQueueConnectionFactory-Connection-Pool" ping="false" pool-resize-quantity="2" pooling="true" resource-adapter-name="jmsra" steady-pool-size="8" validate-atmost-once-period-in-seconds="0"/>
</resources>

It is a configuration file and the two related files with variable names added of queue and connection factory as explained in the description of JMS.

Hope you liked it. See you next time.



My main area of specialization is Java and J2EE. I have worked on many international projects like Recorders,Websites,Crawlers etc.Also i am an Oracle Certified java professional as well as DB2 certified

What did you think of this post?
Services
[Close]
To have full access to this post (or download the associated files) you must have MrBool Credits.

  See the prices for this post in Mr.Bool Credits System below:

Individually – in this case the price for this post is US$ 0,00 (Buy it now)
in this case you will buy only this video by paying the full price with no discount.

Package of 10 credits - in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download few videos. In this plan you will receive a discount of 50% in each video. Subscribe for this package!

Package of 50 credits – in this case the price for this post is US$ 0,00
This subscription is ideal if you want to download several videos. In this plan you will receive a discount of 83% in each video. Subscribe for this package!


> More info about MrBool Credits
[Close]
You must be logged to download.

Click here to login