RocketMQ learning process (4)----message processing (2)

1. Two consumption patterns of consumers

insert image description here

  • Sequential Consumer Mode:
    In the sequential consumption mode, messages in the message queue are consumed sequentially by consumers in the order they are sent. Each message queue will only be consumed by one consumer thread to ensure the order of messages. This mode is suitable for scenarios that need to maintain the order of messages, such as order processing, business processes, etc.

  • Concurrent Consumer Mode:
    In the concurrent consumption mode, messages in the message queue can be consumed concurrently by multiple consumers . Each message queue can be consumed by multiple consumer threads at the same time, improving the concurrency of consumption. The order of messages is not guaranteed in this mode. This mode is suitable for scenarios that do not have strict requirements on the order of message processing, such as logging, broadcast notifications, etc.

According to specific business needs and scenarios, you can choose an appropriate consumption mode. If the order of messages is very important to the business, then the sequential consumption pattern is a more appropriate choice. If concurrency is a more important consideration , and message processing order is not strictly required, then concurrent consumption mode can provide better throughput and performance.

2. Message accumulation

2.1. Possible reasons for consumption accumulation:

  1. Slow consumer processing : If the processing speed of consumers cannot keep up with the production speed of messages, messages will accumulate in the queue. This may be caused by complex consumer processing logic, insufficient consumer resources, or heavy consumer load.

  2. Network delays or failures : When a network is delayed or fails, the delivery of messages can be slowed or interrupted, causing messages to accumulate in queues. This may be caused by unstable network connection, message transmission channel congestion, or abnormal message transmission.

  3. Message processing failure : If an error or exception occurs during the processing of the message on the consumer side, causing the message consumption to fail, but it is not processed correctly or retried, then these messages will accumulate in the queue. It may be caused by program bugs, dependent service failures, or abnormal data.

  4. Messages are produced too fast : When messages are produced faster than consumers can process them, messages accumulate in the queue. This may be due to reasons such as increased system load, business peak hours, or insufficient message producer resources.

  5. Unreasonable queue configuration : If the capacity of the queue is set too small to meet the production and consumption needs of messages, it will easily lead to message accumulation. In addition, if the priority setting of the queue is unreasonable or the number of concurrency of message consumers is not configured correctly, it may also cause message accumulation.

Solution:

  1. Monitor and adjust the processing power of consumers to ensure that consumers can process messages in a timely manner.
  2. Regularly check network connections and transmission channels to ensure that messages can be transmitted normally.
    Handle the failure of message consumption, implement a retry mechanism or manually process the failed message.
  3. Adjust the rate of message producers according to business needs and system load conditions.
    Reasonably set the queue capacity and priority to ensure that the queue can adapt to the production and consumption needs of messages.
  4. Use monitoring tools to monitor the status of message queues in real time , discover and deal with accumulation problems in time.

3. Missing messages

3.1. Possible reasons:

  1. Producer sending failure : When an error or exception occurs when a message producer sends a message, the message may be lost. For example, network connectivity issues, producer crashes, or send timeouts can cause messages to fail and be lost.

  2. Middleware failure : If the message middleware (such as message queue) itself fails or is abnormal, messages may be lost. This could be due to hardware failures, software bugs, unstable network connections, or configuration issues, among other things.

  3. Message transmission failure : When messages encounter problems during transmission, such as network delays, transmission channel congestion, or transmission errors, messages may be lost.

  4. Message consumption failure : When an error or exception occurs during the processing of a message on the consumer side, the message consumption fails and is not processed or retried correctly, which may also cause the message to be lost.

3.2. Solution:

  1. Implement a reliable message sending mechanism , such as using the persistence mechanism provided by the message queuing system, to ensure that messages are stored persistently when they are sent, and can be recovered after a failure occurs.
  2. Use transactional messaging or acknowledgment mechanisms to ensure that messages are acknowledged after they are sent to avoid delivery failures and message loss.
  3. Set an appropriate persistence strategy and replication mechanism at the message middleware level to ensure reliable delivery and storage of messages.
    Implement idempotent processing on the message consumer side to prevent repeated consumption or processing of messages.
  4. Use monitoring tools to monitor the status of message queues and consumers in real time , and find and handle abnormal situations in time.
  5. Consider the possibility of message loss when designing your application and implement appropriate error handling and retry mechanisms.

To sum up:
the idea of ​​troubleshooting MQ faults:
from software to network to hardware:
insert image description here

  1. Determine the running status of the software : check the running status of the broker, whether it is running normally, and check the accumulation or processing of messages.
  2. Check the smoothness of the network : Check whether the network access is smooth, whether there are hard network exceptions, network interruptions, network packet loss, etc. Whether access to the nameserver, broker, software port access within the architecture is smooth.
  3. Check the server hardware : Check whether the memory is full and stop abnormally, check the cpu, hard disk read and write, or the server is overheated.

Guess you like

Origin blog.csdn.net/faker1234546/article/details/130794481