英文:
Nats cannot create a queue subscription for a consumer without a deliver group
问题
我正在尝试在一个队列中创建多个订阅者,以便每个消息只被其中一个订阅者读取。当我尝试第二次调用QueueSubscribe
时,我会收到一个错误:cannot create a queue subscription for a consumer without a deliver group
。
我尝试在一个应用程序中创建两个订阅者,并尝试运行两个实例,但是出现了相同的错误。
以下是订阅者的代码:
s1, err = js.QueueSubscribe(
"KEYS.group",
"queue",
func(m *nats.Msg) {
fmt.Printf("1: %s\n", m.Data)
},
)
s2, err = js.QueueSubscribe(
"KEYS.group",
"queue",
func(m *nats.Msg) {
fmt.Printf("2: %s\n", m.Data)
},
)
以及发布者的代码:
_, err := js.AddStream(&nats.StreamConfig{
Name: "KEYS",
Subjects: []string{"KEYS.group"},
Retention: nats.WorkQueuePolicy, // 如果可能的话,尝试使用默认策略
})
for i := 0; i < 20; i++ {
msg := fmt.Sprintf(`{"key": "%d"}`, i)
if _, err := js.Publish("KEYS.group", []byte(msg)); err != nil {
print(err)
}
}
我还尝试添加了Durable
属性,但没有帮助。
英文:
I'm trying to create several subscribers in one queue so each message is read only by one of them. When I try to QueueSubscribe
second time I get an error: cannot create a queue subscription for a consumer without a deliver group
.
I've tried creating two subscribers in one app and tried running two instances as well, it's the same error.
Here're subscribers:
s1, err = js.QueueSubscribe(
"KEYS.group",
"queue",
func(m *nats.Msg) {
fmt.Printf("1: %s\n", m.Data)
},
)
s2, err = js.QueueSubscribe(
"KEYS.group",
"queue",
func(m *nats.Msg) {
fmt.Printf("2: %s\n", m.Data)
},
)
And publisher:
_, err := js.AddStream(&nats.StreamConfig{
Name: "KEYS",
Subjects: []string{"KEYS.group"},
Retention: nats.WorkQueuePolicy, // tried with default policy if it may be relevant
})
for i := 0; i < 20; i++ {
msg := fmt.Sprintf(`{"key": "%d"}`, i)
if _, err := js.Publish("KEYS.group", []byte(msg)); err != nil {
print(err)
}
}
I've tried to add Durable
attribute as well and it didn't help.
答案1
得分: 2
问题是由于nats服务器的版本问题(2.3.6)导致的,更新到2.7.2后一切正常。该库不兼容旧版本。
英文:
The problem occured because of the version of nats server (2.3.6), after update to 2.7.2 everything works fine. Library is not compatible with old versions.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论