gpt4 book ai didi

node.js - 无法在 ActiveMQ 中使用 STOMP 选择器过滤消息

转载 作者:太空宇宙 更新时间:2023-11-04 00:00:09 25 4
gpt4 key购买 nike

我正在使用ActiveMQ 5.15.8。我使用 node.js 中的 STOMP 协议(protocol)和库 stompit 连接到它。

生产者代码片段:

var headers = {
'destination':'/topic/xyz',
'persistent':'true',
'content-type':'binary/octet-stream',
'content-length':9999,
'selector': "key = 'A'"
}
var frame = client.send(headers)

消费者代码订阅片段:

client.subscribe({'ack':'client-individual',
'activemq.retroactive':'true',
'activemq.subscriptionName':'name',
'destination':'/topic/xyz',
'selector':"key = 'A'"},(err,msg)=>{})

问题是我无法获得正确的选择器。我无法使用上述代码接收任何消息。我也尝试过使用:

'selector':'key=A'

这样我就可以收到所有消息,但不会根据 key 进行过滤。

有人可以帮我正确选择这个选择器吗?我再次使用 Node.js 库 stompit。

谢谢

最佳答案

当您发送消息时,您不会应用选择器 header 。您只需应用一个键/值,例如:

var headers = {
'destination':'/topic/xyz',
'persistent':'true',
'content-type':'binary/octet-stream',
'content-length':9999,
'key': "A"
}
var frame = client.send(headers)

然后您的消费者的选择器将对该 header 进行操作。保持消费者的选择器定义相同。一旦您更新了生产者,它就应该可以工作。

就其值(value)而言,选择器使用 here 中描述的 SQL92 条件表达式语法的子集。 (向下滚动到“消息选择器”部分)。为此引用 JMS 文档似乎很奇怪,但 STOMP 规范没有定义与选择器相关的任何内容。但是,为了方便起见,已经为其 JMS 客户端(如 ActiveMQ)实现它的代理将其公开给 STOMP 客户端。

关于node.js - 无法在 ActiveMQ 中使用 STOMP 选择器过滤消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55153662/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com