3.3 Case 2: job queue, jobqueue

Source: Internet
Author: User

3.3 Case 2: job queue, jobqueue

The 2nd cases are work queues. A typical point-to-point message, a Producer sends a work message to the queue, and a Consumer with a Listener class can obtain a work-condition message from the work queue, after the message is consumed by the consumer, it does not exist. It belongs to a one-to-one mode, this is different from the stock futures in the 3.2 case, which can publish a price to multiple subscribed consumers.

Another difference: After the Producer uses the message Producer to send 100 messages to the queue, the Producer immediately closes the connection, which is the same as 3.2. Since then, these 10 messages still exist in the message domain of the JMS server, and then the consumer will consume these messages when they are running, so they do not need to be online all the time, messages in the queue will not die. This is also different from the 3.2 case.

Start procedure:

1. Start ActiveMQ.

2. The first thing to run is the Producer class.

3. Run the Consumer class.

Note that:

1. It doesn't matter who starts it this time, because the message will be temporarily stored in the queue for a period of time, and it doesn't matter who starts it first. I have confirmed this many times, and, the message consumed by the consumer is complete, and no one is missing.

2. The description of the "point-to-point" mode should be specifically "point-to-point message ". If it is understood as a producer and a consumer, it is wrong to understand that a producer can only consume messages sent by one consumer, but other consumers cannot, because the message is a one-time message, nothing changes in the queue after entering the queue, and the queue image is like a pass-through sub-container, I just kept this message in it for a while without it.

Here is the point-to-point message mode diagram I understand:

 

 

Appendix: program running result:

 

 

 

 

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.