'Nats cannot create a queue subscription for a consumer without a deliver group
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
