confluentinc / librdkafka

The Apache Kafka C/C++ library
Other
204 stars 3.14k forks source link

[Question] Approach to implement the both synchronous and asynchronous producer #1651

Closed karthikeyanajendran1984 closed 6 years ago

karthikeyanajendran1984 commented 6 years ago

We have to produce or publish a message to Kafka Server on synchronous and asynchronous mode in our producer application. we have either high volume of message publishing or lower volume OLTP type messages, also Scenario 1 : our application should return the acknowledgement to caller for each message or batched message(synchronous) Scenario 2 : our application can just log delivery acknowledgement in log whenever acknowledgements received(asynchronous).

We have an approach to instance can support either synchronously or asynchronous mode based on configuration. KAFKA_COMMUNICATION_TYPE : Asynchronous(Configuration) Approach to asynchronous communication(Both single & batch message publishing):

1) Two key parameters queue.buffering.max.ms, batch.num.messages to be consider and set for latency and throughput. 2) Register a delivery report callback functions to get acknowledgement status. 3) set request.required.acks to 1 for asynchronous non blocking call 4) Also librdkafka C API support two async calls (rd_kafka_produce and rd_kafka_produce_batch) to be used for single message processing and batched request. 5) invoke rd_kafka_poll at to serve the delivery report. 6) Once delivery report callback function get invoked by librdkafka, log the acknowledgement status message into producer application log file. Because here the caller who send the actual message, he will not wait for any response. So we log into log file and error status can be handled manually. Questions:

Do we need to set request.required.acks to 1 for asynchronous non blocking call ? Can you please comment on above asynchronous approach ?


KAFKA_COMMUNICATION_TYPE : Synchronous (Configuration) Approach to synchronous communication(Both single & batch message publishing):

1) Register a delivery report callback functions to get acknowledgement status. 2) set request.required.acks to 1 for asynchronous non blocking call 3) librdkafka C API support only on async calls and to support sync producer( already mentioned on https://github.com/edenhill/librdkafka/wiki/Sync-producer) 4) Here for single message processing, it has to be wait for acknowledgements for each messages in a loop based as mentioned on above link. 5) Once received the acknowledgement status from delivery report callback, send back the acknowledgment to caller. Because here the caller who send the actual message, he will wait for a response for each message. So we send acknowledgment status to caller. Questions:

1) As we have to support batch message processing in synchronous message, we have to send one acknowledgment status for batch message to caller. But there is no approach to be use in Sync Producer link (mentioned above) to use batch API(rd_kafka_produce_batch()), it has only used rd_kafka_produce(). Can you please give us whether it can be implementable or not advisable ? 2) As i look into batch API (rd_kafka_produce_batch), delivery report calls for each message inside the batch. For Ex : If we have publish 1000 message at one batch call, we will receive 1000 deivery reports through callback for each message. Please confirm ? 3) Do we also need to consider the key parameters(queue.buffering.max.ms and batch.num.messages) while performing synchronous call or only set request.required.acks is enough ?


COMMON: Please have a look and advise on the above approach.

Thanks in advance.

Regards, Karthikeyan Rajendran.

mhowlett commented 6 years ago

Asynchonous Configuration

Synchronous Configuration

karthikeyanajendran1984 commented 6 years ago

@mhowlett , Thanks for your valuable reply.

Regarding synchronous communication, as you mentioned " librdkafka can't do transactional batch delivery - there will be an individual DR per message ".

So I have the restriction to implement the batch request in synchronous mode as it deliver individual DR per message, because it is very important to deliver the response for the batch request. But i will try to find out some way to collect each replies and send one response back to the caller.

In the mean time can you or @edenhill please let me know the timeline for the fix to perform transnational batch delivery. As we are in agile methodology we have to deliver our producer API using librdkafka C API in 30MD. Do i need to raise a separate Issue for the same ? Regards, Karthikeyan Rajendran.

edenhill commented 6 years ago

Idempotent producer and transactional API is scheduled for Q2

karthikeyanajendran1984 commented 6 years ago

@edenhill, am i receive any notification once this issue fixed and patch release. ? can you please let me know how i can track ?

edenhill commented 6 years ago

Please monitor this issue: https://github.com/edenhill/librdkafka/issues/1308