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 6 deletions
Showing only changes of commit 52d1c4839f - Show all commits

View File

@ -35,19 +35,19 @@ func (js JetStream) Subscribe(stream, subject string, cb nats.MsgHandler) (*nats
// //
// Example: // Example:
// //
// sub, err := natsio.PullSubscribe("A_STREAM", "A_OBJECT") // js := natsio.GetJetStream()
//
// sub, err := js.PullSubscribe("A_SUBJECT", "A_DURABLE")
// //
// for { // for {
// messages, err := sub.Fetch(10) // messages, err := sub.Fetch(10)
// // process each messages // // process each messages
// } // }
// //
func (js JetStream) PullSubscribe(stream, subject string) (*nats.Subscription, error) { func (js JetStream) PullSubscribe(subject, durable string) (*nats.Subscription, error) {
channel := combineStreamAndSubjectName(stream, subject) sub, err := js.instance.PullSubscribe(subject, durable)
sub, err := js.instance.PullSubscribe(stream, subject)
if err != nil { if err != nil {
msg := fmt.Sprintf("[NATS JETSTREAM] - pull subscribe subject #%s error: %s", channel, err.Error()) msg := fmt.Sprintf("[NATS JETSTREAM] - pull subscribe subject #%s - durable #%s error: %s", subject, durable, err.Error())
return nil, errors.New(msg) return nil, errors.New(msg)
} }