From 941e4c5ca3098f857b5ec9d3f7b2bbbf1ba4b08c Mon Sep 17 00:00:00 2001 From: Nam Huynh Date: Fri, 18 Mar 2022 10:55:13 +0700 Subject: [PATCH] add check consumer --- jetstream_pubsub.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/jetstream_pubsub.go b/jetstream_pubsub.go index 066db87..c4c1aaa 100644 --- a/jetstream_pubsub.go +++ b/jetstream_pubsub.go @@ -49,6 +49,16 @@ func (js JetStream) PullSubscribe(stream, subject, durable, consumer string) (*n con, err := js.instance.ConsumerInfo(stream, consumer) fmt.Println("con", con) fmt.Println("err", err) + if con == nil { + info, err := js.instance.AddConsumer(stream, &nats.ConsumerConfig{ + Durable: durable, + }) + if err != nil { + fmt.Println("CONSUMER INFO", info) + } else { + fmt.Println("ADD CONSUMER ERROR", err) + } + } sub, err := js.instance.PullSubscribe(subject, durable) if err != nil {