Please indicate the original source, thank you!

RocketMQ network deployment diagram

  • NameServer: In the system does the naming service, updates and discovers the broker service.
  • Broker-master: Broker message host server.
  • Broker-slave: Broker messages to the Slave server.
  • Producer: indicates message producers.
  • -Penny: Consumer.

Note: The RocketMQ series will be described in RocketMQ-4.0-incubating.

Rocketmq can be obtained based on RocketMQ4.1.0 plus detailed Chinese code notes. Welcome star, Fork!

RocketMQ(8) : Message sending mainly analyzes the general sending process, this article will introduce the timing of sending, sequential sending, batch sending and so on.

Message Sending Overview

The diagram above is probably the core logic for the producer to send messages to the broker.

Note: This article will introduce timing, sequence, and batch sending. All of these cases are explained from the perspective of producer. The content related to brokers will be analyzed when analyzing the content related to brokers.

Regularly send

What is a timed message

The Producer sends a message to the MQ server, but does not expect the message to be delivered immediately. Instead, the message is delivered to a Consumer after a certain amount of time.

Call form

It is basically no different from ordinary call sending, except that there is a message set setDelayTimeLevel. The code call is shown below:

So what should be the level here? And what does that correspond to? –> This piece will be analyzed in the future. Today, here is a brief explanation:

The rest is no different from normal sending, the key processing is in the broker, subsequent analysis.

The order sent

What is the order of sending

Reference: https://help.aliyun.com/document_detail/49319.html?spm=a2c4g.11186623.2.3.21aKRd

Call form

Let’s take a look at the implementation call to see what’s going on:

  • Get all the information that can be sent

  • Send content

  • Used to distinguish (e.g., order numbers, which are sequential but can be unordered with other order numbers)

 sendResult = producer.send(msg, new MessageQueueSelector() { @Override public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) { Integer id = (Integer) arg;  int index = id % mqs.size();return mqs.get(index);
                    }
                }, orderId);
Copy the code

In this case, MQS is to fetch all the information that can be sent, and orderId is used to distinguish. Every time this orderId is used to fetch all the information (if all the information does not change below), then one is fixed to the same queue (queue is fifo), and the subsequent consumption is to analyze how the consumption processes this piece.

** Note: ** This order is also relative, if the broker is added or reduced, then the information will be inconsistent, so you need to understand.

Batch send

What is batch delivery

I’m sure you’re all familiar with the concept of batch. In many tuning scenarios, such as database batch processing, some requests are merged and sent, rocketMQ batch is also designed to achieve performance, especially when the volume is very large.

** Note: ** Since the batch is sent after a batch, then the real time must be slightly delayed (can be ignored, especially in the case of a large amount of data). I generally deal with the batch of two dimensions, reach one can trigger, 1. Reach a given number of 2. Reach a given time (e.g., 3s, if the amount of data is still insufficient at this time, it will also send)…

Rocketmq simply provides the interface to send a batch of data, and it is up to you to choose when to send that batch of data. The two above are general practices:

  • Reaches a given number of bars.
  • Reaches the given time.
Call form

Rocketmq does a simple conversion to reduce network traffic when sending in bulk.

Convert these into a, B, C, etc.

Let’s take a look at the batch delivery examples rocketMQ gave us, why did they give us 2 examples? Need to think!! , I will explain to you below:

Note: Batch delivery requires the same topic and the same waitStoreMsgOK and timed delivery is not supported.

Messages of the same batch should have: Same topic, same waitStoreMsgOK and no schedule support.

This type of delivery is called a batch (the batch here is not particularly large), and it just sends itself out.

The batch here (the batch data is too much), so it is segmented and sent. The final method is the same.

We know that RocketMQ currently supports 4M message content (either single or batch) by default, and it can be adjusted if needed, so will there always be no upper limit? There are also many people who say why the adjustment of 10M does not take effect. The adjustment requires both the Producer and the server broker to adjust it, and since it is based on Netty network transmission, you may need to look at RocketMQ(2) : RPC communication, which is explained here.

Here decided the maximum maximum can only be 16M, if necessary, need to modify, generally not recommended to modify, and batch send the second way on the same line, to open the batch send is.


If you feel that you have gained something after reading it, please click “like”, “follow” and add the official account “Ingenuity Zero” to check out more wonderful history!!

Join knowledge Planet and discuss together!