我正在尝试使用 go-stom/stomp 连接到由 Network rail 托管的 darwin pushport 服务
I am trying to connect to the darwin pushport service hosted by network rail using go-stom/stomp
我正在尝试连接到位于 here. When I try to connect following the instructions from wiki 的 Darwin Push 端口提要,我收到 2 个错误中的 1 个。
如果我遗漏了订阅选项,我会收到身份验证错误消息,
如果我包含它们,它会说我无法创建对 queue.
的持久订阅
如果有人能告诉我哪个错误更接近连接,那将是一个很大的帮助。
package main
import (
"fmt"
"github.com/Showmax/go-fqdn"
"github.com/go-stomp/stomp"
"github.com/go-stomp/stomp/frame"
)
var serverAddr = "darwin-dist-44ae45.nationalrail.co.uk:61613"
var messageCount = 10
var topic = "topic/darwin.pushport-v16"
var username = "####"
var password = "###"
var stop = make(chan bool)
fqdn, err := fqdn.FqdnHostname()
if err != nil {
panic(err)
}
var connOptions []func(*stomp.Conn) error = []func(*stomp.Conn) error{
stomp.ConnOpt.Login(username, password),
stomp.ConnOpt.Host(serverAddr),
stomp.ConnOpt.Header("client-id", fmt.Sprintf("%v-%v", username, fqdn)),
}
conn, err := stomp.Dial("tcp", serverAddr, connOptions...)
if err != nil {
println("cannot connect to server", err.Error())
return
}
subOptions := []func(*frame.Frame) error{
stomp.SubscribeOpt.Header("activemq.subscriptionName", fqdn),
stomp.SubscribeOpt.Header("durable-subscription-name", fqdn),
}
sub, err := conn.Subscribe(topic, stomp.AckClient, subOptions...)
if err != nil {
println("cannot subscribe to", topic, err.Error())
return
}
for i := 1; i <= messageCount; i++ {
msg := <-sub.C
fmt.PrintLn(msg)
}
}
println("receiver finished")
}
我得到的是:
2020/09/04 16:55:35 received ERROR; Closing underlying connection
2020/09/04 16:55:35 Subscription 1: topic/darwin.pushport-v16: ERROR message:Invalid Subscription: cannot durably subscribe to a Queue destination!
Expected: Message #1
Actual: org.apache.activemq.transport.stomp.ProtocolException: Invalid Subscription: cannot durably subscribe to a Queue destination!
at org.apache.activemq.transport.stomp.ProtocolConverter.onStompSubscribe(ProtocolConverter.java:581)
at ...
如果我删除订阅 headers:
subOptions := []func(*frame.Frame) error{
// stomp.SubscribeOpt.Header("activemq.subscriptionName", fqdn),
// stomp.SubscribeOpt.Header("durable-subscription-name", fqdn),
}
我明白了:
2020/09/04 17:00:13 received ERROR; Closing underlying connection
2020/09/04 17:00:13 Subscription 1: topic/darwin.pushport-v16: ERROR message:User REDACTED is not authorized to read from: queue://topic/darwin.pushport-v16
Expected: Message #1
Actual: java.lang.SecurityException: User REDACTED is not authorized to read from: queue://topic/darwin.pushport-v16
at org.apache.activemq.security.AuthorizationBroker.addConsumer(AuthorizationBroker.java:159)
at org.apache.activemq.broker.BrokerFilter.addConsumer(BrokerFilter.java:104)
at org.apache.activemq.broker.BrokerFilter.addConsumer(BrokerFilter.java:104)
at
我已经尝试了这两种方法,有和没有 topic/
继续这个话题。
如有任何帮助,我们将不胜感激。
队列和主题的 STOMP 客户端 ActiveMQ 中的目标前缀分别为 /queue/
或 /topic/
,没有前缀或在您的情况下无效的前缀是默认值使用队列。
要将 Tim Bish 的回答得出合乎逻辑的结论,您需要在主题描述中添加一个前导斜杠,以便它显示为 /topic/darwin.pushport-v16
而不仅仅是 topic/darwin.pushport-v16
。然后它将被正确识别为主题(而不是默认为队列)并且应该“正常工作”。
我正在尝试连接到位于 here. When I try to connect following the instructions from wiki 的 Darwin Push 端口提要,我收到 2 个错误中的 1 个。
如果我遗漏了订阅选项,我会收到身份验证错误消息, 如果我包含它们,它会说我无法创建对 queue.
的持久订阅如果有人能告诉我哪个错误更接近连接,那将是一个很大的帮助。
package main
import (
"fmt"
"github.com/Showmax/go-fqdn"
"github.com/go-stomp/stomp"
"github.com/go-stomp/stomp/frame"
)
var serverAddr = "darwin-dist-44ae45.nationalrail.co.uk:61613"
var messageCount = 10
var topic = "topic/darwin.pushport-v16"
var username = "####"
var password = "###"
var stop = make(chan bool)
fqdn, err := fqdn.FqdnHostname()
if err != nil {
panic(err)
}
var connOptions []func(*stomp.Conn) error = []func(*stomp.Conn) error{
stomp.ConnOpt.Login(username, password),
stomp.ConnOpt.Host(serverAddr),
stomp.ConnOpt.Header("client-id", fmt.Sprintf("%v-%v", username, fqdn)),
}
conn, err := stomp.Dial("tcp", serverAddr, connOptions...)
if err != nil {
println("cannot connect to server", err.Error())
return
}
subOptions := []func(*frame.Frame) error{
stomp.SubscribeOpt.Header("activemq.subscriptionName", fqdn),
stomp.SubscribeOpt.Header("durable-subscription-name", fqdn),
}
sub, err := conn.Subscribe(topic, stomp.AckClient, subOptions...)
if err != nil {
println("cannot subscribe to", topic, err.Error())
return
}
for i := 1; i <= messageCount; i++ {
msg := <-sub.C
fmt.PrintLn(msg)
}
}
println("receiver finished")
}
我得到的是:
2020/09/04 16:55:35 received ERROR; Closing underlying connection
2020/09/04 16:55:35 Subscription 1: topic/darwin.pushport-v16: ERROR message:Invalid Subscription: cannot durably subscribe to a Queue destination!
Expected: Message #1
Actual: org.apache.activemq.transport.stomp.ProtocolException: Invalid Subscription: cannot durably subscribe to a Queue destination!
at org.apache.activemq.transport.stomp.ProtocolConverter.onStompSubscribe(ProtocolConverter.java:581)
at ...
如果我删除订阅 headers:
subOptions := []func(*frame.Frame) error{
// stomp.SubscribeOpt.Header("activemq.subscriptionName", fqdn),
// stomp.SubscribeOpt.Header("durable-subscription-name", fqdn),
}
我明白了:
2020/09/04 17:00:13 received ERROR; Closing underlying connection
2020/09/04 17:00:13 Subscription 1: topic/darwin.pushport-v16: ERROR message:User REDACTED is not authorized to read from: queue://topic/darwin.pushport-v16
Expected: Message #1
Actual: java.lang.SecurityException: User REDACTED is not authorized to read from: queue://topic/darwin.pushport-v16
at org.apache.activemq.security.AuthorizationBroker.addConsumer(AuthorizationBroker.java:159)
at org.apache.activemq.broker.BrokerFilter.addConsumer(BrokerFilter.java:104)
at org.apache.activemq.broker.BrokerFilter.addConsumer(BrokerFilter.java:104)
at
我已经尝试了这两种方法,有和没有 topic/
继续这个话题。
如有任何帮助,我们将不胜感激。
队列和主题的 STOMP 客户端 ActiveMQ 中的目标前缀分别为 /queue/
或 /topic/
,没有前缀或在您的情况下无效的前缀是默认值使用队列。
要将 Tim Bish 的回答得出合乎逻辑的结论,您需要在主题描述中添加一个前导斜杠,以便它显示为 /topic/darwin.pushport-v16
而不仅仅是 topic/darwin.pushport-v16
。然后它将被正确识别为主题(而不是默认为队列)并且应该“正常工作”。