In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the knowledge of "how to configure the activemq Dead letter queue". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
New ideas for monitoring
1. There is no need to destroy the relationship between producers and consumers, to create the corresponding consumers of the dead letter queue, if different queues to create the corresponding dead letter queue monitoring, it is meaningless, reuse the initial ideas to change. Mq configuration changes specify to listen on the dead letter queue, and the name of the dead letter queue can be configured and specified.
@ Bean public ActiveMQConnectionFactory connectionFactory () throws JMSException {ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory (brokerurl); factory.setTrustAllPackages (true); / / Trust serialized objects under all packages to solve the problem that cannot send object messages javax.jms.Connection connection = factory.createConnection (); connection.start (); Session session = connection.createSession (false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue ("ActiveMQ.DLQ") MessageConsumer messageConsumer = session.createConsumer (queue); messageConsumer.setMessageListener (new QueueListener ()); factory.setUserName (userName); factory.setPassword (password); return factory;}
Create a new listening class
/ * @ author zhaokkstart * @ create 2020-09-11 11:18 * / public class QueueListener implements MessageListener {@ Override public void onMessage (Message message) {System.out.println ("consumer message:" + message);}}
See what you can get from message.
Public interface Message {
Static final int DEFAULT_DELIVERY_MODE = DeliveryMode.PERSISTENT
Static final int DEFAULT_PRIORITY = 4
Static final long DEFAULT_TIME_TO_LIVE = 0
String getJMSMessageID () throws JMSException
Void setJMSMessageID (String id) throws JMSException
Long getJMSTimestamp () throws JMSException
Void setJMSTimestamp (long timestamp) throws JMSException
Byte [] getJMSCorrelationIDAsBytes () throws JMSException
Void setJMSCorrelationIDAsBytes (byte [] correlationID) throws JMSException
Void setJMSCorrelationID (String correlationID) throws JMSException
String getJMSCorrelationID () throws JMSException
Destination getJMSReplyTo () throws JMSException
Void setJMSReplyTo (Destination replyTo) throws JMSException
Destination getJMSDestination () throws JMSException
Void setJMSDestination (Destination destination) throws JMSException
Int getJMSDeliveryMode () throws JMSException
Void setJMSDeliveryMode (int deliveryMode) throws JMSException
Boolean getJMSRedelivered () throws JMSException
Void setJMSRedelivered (boolean redelivered) throws JMSException
String getJMSType () throws JMSException
Void setJMSType (String type) throws JMSException
Long getJMSExpiration () throws JMSException
Void setJMSExpiration (long expiration) throws JMSException
Int getJMSPriority () throws JMSException
Void setJMSPriority (int priority) throws JMSException
Void clearProperties () throws JMSException
Boolean propertyExists (String name) throws JMSException
Boolean getBooleanProperty (String name) throws JMSException
Byte getByteProperty (String name) throws JMSException
Short getShortProperty (String name) throws JMSException
Int getIntProperty (String name) throws JMSException
Long getLongProperty (String name) throws JMSException
Float getFloatProperty (String name) throws JMSException
Double getDoubleProperty (String name) throws JMSException
String getStringProperty (String name) throws JMSException
Object getObjectProperty (String name) throws JMSException
Enumeration getPropertyNames () throws JMSException
Void setBooleanProperty (String name, boolean value) throws JMSException
Void setByteProperty (String name, byte value) throws JMSException
Void setShortProperty (String name, short value) throws JMSException
Void setIntProperty (String name, int value) throws JMSException
Void setLongProperty (String name, long value) throws JMSException
Void setFloatProperty (String name, float value) throws JMSException
Void setDoubleProperty (String name, double value) throws JMSException
Void setStringProperty (String name, String value) throws JMSException
Void setObjectProperty (String name, Object value) throws JMSException
Void acknowledge () throws JMSException
Void clearBody () throws JMSException;}
It's still something in the object, so there's a new idea.
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_xxxxxx, 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}
You don't have to specify type to maintain the information relationship of the queue, and get the
Destination = queue: / / add_xxxxxx
That is, get the originalDestination attribute, determine which queue this message is queued, and then get the consumer queuing message of the queue for conversion
This method is sure to monitor the dead letter queue, and the personal test is effective.
(1) Dead letter queue configuration (default is generally used)
1. SharedDeadLetterStrategy
Whether it is queue or topic, failed messages are placed in this queue. Let's modify the configuration of activemq.xml to change the name of the queue.
2. IndividualDeadLetterStrategy
Two dead letter queues can be specified separately for queue and topic. You can also specify a separate dead letter queue for a topic.
This is the end of the content of "how to configure the activemq Dead letter queue". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.