JMS 基础概念(一)

A JMS application is composed of the following parts.

      1) A JMS provider is a messaging system that implements the JMS interfaces and provides administrative and control features. An implementation of the J2EE platform at release 1.3 and later includes a JMS provider.
      2)JMS clients are the programs or components, written in the Java programming language, that produce and consume messages. Any J2EE application component can act as a JMS client.
      3) Messages are the objects that communicate information between JMS clients.
      4) Administered objects are preconfigured JMS objects created by an administrator for the use of clients. The two kinds of JMS administered objects are destinations and connection factories, which are described in Administered Objects.
Figure 33-2 illustrates the way these parts interact. Administrative tools allow you to bind destinations and connection factories into a JNDI namespace. A JMS client can then look up the administered objects in the namespace and then establish a logical connection to the same objects through the JMS provider.

说明:JSM provider指的是实现JMS接口的第三方软件(比如activemq),我们的编程是在这基础上。工程代码中实现自己的生产者、消费者的逻辑代码。这有些类似一个开源框架pushlet,服务器端由用户自定义事件的产生(生产者),而客户端只需要实现相应的function即可(消费者)。( Administered objects 在下一篇文章中阐述)



          
Messaging Domains

     Before the JMS API existed, most messaging products supported either the point-to-point or the publish/subscribe approach to messaging. The JMS specification provides a separate domain for each approach and defines compliance for each domain. A stand-alone JMS provider can implement one or both domains. A J2EE provider must implement both domains.

     In fact, most implementations of the JMS API support both the point-to-point and the publish/subscribe domains, and some JMS clients combine the use of both domains in a single application. In this way, the JMS API has extended the power and flexibility of messaging products.

      The JMS 1.1 specification goes one step further: It provides common interfaces that enable you to use the JMS API in a way that is not specific to either domain. The following subsections describe the two messaging domains and then describe this new way of programming using common interfaces.

      Point-to-Point Messaging Domain
      A point-to-point (PTP) product or application is built on the concept of message queues, senders, and receivers. Each message is addressed to a specific queue, and receiving clients extract messages from the queues established to hold their messages. Queues retain all messages sent to them until the messages are consumed or until the messages expire.

     


     Point-to-Point Messaging的特性:
     1)Each message has only one consumer.
     2)A sender and a receiver of a message have no timing dependencies. The receiver can fetch the message whether or not it was running when the client sent the message.
     3)he receiver acknowledges the successful processing of a message.
     Use PTP messaging when every message you send must be processed successfully by one consumer

     Publish/Subscribe Messaging Domain
     In a publish/subscribe (pub/sub) product or application, clients address messages to a topic, which functions somewhat like a bulletin board. Publishers and subscribers are generally anonymous and can dynamically publish or subscribe to the content hierarchy. The system takes care of distributing the messages arriving from a topic's multiple publishers to its multiple subscribers. Topics retain messages only as long as it takes to distribute them to current subscribers.

         

     Publish/Subscribe Messaging的特性:
     1)Each message can have multiple consumers.
     2)Publishers and subscribers have a timing dependency. A client that subscribes to a topic can consume only messages published after the client has created a subscription, and the subscriber must continue to be active in order for it to consume messages.

说明:Point-to-Point Messaging和Publish/Subscribe Messaging关于timing dependency,前者没有依赖关系,而后者必须有依赖关系,订阅者必须要在订阅的主题产生之前才能有效接受相应的消息,而且订阅者必须是在active状态才能接受消息;前者则没有这种制约,消息会一直保存知道订阅者获取消息或者设置的时间戳期限到。前者发布消息后,分发给活动状态的订阅者,消息销毁。

The JMS API relaxes this timing dependency to some extent by allowing subscribers to create durable subscriptions, which receive messages sent while the subscribers are not active. Durable subscriptions provide the flexibility and reliability of queues but still allow clients to send messages to many recipients.

Message Consumption

     Messaging products are inherently asynchronous: There is no fundamental timing dependency between the production and the consumption of a message. However, the JMS specification uses this term in a more precise sense. Messages can be consumed in either of two ways:
     1)Synchronously: A subscriber or a receiver explicitly fetches the message from the destination by calling the receive method. The receive method can block until a message arrives or can time out if a message does not arrive within a specified time limit.
     2)Asynchronously: A client can register a message listener with a consumer. A message listener is similar to an event listener. Whenever a message arrives at the destination, the JMS provider delivers the message by calling the listener's onMessage method, which acts on the contents of the message.

【注意】:时间依赖关系和消费信息方式(同步或者异步)是两个不同的概念
         1) 时间依赖关系是指的生产者(发布者)和消费者(订阅者)之间的先后顺序(信息产生是在信息订阅之前还是之后)以及消费者是否处于活动状态;
         2)消费信息方式是指消费者是等待直到有消息产生呢还是个干个的事情,直到有消费产生我在回过头处理相应的消息。

JMS的基本概念了解后,后一篇阐述 The JMS API Programming Model
    

猜你喜欢

转载自fay19880111-yeah-net.iteye.com/blog/1636450
jms