【发布时间】:2019-11-08 23:13:41
【问题描述】:
我很好奇您应该如何表达您希望将消息传递到浮士德的 Kafka 主题。他们自述文件中的示例似乎没有写入主题:
import faust
class Greeting(faust.Record):
from_name: str
to_name: str
app = faust.App('hello-app', broker='kafka://localhost')
topic = app.topic('hello-topic', value_type=Greeting)
@app.agent(topic)
async def hello(greetings):
async for greeting in greetings:
print(f'Hello from {greeting.from_name} to {greeting.to_name}')
@app.timer(interval=1.0)
async def example_sender(app):
await hello.send(
value=Greeting(from_name='Faust', to_name='you'),
)
if __name__ == '__main__':
app.main()
我希望上述代码中的hello.send 向主题发布消息,但似乎没有。
有许多阅读主题的示例,以及许多使用 cli 推送临时消息的示例。梳理完文档后,我没有看到任何明确的在代码中发布到主题的示例。我是不是疯了,上面的代码应该可以工作?
【问题讨论】:
-
hello.send是asyncio的一部分,我认为,不是浮士德函数......浮士德主要用于流处理,而不是流“生产”。这意味着您已经拥有该主题中的数据,并且 Kafka Streams 的工作方式类似 -
上面的 example-sender 确实将数据发布到“hello-topic”。您可以使用 kafka-console-consumer 进行检查。
标签: python apache-kafka faust