-
Notifications
You must be signed in to change notification settings - Fork 172
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 client.flush()
calls to example code in docs
#1263
Conversation
Thank you for your PR!
The reason why the messages can be lost on dropping the client/shutting is because there is no custom client drop logic that would clear our all buffers. We were discussing few times if we should do that, but as its similar to how other clients behave, we keep it as it is. Especially that making sure that everything is flushed can cause potential edge cases of very slow (which is unwated) drop process (for example if client encounters some connectivity problems at that time). |
to make CI happy
noted, so I assume you're only supposed to call
pardon my ignorance, but what if I'm not receiving messages, only publishing them?
but that doesn't seem to be the case here, unless I'm hitting an edge-case where there's just not enough time for the buffer to get flushed before the app exits.
I thought the flushing mechanism was count or time-based so I expected there to be some sort of threshold setting but since you said it's not, never mind. |
Yes. We have flush since the time when flush was time-based. Now it's useful just for closing.
Sorry, mental shortcut. I meant - the loop that polls the queue is receiving the published messages and putting them into the stream :).
This is different - when close the client immediately after publishing the message, there is nothing that forces the drop to wait until loop finished reading/flushing messages in the buffer. We might revisit it, but I assume that as
Understood :). |
Got it, thank you for taking your time to explain it! Should I change the comment's phrasing to say that calling -//! // Flush internal buffer to make sure messages are sent
+//! // Optionally flush internal buffer to make sure messages are sent
//! client.flush().await?; Or maybe instead of suggesting |
Happy to help! I would rather explicitly mention that it's a good idea to flush before shutting down the application/closing the client. |
You forgot to import |
oops. my bad, thank you. |
- remove flush() call from complete example code - change phrasing on publish-only example comment
Alright, how does this look? |
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! Thank you!
This PR adds
client.flush()
calls to publish examples in the documentation to help avoid potential confusion when messages aren't immediately published due to buffering (in fact, on my short-lived CLI app they weren't being sent at all). See #773 (comment).@Jarema I actually have a few questions in regards to this:
flush()
supposed to be called on a regular basis if not publishing too frequently?