ai didi

java - Spring jms 分隔符由 messageId

转载 作者:行者123 更新时间:2023-11-30 10:19:53 24 4
gpt4 key购买 nike

我正在使用 @JmsListener从队列接收所有消息的注释

@JmsListener(destination = MyQueue, selector = "MAINST = '" + instanceName + "'")
public void receivMsg(Message message) {

但是另一个系统不能处理消息属性。它以关联 ID 响应。当 LinkedList<String> 中存在时,如何按 correlationID 过滤消息

最佳答案

instanceName 使用属性占位符。这是一个在同一队列中有两个监听器的示例...

@SpringBootApplication
public class So48377178Application {

public static void main(String[] args) {
SpringApplication.run(So48377178Application.class, args);
}

@Bean
public ApplicationRunner runner(JmsTemplate template) {
return args -> {
template.convertAndSend("foo", "This one's for A", m -> {
m.setJMSCorrelationID("A");
return m;
});
template.convertAndSend("foo", "This one's for B", m -> {
m.setJMSCorrelationID("B");
return m;
});
};
}

@JmsListener(destination = "foo", selector = "JMSCorrelationID='${a.instance}'")
public void listenA(Message message) {
System.out.println("A: " + message);
}

@JmsListener(destination = "foo", selector = "JMSCorrelationID='${b.instance}'")
public void listenB(Message message) {
System.out.println("B: " + message);
}

}

a.instance=A
b.instance=B

B: ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:gollum.local-56240-1516631774140-4:4:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:gollum.local-56240-1516631774140-4:4:1:1, destination = queue://foo, transactionId = null, expiration = 0, timestamp = 1516631774348, arrival = 0, brokerInTime = 1516631774348, brokerOutTime = 1516631774349, correlationId = B, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 1056, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = This one's for B}
A: ActiveMQTextMessage {commandId = 5, responseRequired = true, messageId = ID:gollum.local-56240-1516631774140-4:3:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:gollum.local-56240-1516631774140-4:3:1:1, destination = queue://foo, transactionId = null, expiration = 0, timestamp = 1516631774341, arrival = 0, brokerInTime = 1516631774341, brokerOutTime = 1516631774345, correlationId = A, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = null, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 1056, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false, text = This one's for A}

关于java - Spring jms 分隔符由 messageId,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48377178/

24 4 0
文章推荐: xcode - NSTable insertRowsAtIndexes 动画
文章推荐: javascript - 为什么 "draw"在我的石头剪刀布蜥蜴史波克中不增加+1?
文章推荐: objective-c - 如何将 Objective-C 文件添加/导入到 Swift 应用程序
文章推荐: javascript - 用于 backbone.js 验证的自定义验证器
行者123
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com