溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

activemq死信隊列怎么配置

發(fā)布時間:2021-12-30 09:41:21 來源:億速云 閱讀:271 作者:iii 欄目:大數(shù)據(jù)

本篇內(nèi)容介紹了“activemq死信隊列怎么配置”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!

監(jiān)聽新思路

1.不必去破壞生產(chǎn)者消費(fèi)者的關(guān)系,去創(chuàng)建死信隊列的對應(yīng)消費(fèi)者,如果不同隊列去創(chuàng)建對應(yīng)的死信隊列監(jiān)聽,沒什么意義,復(fù)用剛開始的思路進(jìn)行更改。mq配置更改指定監(jiān)聽死信隊列,死信隊列的名稱是可以配置指定的

@Bean    public ActiveMQConnectionFactory connectionFactory() throws JMSException {        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerurl);        factory.setTrustAllPackages(true);//信任所有包下的序列化對象,解決無法發(fā)送對象消息        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;    }

新建監(jiān)聽類

/** * @author zhaokkstart * @create 2020-09-11 11:18 */public class QueueListener implements MessageListener {    @Override    public void onMessage(Message message) {        System.out.println("****消費(fèi)者的消息:"+message);    }}

看下能從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;}

還是對象里的那點東西,到有個新思路

  commandId = 5,    responseRequired = true,    messageId = ID: kk - 59648 - 1599635155556 - 1: 239: 1: 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}

不必去指定type維護(hù)隊列的信息關(guān)系,獲取

destination = queue: //add_xxxxxx,

即獲取originalDestination屬性,判斷此消息的入隊隊列是哪個,然后獲取該隊列的消費(fèi)者入隊消息進(jìn)行轉(zhuǎn)換

這個方法是肯定能監(jiān)聽到死信隊列的,親測有效。

activemq死信隊列怎么配置

activemq死信隊列怎么配置

(1) 死信隊列的配置(一般采用默認(rèn))

1. sharedDeadLetterStrategy

不管是queue還是topic,失敗的消息都放到這個隊列中。下面修改activemq.xml的配置,可以達(dá)到修改隊列的名字。

activemq死信隊列怎么配置

 

2. individualDeadLetterStrategy

可以為queue和topic單獨(dú)指定兩個死信隊列。還可以為某個話題,單獨(dú)指定一個死信隊列。

activemq死信隊列怎么配置

activemq死信隊列怎么配置

activemq死信隊列怎么配置

“activemq死信隊列怎么配置”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注億速云網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI