RocketMQ producer-detailed explanation of core parameters
producerGroup: The group name must be unique in an application.
createTopicKey: The topic is created by the producer, but it is generally not produced by the producer, and generally maintained by the members of the architecture group.
defaultTopicQueueNums: The default is 4, and 4 queues are managed by default under a topic.
setMsgTimeout:Unit in milliseconds, set the timeout time for message sending
compressMsgBodyOverHowmuch: The default compression byte is 4096, and the message automatic compression mechanism is conducive to network transmission and reduces bandwidth.
retryTimesWhenSendFailed: When the message fails to be sent, you can set the retransmission, synchronous retransmission strategy, and an asynchronous retransmission strategy.
retryAnotherBrokerWhenNotStoreOK: Default false
maxMessageSize: The maximum message limit. If the message exceeds this setting, an exception will be thrown. The default is 128K.
Analysis of master-slave synchronization mechanism
Master-Slave master-slave synchronization
Synchronization message: data content + metadata information, metadata information is synchronized by a scheduled task, and data content is synchronized in real time.
Metadata synchronization: Broker will recognize the role, and if it is a slave, it will start the synchronization task.
Message synchronization: The code is in the store module, HAService, HAconnection, WaitNotfiyObject, these three classes mainly synchronize CommitLog.
RocketMQ synchronous message sending
Synchronous sending of messages:producer.send(msg)
The core implementation of sending messages synchronously:DefaultMQProducerImpl
The core implementation of asynchronous message sending:DefaultMQProducerImpl
Analysis of Netty's underlying communication framework
Diagram
RocketMQ message data distribution diagram
Message length: Indicates the total length of the message, occupying 4 bytes int type length
Serialization type and header length: serialization type (JSON or other, etc.), header length, occupying 4 bytes int type length
Message header data: the message header data after serialization
Message main data: binary data
RocketMQ producer-message return status (SendStatus) detailed
SEND_OK: The message was sent successfully
FLUSH_DISK_TIMEOUT: The message is sent successfully, but the server has timed out when flushing the data, which will cause data loss
FLUSH_SLAVE_TIMEOUT: When master-slave synchronization, synchronization to SLAVE timeout will cause data loss
SLAVE_NOT_AVAILABLE: SLAVE is not available, and the message enters the server queue, which will cause data loss
RocketMQ producer-delayed message
延迟消息: After the message is sent to the Broker, it will take a certain time to be consumed by the Consumer
Currently RocketMQ只支持固定精度的延迟
MssageStoreConfigConfiguration class & ScheduleMessageServicetask class
Setting on Message: setDelayTimeLevelMethod setting
RocketMQ producer-custom message sending rules
How to send the message to the specified queue ( Message Queue)?
MessageQueueSelector: A Topic will have multiple Msg Queues, if set, the default is 4, and the producer will send messages to the four Queues in turn. This is a load balancing mechanism
producer.send(Msg, Selector, Obj): Without specific settings, it is impossible to send a message to a specific queue, unless a specific rule is made, this method is needed. When sending a message, specify a Selector to select a specific queue. , Obj can do a match based on the queue name