In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "ActiveMq dead letter queue how to monitor", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's train of thought slowly in depth, together to study and learn "ActiveMq dead letter queue how to monitor" it!
To see if mq can be killed, we try to simulate 10000 requests and the maximum number of waiting queues is 53. In other words, when there is high concurrency, there is bound to be data inconsistency between the actual business and the database. When used with redis, you should (must) get data from redis as much as possible.
At this time, a dead letter queue message is found, and the specific cause is unknown. Analyze and solve this problem.
Generation of dead letter queues
Activemq uses asynchronous sending mode by default. If persistence is set but the transaction is not enabled, messages will be lost and mq downtime will be lost.
two。 What are the specific circumstances that will cause the message to be retransmitted?
① Client uses transactions and calls rollback in session
② Client uses transactions and shuts down or does not have commit before calling commit
③ Client calls recover in CLIENT_ACKNOWLEDGE delivery mode and session (allows message resending mode)
The retransmission interval of the message is 1 second, and the default maximum number of retransmissions is 6 times.
If a message is redelivedred more than 6 times, the consumer will give mq a "poison ack" to indicate that the message is poisonous, and the message will be put into the DLQ dead letter queue.
Since I am a local mq, I may get the mq of the test environment. Locally, I will enter the dead letter queue after 4 retries.
Where can I change it?
RedeliveryPolicy.setMaximumRedeliveries (3)
Public ActiveMQConnectionFactory connectionFactory () {ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory (brokerurl); / / trusts serialized objects under all packages to solve the problem that object messages cannot be sent: factory.setTrustAllPackages (true); factory.setUserName (userName); factory.setPassword (password); RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy (); redeliveryPolicy.setMaximumRedeliveries (3); / / modify the number of retransmissions to 3 factory.setRedeliveryPolicy (redeliveryPolicy) Return factory;}
Can also be modified in the configuration file
How do I handle messages in a dead letter queue?
1: manual treatment (too tired)
2: scheduled tasks (too performance-consuming)
3: monitor the dead letter queue
4: dead letter queue write library
How to monitor the dead letter queue?
Idea: a dead-letter queue is also a queue. Create a listener to listen to the dead-letter queue ActiveMQ.DLQ queue for messages, and consume if there are any messages.
/ * * @ author zhaokkstart * @ create 2020-09-07 16:27 * / import javax.jms.BytesMessage;import javax.jms.JMSException;import javax.jms.MapMessage;import javax.jms.Message;import javax.jms.MessageListener;import javax.jms.ObjectMessage;import javax.jms.StreamMessage;import javax.jms.TextMessage;import org.apache.activemq.command.ActiveMQDestination Public class QueueMessageListener implements MessageListener {@ Override public void onMessage (Message message) {try {ActiveMQDestination queues= (ActiveMQDestination) message.getJMSDestination (); if (queues.getPhysicalName (). EqualsIgnoreCase ("ActiveMQ.DLQ")) {System.out.println ("listening queue:" + queues.getPhysicalName () + "consumed messages:") If (message instanceof TextMessage) {TextMessage tm = (TextMessage) message; try {System.out.println ("from get textMessage:\ t" + tm.getText ()) } catch (JMSException e) {/ / TODO Auto-generated catch block e.printStackTrace ();}}
If (message instanceof MapMessage) {MapMessage mm = (MapMessage) message; try {System.out.println ("from get MapMessage:\ t" + mm.getString ("msgId"));} catch (JMSException e) {/ / TODO Auto-generated catch block e.printStackTrace () } / / if it is an Object message if (message instanceof ObjectMessage) {ObjectMessage om = (ObjectMessage) message; System.out.println ("from get ObjectMessage:\ t");}} catch (JMSException e) {e.printStackTrace () }}}
Do you still need to activate consumers to use monitoring?
You don't have to start the consumer, you need to start the producer.
Message listener MessageListener
1.MessageListener2.SessionAwareMessageListenerreSessionAwareMessageListener is provided for us by Spring, it is not a standard JMS MessageListener. 3.MessageListenerAdapter class implements MessageListener interface and SessionAwareMessageListener interface. Its main function is to type the received message, and then give it to an ordinary Java class for processing in the form of reflection. Another major function is that it can send return messages automatically. ActiveMQ queue message backlog problem
1. When the queue is unmonitored for a long time, the queue is automatically deleted. In the official list of features provided by ActiveMQ, there is such a function: Delete Inactive Destination. It can delete "Destination with no outstanding messages and no consumers". I think we have too many business queues and have not been calculated, but at least more than 50 are unnecessary, and those that are not commonly used can be started and stopped manually.
Reference materials for this article
ActiveMQ queue message backlog problem how does https://blog.51cto.com/winters1224/2049432 monitor dead-letter queues? How to consume messages in https://www.cnblogs.com/zhoading/p/12009116.htmlactivemq https://q.cnblogs.com/q/90513/ recommended blog posts https://blog.csdn.net/vop444/article/details/85222353 Thank you for reading. The above is the content of "how to listen in ActiveMq Dead letter queue". After the study of this article, I believe you have a deeper understanding of how to monitor in ActiveMq Dead letter queue. The specific use situation still needs to be verified by practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.