JMS Learning Eleven (Exclusive Consumer of ActiveMQ Consumer Advanced Features)

1. Introduction

The messages in the Queue are distributed to consumers in order. However, when you have multiple consumers fetching messages from the same queue at the same time,

You will lose this guarantee. Because these messages are processed concurrently by multiple threads. Sometimes it is important to ensure that messages are processed in order.

For example, you may not want to update the order until the insert order operation is complete.

  technology sharing

2. Use

ActiveMQ supports Exclusive Consumer since version 4.x. Broker will select a consumer from multiple consumers to process the queue

All messages, thus ensuring the orderly processing of messages. If the consumer fails, the broker will automatically switch to another consumer. 

An Exclusive Consumer can be created through DestinationOptions, as follows:

queue = new ActiveMQQueue("TEST.QUEUE?consumer.exclusive=true");
consumer = session.createConsumer(queue);

 

You can also set priorities for consumers to optimize for network conditions, as follows:

queue = new ActiveMQQueue("TEST.QUEUE?consumer.exclusive=true&consumer.priority=10");

A. When there are one or more backup message recipients and an exclusive message recipient when receiving information at the same time, regardless of the order in which the two are created, at the time of receiving, both are received by the exclusive message recipient.

b. When there are multiple exclusive consumers when receiving information, only one exclusive consumer can receive the message.

c. When there are multiple backup messagers and multiple exclusive consumers, when all exclusive consumers are closed, only one backup consumer receives the message.

 

Solve a queue parallelism problem:

service by queue

 

Split the business logic consumer to process different businesses, respond after processing, and confirm that the message consumption is successful. When all 10 messages are consumed,

Or according to the specific business situation, for example, if only 8 messages are processed successfully, should the program continue to execute, record logs, process after the event, or roll back the data immediately? Flexible handling

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325247357&siteId=291194637