是否有针对事件驱动的Kafka使用者的Python API? [英] Is there a Python API for event-driven Kafka consumer?

查看:92
本文介绍了是否有针对事件驱动的Kafka使用者的Python API?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试构建一个以Kafka为唯一界面的Flask应用.因此,我希望有一个Kafka使用者,当相关主题流中有新消息时触发该使用者,并通过将消息推回到Kafka流中进行响应.

I have been trying to build a Flask app that has Kafka as the only interface. For this reason, I want have a Kafka consumer that is triggered when there is new message in the stream of the concerned topic and respond by pushing messages back to the Kafka stream.

我一直在寻找类似Spring的实现:

I have been looking for something like the Spring implementation:

@KafkaListener(topics = "mytopic", groupId = "mygroup")
public void listen(String message) {
    System.out.println("Received Messasge in group mygroup: " + message);
}

我看过:

  1. kafka-python
  2. pykafka
  3. confluent-kafka
  1. kafka-python
  2. pykafka
  3. confluent-kafka

但是我找不到与事件驱动的Python实现方式相关的任何东西.

But I couldn't find anything related to event-driven style of implementation in Python.

推荐答案

Kafka Consumer必须不断轮询以从经纪人那里检索数据.

Kafka Consumer have to continuously poll to retrieve data from brokers.

Spring为您提供了这个精美的API,但在幕后,它循环调用poll,并且仅在检索到记录时才调用您的方法.

Spring gives you this fancy API but under the covers, it calls poll in a loop and only invokes your method when records have been retrieved.

您可以使用您提到的任何Python客户端轻松构建类似的东西.就像在Java中一样,这不是(大多数)Kafka客户端直接公开的API,而是由顶层上的某个层提供的东西.这是需要构建的东西.

You can easily build something similar with any of the Python clients you've mentioned. Like in Java, this is not an API directly exposed by (most) Kafka clients but instead something provided by a layer on top. It's something you need to build.

这篇关于是否有针对事件驱动的Kafka使用者的Python API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆