跳转到主要内容

单击提交则表示您同意developerWorks 的条款和条件。 查看条款和条件.

当您初次登录到 developerWorks 时,将会为您创建一份概要信息。您在 developerWorks 概要信息中选择公开的信息将公开显示给其他人,但您可以随时修改这些信息的显示状态。您的姓名(除非选择隐藏)和昵称将和您在 developerWorks 发布的内容一同显示。

所有提交的信息确保安全。

  • 关闭 [x]

当您初次登录到 developerWorks 时,将会为您创建一份概要信息,您需要指定一个昵称。您的昵称将和您在 developerWorks 发布的内容显示在一起。

昵称长度在 3 至 31 个字符之间。 您的昵称在 developerWorks 社区中必须是唯一的,并且出于隐私保护的原因,不能是您的电子邮件地址。

单击提交则表示您同意developerWorks 的条款和条件。 查看条款和条件.

所有提交的信息确保安全。

  • 关闭 [x]

JMS 1.1 simplifies messaging with unified domains

A quick introduction to JMS

Return to article

JMS is the standard Java API for accessing enterprise messaging products, such as WebSphere MQ (formally MQSeries) and TIBCO. There are two different but complementary approaches to performing enterprise messaging:

  1. Point-to-Point: Only one receiver consumes a particular message. An example is one program telling another to perform a task, such as an investing program telling a brokerage's system to buy a stock.

  2. Publish/Subscribe. A copy of each message is delivered to every subscriber. An example is one program notifying others of an event, such as a brokerage broadcasting a stock price.

Figures 1 and 2 (reprinted with permission from Java Message Service, O'Reilly & Associates, 2001) illustrate the difference between these two domains.


Figure 1. Point-to-point messaging
Point-to-point messaging

Figure 2. Publish/subscribe messaging
Publish/subscribe messaging

JMS (the javax.jms package) represents these two approaches using the interfaces Queue (point-to-point) and Topic (publish/subscribe). They extend the interface Destination , which represents a messaging channel that may be either point-to-point or publish/subscribe, as shown in Figure 3.


Figure 3: The JMS destination hierarchy
The JMS Destination hierarchy

A destination acts like an ordered-list data structure -- as messages are added, the destination lines them up for delivery. A produceradds messages to the list, whereas a consumer removes messages from the list. JMS represents these using the interfaces MessageProducer and MessageConsumer , respectively.

A message (the JMS interface Message ) is a unit of information, such as a request or a document, to be communicated from a producer to a consumer. When a producer adds a message to a queue, it is said to send the message. When a consumer removes a message from a queue, it is said to receivethe message.

Messages themselves work the same way in JMS 1.1 that they do in JMS 1.0.2. The difference is the code JMS clients use to send and receive messages.

Backwards compatibility

JMS 1.1 is fully backwards compatible with JMS 1.0.2, so client code written to send and receive messages using JMS 1.0.2 will work just fine with JMS 1.1. Also, the semantic difference between the behavior of Queue implementations and Topic implementations has been retained, so point-to-point and publish/subscribe messaging still work the same as they always have.

Therefore, JMS 1.1 does everything JMS 1.0.2 does. The difference is that JMS 1.1 has additions to its API so that most client code can treat a channel as a generic Destination . This is a big improvement over JMS 1.0.2 client code, which has to treat a channel specifically as a Topic or a Queue .

Return to article