Spring Series, Part 4: Spring JMS Message Processing 1-2-3

Source: Internet
Author: User
Tags sessions

Learn the basics of using the Spring JMS framework and IBM WebSphere MQ 5.3 for JMS message processing.

In the 4th and final installment of the Spring Series, I'll describe the characteristics of the spring JMS (Java messaging) framework. JMS PG defines a standard way for Java applications to create and exchange messages through message-oriented middleware (MOM).

As in previous articles in this series, I'll use a simple example to illustrate the characteristics of Spring JMS. Along with me, you will develop a point-to-point (peer-to-peer), messaging based system that uses the Spring JMS framework to integrate with IBM's WebSphere MQ via the JMS interface. After completing the exercise, you will be able to send and receive simple text messages through this system.

Before you begin, download the source code for the article. See resources for access to the Spring framework and IBM WebSphere MQ 5.3. You also need Apache Ant to run the sample application.

Spring JMS

Spring's JMS abstraction framework simplifies the use of the JMS API and integrates smoothly with JMS providers such as IBM's WebSphere MQ 5.3. The Org.springframework.jms.core package provides the core functionality of using JMS in Spring. Its template class handles the creation and release of resources, simplifying the use of JMS.

Like most other Spring template classes, the JMS template class provides a helper method for performing common operations. In situations where more complex applications are required, the class delegates the core of the processing task to the user-implemented callback interface. The JMS class provides a convenient way to send messages, use messages synchronously, and expose the creator of JMS sessions and messages to users.

The following JMS packages and Org.springframework.jms.core together make up the functionality of Spring JMS:

Org.springframework.jms.support provides the ability to convert jmsexception. The transformation code converts the detected jmsexception hierarchy into a mirrored hierarchy that does not detect an exception. Org.springframework.jms.support.converter provides a messageconverter abstraction to convert between Java objects and JMS messages. Org.springframework.jms.support.destination provides different strategies for managing JMS goals, such as service locators for targets saved in JNDI. Org.springframework.jms.connection provides connectionfactory implementations that are suitable for use in stand-alone applications. Connection also contains the Spring Platformtransactionmanager implementation for JMS. It allows the integration of JMS as a transactional resource into Spring's transaction management mechanism.

IBM WebSphere MQ

As mentioned earlier, the sample application integrates with IBM's WebSphere MQ through the JMS interface with the Spring's JMS framework. WebSphere MQ provides reliable, recovery-capable application integration by passing messages between applications and WEB services. It uses queues and transactional tools to help maintain the integrity of messages across networks. WebSphere MQ reduces the risk of information loss and the need to reconcile communication IT systems.

WebSphere MQ provides a consistent application programming interface on all of the platforms it supports, which helps to make integrated programs portable. In addition to the standard interfaces, WebSphere MQ implements the JMS interface in its entirety, including support for publish-subscribe messaging. The WebSphere MQ Explorer tool can remotely manage and configure an entire MQ network. The management and configuration tools are based on the open source Eclipse framework and are extensible.

Spring JMS Templates

The Spring framework provides two implementations of Jmstemplate. The Jmstemplate class uses the JMS 1.1 API, and subclass JMSTEMPLATE102 uses the JMS 1.0.2 API. My sample application is using JMSTEMPLATE102.

JMS templates are used to send and receive JMS messages. Spring uses a callback mechanism to coordinate JMS information delivery. The Messagecreator callback interface creates a message using the session provided by the calling code in Jmstemplate. To support more complex applications of the JMS API, the callback Sessioncallback provides a JMS session to the user, while callback Producercallback exposes the sessions and messageproducer combinations.

Listing 1 shows the configuration of the JMS template used by the sample application. The manifest is excerpted from the Spring-mqseries-jms.xml file (see download).

Listing 1. JMS Template Configuration

<!-- JMS Queue Template -->
  <bean id="jmsQueueTemplate"
      class="org.springframework.jms.core.JmsTemplate102">
   <property name="connectionFactory">
    <ref bean="jmsQueueConnectionFactory"/>
   </property>
   <property name="destinationResolver">
    <ref bean="jmsDestinationResolver"/>
   </property>
   <property name="pubSubDomain">
    <value>false</value>
   </property>
   <property name="receiveTimeout">
    <value>20000</value>
   </property>
  </bean>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.