3

I'm using a non Blocking (Async) sending message to Kafka using this :

    ListenableFuture<SendResult<Integer, String>> future = template.send(record);
    future.addCallback(new ListenableFutureCallback<SendResult<Integer, String>>() {

        @Override
        public void onSuccess(SendResult<Integer, String> result) {
            handleSuccess(data);
        }

        @Override
        public void onFailure(Throwable ex) {
            handleFailure(data, record, ex);
        }

    });

This work perfectly when the send action does its work.

But when there is a connection problem (server down for example), the result become non asynchronous and the method remains blocked until the end of the duration of max.block.ms.

Idriss
  • 354
  • 3
  • 10

1 Answers1

2

This is natural in Async KAfka producer. You have two options

  1. Either reduce the max.block.ms but don't reduce it too much.
  2. You can wait for acks

You can also create a callback function for onCompletion()

Vinit Pillai
  • 518
  • 6
  • 17
  • kindly, can evolve your answer? Maybe just pasting some code snippet or comment a bit more. What do you mean by "wait for acknolodegments"? Does't it mean "against" approach to Async? I am studing use Async Kafka producer for logging purposes. Have you faced similar scenario and do apply some benchmarcket regard max.block.ms? – Jim C Feb 21 '20 at 15:29