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

How to deal with mq after listening in dead letter queue

2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Today, I would like to talk to you about how to deal with mq monitoring the dead letter queue, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.

Yesterday I tried for a long time why I could not listen to the message of the dead letter queue, because it was opened in the wrong way, and there was only one message in the dead letter queue, which was boring.

What kind of business? I didn't even activate the transaction, why did he go in there?

Don't you say that retry is the default of 6 times? I didn't even change the configuration, how did I get in?

1. How do I get a message into a dead letter queue?

1. Equip ActiveMQConnectionFactory with retransmission mechanism; 2. Configure transactions for DefaultMessageListenerContainer

Or set the expiration time for the message, and enter the dead letter queue after expiration.

I didn't even enable the transaction, saying that it was all bullshit. I killed a business consumer, and then turned that consumer into listening on a dead letter queue consumer, and jmeter opened a 10000 thread loop to adjust it.

Consumers do not consume, and then each message is dequeued + 1, and then the dead letter queue + 1

About the retry mechanism RedeliveryPolicy

RedeliveryPolicy can be set in ActiveMQConnectionFactory. If not, it will be the default.

/ * Sets the global default redelivery policy to be used when a message is delivered * but the session is rolled back session will be rolled back * / public void setRedeliveryPolicy (RedeliveryPolicy redeliveryPolicy) {this.redeliveryPolicyMap.setDefaultEntry (redeliveryPolicy);}

Activemq official website API

Http://activemq.apache.org/maven/apidocs/org/apache/activemq/RedeliveryPolicy.html

If customized

RedeliveryPolicy redeliveryPolicy= new RedeliveryPolicy (); / / whether to increase the waiting time redeliveryPolicy.setUseExponentialBackOff (true) after each failed retransmission attempt; / / the default number of retransmissions is 6. Here it is set to 10 redeliveryPolicy.setMaximumRedeliveries (10); / / the retransmission interval is 1 second redeliveryPolicy.setInitialRedeliveryDelay (1). / / wait 500 milliseconds before retransmission after the first failure, and wait 500 * 2 milliseconds for the second failure, where 2 is value redeliveryPolicy.setBackOffMultiplier (2); / / whether to avoid message collision redeliveryPolicy.setUseCollisionAvoidance (false) / / set the maximum delay time for retransmission-1 means there is no delay. Only when UseExponentialBackOff (true) is true, redeliveryPolicy.setMaximumRedeliveryDelay (- 1) takes effect.

Other methods can take a look at the source code.

Isn't it six times to retry?

Public class RedeliveryPolicy extends DestinationMapEntry implements Cloneable, Serializable {

Public static final int NO_MAXIMUM_REDELIVERIES =-1; public static final int DEFAULT_MAXIMUM_REDELIVERIES = 6; default is indeed 6 times

Private static Random randomNumberGenerator

/ / + /-15% for a 30% spread-cgs protected double collisionAvoidanceFactor = 0.15d; protected int maximumRedeliveries = DEFAULT_MAXIMUM_REDELIVERIES; protected long maximumRedeliveryDelay =-1; protected long initialRedeliveryDelay = 1000L; protected boolean useCollisionAvoidance; protected boolean useExponentialBackOff; protected double backOffMultiplier = 5.0; protected long redeliveryDelay = initialRedeliveryDelay

There's a load factor like Hashmap, which has a fluctuation range, but the local one is four times.

Protected double collisionAvoidanceFactor = 0.15d

two。 What are the items stored in the dead letter queue?

Nah, this is the thing I saved.

Object is what we want.

Consumption content ActiveMQObjectMessage {commandId = 5, responseRequired = true, messageId = ID: KK-59648-1599635155556-1: 239: 1: 1, originalDestination = null, originalTransactionId = null, producerId = ID: KK-59648-1599635155556-1: 239: 1: 1, destination = queue: / / add, transactionId = null, expiration = 0, timestamp = 1599636301936, arrival = 0, brokerInTime = 1599636301937, brokerOutTime = 1599636302110, correlationId = null, replyTo = null, persistent = true, type = null Priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@54eae153, marshalledProperties = org.apache.activemq.util.ByteSequence@1318dd4d, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {timestamp=1599636300958}, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false}

3. New question: how to deal with the dynamic objects or messages stored in the dead letter queue?

1. Assign a dead-letter queue name to the service and consume the dead-letter queue one-on-one, so that you know the contents of joining and leaving the queue.

two。 Add an attribute value of type to the queue before joining the queue, use enumerations to determine what type to switch to, either directly instance of, or use prefixes or prefixes to transfer.

Then it is good to deal with the business logic when consuming. If the object is transferred successfully, check the library.

If the data is found, it is determined that the last operation time will be executed if it is after the time in the library, and if the message in the queue is deleted or not processed before the time in the library.

If the data cannot be found, the data in this article will be executed directly.

If you don't say much, come to him 100000 times first

In addition, did you encounter the problem of dead letter queue in the business?

No, I just took one more look at it in the queue and found that the dead letter queue appeared in front of me, which caused so many problems.

After reading the above, do you have any further understanding of how mq monitors the dead letter queue? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

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