Queue Subscriptions

Queue subscriptions are created like other subscriptions with the addition of a queue name.

  1. qsub1, _ := sc.QueueSubscribe(channelName,
  2. queueName, func(m *stan.Msg) {...})
  3. qsub2, _ := sc.QueueSubscribe(channelName,
  4. queueName, func(m *stan.Msg) {...})

Multiple subscriptions using the same channel and queue name are members of the same queue group. That means that if a message is published on that channel, only one member of the group receives the message. Other subscriptions receive messages independently of the queue groups, that is, a message is delivered to all subscriptions and one member of each queue group.

To create a durable queue subscription, simply add a durable name:

  1. qsub, err := sc.QueueSubscribe(channelName,
  2. queueName, func(m *stan.Msg) {...},
  3. stan.DurableName("durable-name"))

Subscriptions options apply to each member independently, notably, the AckWait and MaxInflight. Those two members of the same queue group use different options for redelivery and max inflight.

  1. qsub1, _ := sc.QueueSubscribe(channelName,
  2. queueName, func(m *stan.Msg) {...},
  3. stan.AckWait(5*time.Second),
  4. stan.MaxInflight(5))
  5. qsub2, _ := sc.QueueSubscribe(channelName,
  6. queueName, func(m *stan.Msg) {...},
  7. stan.AckWait(20*time.Second),
  8. stan.MaxInflight(10))

If the queue subscription is durable, only the last member calling Unsubscribe() will cause the durable queue group to be removed from the server.

Check the concepts section for more information.