Push and pull modes of rocketMQ consumer

Push and pull modes
In RocketMQ, consumers have two modes, one is push mode and the other is pull mode.
Push mode: After the client establishes a connection with the server, when the server has a message, the message is pushed to the client.
Pull mode: The client continuously polls the request server to obtain new messages.
However, in the specific implementation, both Push and Pull modes use the consumer-side active pull method, that is, the consumer polls to pull messages from the broker.
the difference:

  • In Push mode, the consumer encapsulates the polling process and registers the MessageListener listener. After receiving the message, it wakes up the consumeMessage() of the MessageListener to consume it. For the user, it feels that the message is being pushed.
  • In the Pull method, the process of fetching messages needs to be written by the user. First, get the collection of MessageQueue through the Topic you intend to consume, traverse the collection of MessageQueue, and then fetch messages in batches for each MessageQueue. After fetching once, record that the queue will be fetched next time The start of the offset, until the end of the fetch, and then change to another MessageQueue.

Question: Since it is implemented in pull mode, how does RocketMQ ensure the real-time performance of messages?

Long polling
RocketMQ adopts the long polling method. What is long polling?
Long polling is in the process of requesting, if the server-side data is not updated, then the connection is suspended until the server pushes new data, and then returns, and then enters the cycle.
The client requests data from the server like traditional polling. The server will block the request and will not return immediately. It will not return to the client until there is data or timeout, and then close the connection. The client will send a new message to the server after processing the response. Request.

The pull mode is hardly used in work

Guess you like

Origin blog.csdn.net/qq_26896085/article/details/104958768