Hi, using the Pulsar Java Client, is there a way, ...
# general
g
Hi, using the Pulsar Java Client, is there a way, when batching is enabled, to be called when messages are effectively send to pulsar ? As send is asynchronous, how can we be sure that message are effectively sent to pulsar (for example, in case of OOM) ?
l
The
CompletableFuture
of each message will get completed when the send completes. If it never completes or fails, the sender will have to assume that the message hasn't been sent. There's at-least-once semantics by default. If duplicates are a concern, you should use message deduplication https://pulsar.apache.org/docs/3.2.x/cookbooks-deduplication/ or transactions. The limitations of idempotent producer are explained here: https://pulsar.apache.org/docs/3.2.x/txn-why/#limitation-of-idempotent-producer .
This would be a good question to ask in https://github.com/apache/pulsar/discussions/categories/q-a so that the Q&A can be found by others later.
g
Thank you. Do we have a guarantee that the returns (CompletableFuture) will arrive in order ? (I mean, if 2 batches are sent async, do CompletableFuture will be called in the same order ?)
l
Yes. If you have complex message sending pipelines, you might find the Reactive Pulsar Client more convenient. Unfortunately there isn't good docs and examples for the Reactive Pulsar client (contributions are welcome!) https://github.com/apache/pulsar-client-reactive/blob/ea3a2e4eb7b40e78a6a0f4bbfa7c[…]rg/apache/pulsar/reactive/client/api/ReactiveMessageSender.java
ReactiveMessageSender supports a correlation object to be attached. This is very useful in handling the results. Obviously you can achieve it also with the plain Java API. One of the key concerns that ReactiveMessageSender handles is non-blocking backpressure handling.
Under the covers, Reactive Pulsar client also uses the Pulsar Java client's async API.