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: FlowControl + Heartbeats for Push Consumers #692
Conversation
nats.go
Outdated
select { | ||
case sub.mch <- m: | ||
case jsi.fch <- m: |
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 order to support ChanSubscribe, SyncSubscribe and Async Subscribers, a goroutine that expects signals via a channel is started to process the status messages outside of the message delivery.
11407b9
to
7843601
Compare
js.go
Outdated
} else if hasFC || hasHeartbeats { | ||
// Start goroutine to handle flow control messages for a push consumer. | ||
sub.jsi.fch = make(chan *Msg, 64) | ||
go sub.processControlFlow() |
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.
Why do we need this?
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.
I moved the control messages handling to be done before delivering the message at processMsg
and added an extra goroutine that would be handling the flow control messages from a subscription instead: https://github.com/nats-io/nats.go/pull/692/files#diff-1d2fb9af677137c0182213770500dd5625a51ba7286301cb11d0197b21e0f948R2533
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.
Anyway to avoid having another Go routine?
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.
I removed the goroutine and now responding a flow control message happens as soon as we receive the message, we have to do the processing of control messages there to be able to support ChanSubscribe:
821f170
to
3b348f7
Compare
Signed-off-by: Waldemar Quevedo <wally@synadia.com>
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
This adds the following options to push based consumers:
When they are enabled, the client will automatically handle/skip the control messages sent by the server. In case of push based consumers with Heartbeats, an asynchronous typed error will be dispatched so that the subscription could deleted and restarted from the given sequence:
Signed-off-by: Waldemar Quevedo wally@synadia.com