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: