JMS 基本概念

消息的消费

在JMS中,消息的produce 和 comsume 是异步的。对于消费者来说,JMS的消息者可以通过两种方式来消费消息

(1)同步 

订阅者者或消费者调用receive方法来接收消息,receive方法在能够接收到消息之前(或超时之前)将一直阻塞

(2)异步

订阅者或者消费者可以注册为一个msg listener 。当消息到达后,系统自动调用监听器的onMessage method

JMS基本组件

ConnectionFactory(连接工厂) 

创建Connection对象的工厂,针对两种不同的JMS消息模型,分别对应

QueueConnectionFactory

TopicConnectionFactory

可以通过JNDI来查找ConnectionFactory

Destination(session build 的msg queue或topic)

分为Queue 和Topic,通过JNDI 来查询对应的Destination

Connection(factory build 出来的连接)

connection表示client和JMS系统之间的连接(对TCP/IP,socket的包装)。connection可以产生一个或者多个Session实例对象。

QueueConnection

TopicConnection
 

Session(连接创建出的session)

消息操作的接口,通过session创建生产者、消费者、消息等。Session提供了事务的功能。当我们需要使用session send/receive 多个消息的时候,可以将这些send/receive action 放到一个事务中。

 QueueSession

 TopicSession

Producer

消息生产者由Session创建,并用于将Msg发送到Destination.

QueueSender

TopicPublisher

use producer's method send/publish  msg  

Comsume

由Session创建,用于receive the sended msg from Destination

QueueReceiver

TopicSubscriber

by using session's  createReceiver(Queue) method

or createSubscriber(Topic) method

creatDurableSubscriber the same for persistence

MessageListener

消息监听器。如果注册了消息监听器,只要有Msg 到达,将自动监听 Listener的OnMessage method

EJB中的MDB(Message-Driven Bean) 就是一种MessageListener

è¿éåå¾çæè¿°

猜你喜欢

转载自blog.csdn.net/kevin_loving/article/details/81982667
jms