In the previous article, the author presented an example of the process of developing Java EE applications in was CE v2.1, covering many of the new features of Java EE 5, including: Java Server Faces (JSF), Java Persistence API ( JPA), Enterprise Java Bean (EJB), and Jax-ws 2.0. As a second article in this series, this article introduces another technical--JMS (Java message Service) of Java EE 5.
Introduction to JMS
What is JMS
JMS is also part of the Java EE 5 specification, which is used primarily for messaging and management of applications. The current version of the JMS specification is 1.1, the specification defines a set of APIs, and the JMS implementations are left to be provided by different vendors. The implementation of JMS is called the JMS Provider.
JMS is a messaging-oriented middleware (message oriented middleware,mom). Compared with CORBA, DCOM, RMI and other communication methods, JMS has many new features:
Messages are sent and received asynchronously, and the sender does not have to wait.
Can one-to-many communication: For a message can have multiple recipients.
The life cycle of the sender and receiver does not need to be the same: the receiver does not necessarily run when the message is sent, and the sender does not necessarily run when the message is received.
While other modes of communication are also characteristic of JMS, JMS combines three features and undoubtedly provides great flexibility for application development. Because of the good features of JMS, various JMS Provider have emerged. Among them, the implementation of the open source community, such as ActiveMQ, Openmq, also has a commercial implementation, such as Websphere MQ.
Message model for JMS
The great flexibility of JMS is closely related to its messaging model. There are two types of message models in JMS: The Publish/Subscribe message model and the point-to-point messaging model.
1. Publish/Subscribe message model
In the Publish/subscribe model, the sender of the message communicates with the receiver through the subject (TOPIC). The sender publishes the message under the given Topic, and the recipient subscribes to the Topic to receive the message published under Topic. The Publish/subscribe model is characterized by a publisher who can send messages to multiple receivers, or even multiple publishers using the same Topic to publish messages, and all recipients who subscribe to Topic receive messages.
Depending on the characteristics of the Publish/Subscribe message model, you can use the message model in a one-to-many scenario. That is, you can use the Publish/Subscribe message model When you have a publisher who needs to send messages to multiple recipients. This scenario is very similar to RSS's message subscriptions, with several recipients subscribing to the same "feed", and any message under the feed will be received by all subscribers.
2. Point to Point message model
The point-to-point message model is simpler compared with the Publish/subscribe model. The message sender and receiver use the same message queue (queue), the sender sends the message to the message queue, and the receiver goes directly to the queue to fetch the message. The point to Point message model is characterized by: messages in message queues can only be taken away by one recipient, and messages continue to be stored in message queues if no recipient receives the message.
Depending on the characteristics of the point-to-point messaging model, the message model can be used in a "one-to-one" scenario. That is, when a sender needs a specific recipient to send a message, a point-to-point message model can be used. This scenario is similar to when a sender sends a "message" to the receiver, and only the specified recipient can see "mail" in his or her "Mailbox".
JMS Provider in was CE
The previous article briefly introduced a Java EE 5 certified Application Server-was CE (Websphere application Server Community Edition). Was CE with ActiveMQ as its own JMS Provider. The application of JMS can be easily developed through ActiveMQ. ActiveMQ is an open source project in the Apache community with the following features:
The Resource Adapter, which complies with the JCA (Java Connector Architecture) 1.5 specification, can be used on a variety of application servers, such as Apache Geronimo, Redhat JBoss, GlassFish, and O Racle WebLogic.
Use JDBC to support rapid persistence of messages.
It can be used for Cluster, C/S architecture and Peer-to-peer (peer-to-peer) Message delivery.
Can be used as a stand-alone JMS platform (no application server) for unit testing.
As a top project in the Apache community, ActiveMQ is still evolving. Its good characteristic also for was CE to add a lot of. The remainder of this article expands the examples in the previous article to illustrate the development process for JMS applications in was CE 2.1.