Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the best practices for Rocket sequential messages

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article will explain in detail what the best practices about Rocket sequential messages are, and the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have some understanding of the relevant knowledge after reading this article.

Sequence message defect

Sending sequential messages cannot be consumed by using the cluster Fail Over feature, and the parallelism of sequential messages depends on the number of queues, and there is a queue hotspot problem. In some queues, there are too many messages due to uneven hashing, and the consumption speed can not keep up. Due to the problem of message accumulation, messages that fail can not be skipped, and the current queue consumption is suspended.

Principle

When produce sends a message, it sends the message to the same queue, and the consumer registers the message listener as MessageListenerOrderly, which ensures that there is only one thread on the consumer side to consume the message.

Note: send messages to the same queue (queue), not the same topic. By default, a topic includes 4 queue.

Expansion

Partial sequential messages can be implemented by implementing a queue selector method that sends messages.

Example: for example, if a database is synchronized through MQ, you only need to ensure that the data of each table is synchronized. Parse the binlog and use the table name as the parameter of the queue selector, which ensures that the data of each table is in the same queue, thus ensuring the sequential consumption of the table data.

Best practices Producer

Topic

An application uses a Topic as much as possible, the message subtype is identified by tags, and the tags can be set freely by the application. Only if tags is set for sending messages, consumers can use tags to filter messages in broker when subscribing to messages.

Key

The unique identification code of each message at the business level should be set to the keys field to facilitate the identification of message loss in the future. The server creates an index (hash index) for each message, and the application can query the content of the message through topic,key and who consumes the message. Because it is a hash index, it is important to make sure that the key is as unique as possible to avoid potential hash conflicts.

/ / order Id

String orderId= "20034568923546"

Message.setKeys (orderId)

Journal

If the message is sent successfully or failed, to print the message log, be sure to print the send result and key fields.

Send

Send message method, as long as no exception is thrown, it means that the message was sent successfully. However, there will be multiple states for successful delivery, which is defined in sendResult.

SEND_OK: message sent successfully

FLUSH_DISK_TIMEOUT: the message was sent successfully, but the server flush timed out, and the message has entered the server queue. Only when the server is down, the message will be lost.

FLUSH_SLAVE_TIMEOUT: the message was sent successfully, but the server timed out when it synchronized to Slave, and the message has entered the server queue. Only when the server goes down will the message be lost.

SLAVE_NOT_AVAILABLE: the message was sent successfully, but the slave is not available and the message has entered the server queue. Only when the server goes down will the message be lost.

Consumer

Idempotent

The message primitive used by RocketMQ is At Least Once, so consumer may receive the same message many times, so be sure to be idempotent at this time.

Journal

Keep a log when consuming so that the problem can be located later.

Bulk consumption

The use of bulk consumption as far as possible can greatly improve the consumption throughput.

This is the end of the best practices on Rocket sequential messages. I hope the above can be helpful to you and learn more. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report