您好,登錄后才能下訂單哦!
本篇內容介紹了“activemq死信隊列怎么配置”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!
監聽新思路
1.不必去破壞生產者消費者的關系,去創建死信隊列的對應消費者,如果不同隊列去創建對應的死信隊列監聽,沒什么意義,復用剛開始的思路進行更改。mq配置更改指定監聽死信隊列,死信隊列的名稱是可以配置指定的
@Bean public ActiveMQConnectionFactory connectionFactory() throws JMSException { ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(brokerurl); factory.setTrustAllPackages(true);//信任所有包下的序列化對象,解決無法發送對象消息 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; }
新建監聽類
/** * @author zhaokkstart * @create 2020-09-11 11:18 */public class QueueListener implements MessageListener { @Override public void onMessage(Message message) { System.out.println("****消費者的消息:"+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維護隊列的信息關系,獲取
destination = queue: //add_xxxxxx,
即獲取originalDestination屬性,判斷此消息的入隊隊列是哪個,然后獲取該隊列的消費者入隊消息進行轉換
這個方法是肯定能監聽到死信隊列的,親測有效。
(1) 死信隊列的配置(一般采用默認)
1. sharedDeadLetterStrategy
不管是queue還是topic,失敗的消息都放到這個隊列中。下面修改activemq.xml的配置,可以達到修改隊列的名字。
2. individualDeadLetterStrategy
可以為queue和topic單獨指定兩個死信隊列。還可以為某個話題,單獨指定一個死信隊列。
“activemq死信隊列怎么配置”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。