Nats cannot create a queue subscription for a consumer without a deliver group

Issue

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.

Solution

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.

Answered By – mishkamashka

Answer Checked By – Terry (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.