New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
js: Add js.PullSubscribe and sub.Fetch APIs for pull consumers #670
Conversation
b6f62ba
to
5c7e641
Compare
b782f72
to
3879124
Compare
Let's squash down for review. |
c4d3b43
to
6493d5d
Compare
Squashed and updated server version in go.mod |
What is this? // Deletes durable consumer on unsubscribe
defer sub.Unsubscribe() |
@scottf that means that when Unsubscribe() is called then also makes the consumer go away: https://github.com/nats-io/nats.go/blob/master/js.go#L427-L440 Note: This comment is stale as the original example has changed. |
2387a12
to
df21c14
Compare
Rebased and updated to test against latest version of the server. |
js.go
Outdated
// this limit can be modified by using PullMaxWaiting when creating the consumer. | ||
// | ||
nr := &nextRequest{Batch: batch, NoWait: o.noWait, Expires: o.expires} | ||
req, _ := json.Marshal(nr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case only Batch is set, could take advantage of the fast path and just the number as bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also results in a lighter protocol.
df21c14
to
c8446bc
Compare
js.go
Outdated
if len(msg.Data) == 0 { | ||
switch msg.Header.Get(statusHdr) { | ||
case noResponders: | ||
return ErrNoResponders |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be another error type surfaced that might be more meaningful?
nats.go
Outdated
switch msg.Header.Get(statusHdr) { | ||
case noResponders: | ||
return ErrNoResponders | ||
case "400", "404", "408", "409": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convert this case for > 400 to future proof this? (either convert to int or test the first char to '4' or '5')... Alternatively, could add a default that results in an error. wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM; the suggested changes aren't critical to this PR.
aa625d9
to
552d360
Compare
52815ba
to
99d20d3
Compare
This is rebased and updated against latest version of the server. The logic is now smarter using NoWait to be signaled in case there are no messages and fallback to a longer pull batch request in case there aren't any at the moment and wait for the delivery. In case of batches of 1, also the way pull works was simplified to be a mix of new style request plus an old style request for the second one in case the initial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general LGTM
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
99d20d3
to
ac8b51a
Compare
This changes the way how Pull consumers work by adding the two following APIs:
PullSubscribe
replaces usingSubscribeSync
orQueueSubscribeSync
along withnats.Pull
option to create pull based consumers. When a subscription is called withPullSubscribe
, it can usesub.Fetch()
to get a synchronous response of a collection of messages.Example usage
Signed-off-by: Waldemar Quevedo wally@synadia.com