扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
本篇内容介绍了“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死信队列怎么配置”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注创新互联网站,小编将为大家输出更多高质量的实用文章!
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
Copyright © 2002-2023 www.kswjz.com 快上网建站品牌 QQ:244261566 版权所有 备案号:蜀ICP备19037934号
微信二维码
移动版官网