Friday, 13 September 2013

Spring JMS Configuration

Java Messaging Service (JMS) API is a crucial member of Java Middleware Application communicating between two or more systems by sending messages. Specification developed under Java Community Process and known as JSR 914.

If your Java application is in distributed environment and the focus is on Loose Coupling, reliability,  asynchronous mode then JMS is an ideal candidate to opt out.

What are the components involved in JMS?

JMS Producer - An application or Java component creates and sends the message. This also known as the JMS Publisher

JMS Consumer - An application or Java component responsible for receiving the messages. The component also known as JMS subscriber.

JMS QueueLogical space that contains messages that have been sent and are waiting to be read in practice the messages are read by one consumer.

JMS Topic - Mechanism for conveying or sending messages that are delivered to multiple subscribers.

Mode of Operation

Point-To-Point  messaging system involves transmitting of messages to intended consumers which maintains the queue for "inbound" messages. Any number of producer can send the message to the queue but only one consumer will get the message. The messages remains in queue until consumed by the consumer.

Publish-Subscribe messaging system supports for broadcasting message to particular topic. Subscribers needs to register themselves to the particular topic if they are interested to get more details on the topic.

Do I need to implement the specification from scratch?
No. There are already providers available in the market, some of them are :
  1. Apache ActiveMQ
  2. HornetQ in JBoss
  3. IBM WebSphere MQ
Demonstration
To demonstrate some functionality how it works lets drill down and makes our hand dirty by coding !! Let's go with steps:

Step 1: Identify provider-> Apache ActiveMQ
Step 2: Identify Application Sandbox - > Spring
I prefer Spring Framework, it provides most of the inbuild helper component to build up fastly:

jms-demo-context.xml



<context:component-scan base-package="com.rp.jms.demo"/>

<bean id="conFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
    <property name="brokerURL" value="tcp://localhost:61616"/>
 </bean>

<bean id="rpJMSTemplate" class="org.springframework.jms.core.JmsTemplate">
     <property name="connectionFactory" ref="conFactory"/>
</bean>

Next we will cover the Java Components... Stay Tuned.


No comments:

Post a Comment