JMS中queue和topic区别

JMS中queue和topic区别

2008-07-08 13:16

What is the difference between queue and topic?

A connection is created between the client and the server from a connection factory. Connections can be shared by several threads. The user credentials are supplied at this level. It is probably common for a client application to share access to a single connection to the server (unless different security credentials are required for different destinations).
A session is created from a connection. The session may only be used by one thread at one time. The user credentials are inherited from the parent connection. It is probably common for each MessageProducer (TopicPublisher or QueueSender) or MessageConsumer (TopicSubscriber or QueueReceiver) to have their own session due to the threading restriction.
You can look at it like a tree. At the top you have a connection factory, beneath this you have your connections and then beneath the connections you have sessions. The leaves of the tree are the JMS actors (MessageProducers and MessageConsumers).

References: Creating Robust JMS Applications : http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JMS6.html

两种JMS的实现方法:
Topic==>消息主题 是发布/订阅 机制 一个消息产生多个对应 1:N
Queue==>消息队列 是点到点 一个消息产生一个对应 1:1  

g

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
JMS(Java消息服务),消息的传递是通过消息介(Message Broker)来实现的。消息介可以是消息队列(Queue)或者主题(Topic)。 JMS提供了两种不同类型的目的地(Destination):队列(Queue)和主题(Topic)。队列目的地是点对点(Point-to-Point)的消息传递模型,而主题目的地是发布/订阅(Publish/Subscribe)的消息传递模型。 队列目的地用于实现点对点的消息传递,即一个消息只能被一个消费者消费。消息生产者将消息发送到队列,而消息消费者从队列接收消息。队列目的地是一种持久化的目的地,也就是说,当消息生产者发送消息到队列时,即使没有消费者在线,该消息仍然会被保存在队列,直到有消费者连接并接收该消息为止。 主题目的地用于实现发布/订阅模型的消息传递,即一个消息可以被多个消费者消费。消息生产者将消息发送到主题,而消息消费者从主题接收消息。主题目的地是一种非持久化的目的地,也就是说,当消息生产者发送消息到主题时,如果没有消费者在线,该消息将会被丢弃,不会被保存在主题。 在JMS,消息的发送和接收都是通过目的地来实现的。发送消息时,需要指定消息发送到哪个目的地,而接收消息时,需要注册一个消息监听器,从指定的目的地接收到消息后,会自动触发消息监听器的回调方法,执行业务逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值