"Activemq-5" activemq Comparison of learning-queue and topic

Source: Internet
Author: User

A comparison between Queue and Topic

1 ,JMS Queue Execute Load balancer semantics:

A message can only be received by one consumer .

If there is no consumeravailable when the message is sent, it will be saved until the consumer that can handle the message is available.

If a consumer receives a message and does not respond to it, then the message will be transferred to another consumer .

A Queue can have a lot of consumerand load balance in multiple available consumer .

How to understand: if a consumer receives a message and does not respond to it, then the message will be transferred to another consumer .

See the procedure in the annex:


in the Receiver.java, Create a consumer and achieve a synchronous receive:

  
 
  1. while (true) {
  2. // 设置接收者接收消息的时间,为了便于测试,这里谁定为100s
  3. TextMessage message = (TextMessage) consumer.receive(18000);
  4. // Object message = (Object) consumer.receive(28000);
  5. if (null != message) {
  6. System.out.println("订阅者1:收到消息-->" + message.getText());
  7. } else {
  8. System.out.println("订阅者1:运行结束...\n");
  9. break;
  10. }
  11. }

in the Receiver2.java, the program that created the consumer but commented out the receiving part:

  
 
  1. //while (true) {
  2. //// 设置接收者接收消息的时间,为了便于测试,这里谁定为100s
  3. //TextMessage message = (TextMessage) consumer.receive(18000);
  4. //if (null != message) {
  5. //System.out.println("订阅者2:收到消息-->" + message.getText());
  6. //} else {
  7. //System.out.println("订阅者2:消费者运行结束...\n");
  8. //break;
  9. //}
  10. //}
First, separate thereceiver andReceiver2 Run and then run sender, you will get the following results:

Special Note: Subscriber 2 stops after subscriber 1, how to stop before Subscribers 1, the result is not the same.
When you turn on receive1 again, you will see:

if Subscriber 2 stops before Subscriber 1, and the following results will appear:


2 ,Topic implement Publish and Subscribe semantics:

When a message is publish , it will be sent to all interested subscribers, so 0 to multiple Subscriber will receive a copy of the message. However, when the message agent receives a message, only the subscriber that activates the subscription can get a copy of the message.

3 , respectively, corresponding to two message modes:

Point-to-Point ( Point-to-point ), Publisher/subscriber Model ( publisher / subscriber )

Where in publicher/subscriber mode There are nondurable subscription(non-persistent subscriptions) and Durable subscription ( persistent subscription ) 2 kinds of message processing methods.


 




From for notes (Wiz)

List of attachments

    "Activemq-5" activemq Comparison of learning-queue and topic

    Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.