Skip to content
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

Add MaxWait on jetstreamcontext.Subscribe(and similar) #699

Open
tpihl opened this issue Apr 1, 2021 · 7 comments
Open

Add MaxWait on jetstreamcontext.Subscribe(and similar) #699

tpihl opened this issue Apr 1, 2021 · 7 comments
Assignees
Labels
feature New feature request

Comments

@tpihl
Copy link

tpihl commented Apr 1, 2021

Feature Request

Creating an ephemeral or durable push subscriber using jetstreamcontext allow you to set almost all consumer parameters, but i cannot find MaxWait(dur).

@tpihl tpihl added the feature New feature request label Apr 1, 2021
@wallyqs
Copy link
Member

wallyqs commented Apr 1, 2021

@tpihl Right now there is no nats.MaxWait(time.Duration) for Subscribe which we should add, though just to be clear you can set js.SubscribeSync("foo", nats.AckWait(1o*time.Duration)) to set how long to wait before the redelivery of a message:
https://github.com/nats-io/nats.go/blob/master/js.go#L771

nats.MaxWait() on the other hand would be how long to wait before the js.SubscribeSync("foo") subscription creation is done, which is by default 5*time.Second.

@tpihl
Copy link
Author

tpihl commented Apr 1, 2021

Thats not really what i meant.

The MaxWait i am looking for is the push-consumers timeout before it will send an un-acked message. Defaults to 30 seconds, visible when you do a nats consumer info as Ack Wait (under Ack Policy). How do i change that when i create a push consumer subscription as above?

@wallyqs
Copy link
Member

wallyqs commented Apr 1, 2021

If you call this:

js.SubscribeSync("foo", nats.AckWait(10*time.Duration))

Then the push consumer would redeliver messages after they have not been acked after 10 seconds.

@tpihl
Copy link
Author

tpihl commented Apr 1, 2021

So MaxWait consumer require a SubscribeSync with my own msg-loop? Isnt that a pull-consumer?

@wallyqs
Copy link
Member

wallyqs commented Apr 1, 2021

SubscribeSync can be used to process synchronously although it is a push based consumer so the messages will all be delivered and be ready in the buffer from the client as they are delivered (max 8192 msgs buffered by default / 65536 for async subscribers). With PullSubscriber, the messages are only delivered when sub.Fetch(int) is called.

@tpihl
Copy link
Author

tpihl commented Apr 1, 2021

So what is the difference except max messages in buffer. My MsgHandler is only invoked one message at the time,isn't it? Even with MaxAckPending higher

@wallyqs
Copy link
Member

wallyqs commented Apr 1, 2021

Yes the MsgHandler is only invoked once per message delivered and it is called sequentially as the messages get delivered to the client, the main difference with PullSubscribers is that you control when to be delivered the messages whereas with Push conssumer, SubscribeSync or Subscribe it is expected that a client is always able to receive messages at a good pace without becoming a slow consumer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature request
Projects
None yet
Development

No branches or pull requests

2 participants