Add pull subscribe #1

Merged
namhq1989 merged 12 commits from add-pull-subscribe into master 2022-03-18 04:28:50 +00:00
1 changed files with 6 additions and 3 deletions
Showing only changes of commit cfbda097a0 - Show all commits

View File

@ -45,6 +45,8 @@ func (js JetStream) Subscribe(stream, subject string, cb nats.MsgHandler) (*nats
// }
//
func (js JetStream) PullSubscribe(stream, subject, durable, consumer string) (*nats.Subscription, error) {
channel := combineStreamAndSubjectName(stream, subject)
// Check if consumer existed
con, err := js.instance.ConsumerInfo(stream, consumer)
fmt.Println("con", con)
@ -53,6 +55,7 @@ func (js JetStream) PullSubscribe(stream, subject, durable, consumer string) (*n
info, err := js.instance.AddConsumer(stream, &nats.ConsumerConfig{
Durable: durable,
AckPolicy: nats.AckExplicitPolicy,
FilterSubject: channel,
})
if err == nil {
fmt.Println("CONSUMER INFO", info)
@ -63,7 +66,7 @@ func (js JetStream) PullSubscribe(stream, subject, durable, consumer string) (*n
sub, err := js.instance.PullSubscribe(subject, durable)
if err != nil {
msg := fmt.Sprintf("[NATS JETSTREAM] - pull subscribe subject #%s - durable #%s error: %s", subject, durable, err.Error())
msg := fmt.Sprintf("[NATS JETSTREAM] - pull subscribe subject #%s - durable #%s error: %s", channel, durable, err.Error())
return nil, errors.New(msg)
}