Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Apache Kafka provide an asynchronous subscription callback API?

My project is looking at Apache Kafka as a potential replacement for an aging JMS-based messaging approach. In order to make this transition as smooth as possible, it would be ideal if the replacement queuing system (Kafka) had an asynchronous subscription mechanism, similar to our current project's JMS mechanism of using MessageListener and MessageConsumer to subscribe to topics and receive asynchronous notifications. I don't care so much if Kafka doesn't strictly conform to the JMS API, but conversely, I would prefer not to redesign our entire suite of publish-subscribe-notification classes if I don't need to.

I can find all kinds of KafkaConsumer polling examples, but so far have not been able to find any examples with a client being notified of new messages via asynchronous notification.

Does anyone know if the current version of Kafka (0.10.2 as of the time of this post) provides such an API, or am I stuck with trying to rewrite my legacy code using polling?

like image 673
Ogre Psalm33 Avatar asked Apr 21 '17 15:04

Ogre Psalm33


People also ask

Does Kafka support asynchronous?

Kafka is a powerful stream processing tool, but it's an asynchronous tool.

Is Kafka producer asynchronous?

The Kafka Producer has a send() method which is asynchronous. Calling the send method adds the record to the output buffer and return right away. The buffer is used to batch records for efficient IO and compression. The Kafka Producer configures acks to control record durability.

Does Kafka have an API?

Kafka has four core APIs: The Producer API allows an application to publish a stream of records to one or more Kafka topics. The Consumer API allows an application to subscribe to one or more topics and process the stream of records produced to them.

What is Kafka callback?

A callback interface that the user can implement to allow code to execute when the request is complete. This callback will generally execute in the background I/O thread so it should be fast.


1 Answers

Kafka clients provides only on-demand pooling mechanism but you can use spring-kafka. It provides MessageListener interface and KafkaListener annotation and similar. See documentation.

like image 106
reynev Avatar answered Oct 18 '22 07:10

reynev