Replies: 3 comments 1 reply
-
- Drain futures will complete when there are no more messages or the timeout expires. Try this code:
|
Beta Was this translation helpful? Give feedback.
-
Ha! Indeed, I didn't know this. Is this a technical limitation? From the API, I would expect it to work the same with or without the default handler. This is how I expected my code to behave
I tested with val dispatcher = connection.createDispatcher { message =>
println("received message " + String(message.getData()))
Thread.sleep(1000)
}
val subscription = dispatcher.subscribe("subject")
// ...
subscription.drain(Duration.ofSeconds(30)).get() and indeed, this times it waits properly until the 5 messages are processed. |
Beta Was this translation helpful? Give feedback.
-
@AlixBa Moved to a discussion. I probably should have noted the similarities between the connection drain and dispatcher drain. They are both done in a way that expects the user to be meaning "I'm completely done with this", i.e. and they both basically close. What were you trying to accomplish by using drain? Maybe that's a better way to look at this. If you are done with the dispatcher, you can just unsubscribe, the dispatcher is basically just doing that, but also the closing down. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Observed behavior
using
subscription.drain(timeout)
doesn't wait until the messages for this subscription in the buffer are processed to complete (and complete positively).Expected behavior
subscription.drain(timeout)
should returntrue
when all buffered messages have been processed, or it should return an error if it's not intended to be used throughsubscription
but throughdispatcher.drain
, or maybe it should be explained in the java doc?Server and client version
server: nats:2.9.22-alpine
client: 2.22.0
Host environment
No response
Steps to reproduce
output
Beta Was this translation helpful? Give feedback.
All reactions