How Can I get stream one value in HTTP Request?

未关闭
#637 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
12/100
Issue 类型
文档
描述清晰度
需要澄清
活跃度
停滞
技术栈
kafka, python

调研方向

Start from the get_data page view and process_events in the snippet: get_data creates data from agent.stream() but never reads it, and process_events reads stream.current_event inside stream.events(). Check how Faust agent streams are consumed from a web handler and what the Faust docs say about sharing a stream with an HTTP request. Done means the question has a working pattern or a documented answer. The issue has been inactive for about 18 months and needs a maintainer to confirm the approach.

由索引模型根据 Issue 内容生成。

描述

from faust import App, Record
from faust.web import Request, Response, View
import asyncio

app = App('ness', broker='kafka://localhost')

data_queues = {}

async def process_message(stream):
async for record in stream:
yield record

async def process_events(stream):
async for event in stream.events():
event = stream.current_event
message = event.message
topic = event.message.topic
print(f"Received message {message} from topic {topic}")

agents = {}
topics = {}
for i in ['test-30']:
agents[i] = app.agent(channel=i, name=app.topic(i))(process_message)
topics[i] = app.topic(i)

app.start()

@app.page('/get_data/{topic_name}')
async def get_data(self, request: Request, topic_name) -> Response:
print(topic_name)
if topic_name not in agents:
return self.json({'error': 'Topic not found'}, status=404)

agent = agents[topic_name]
data = process_events(agent.stream())

return self.json({'topic_name': topic_name, 'message': 'data'})

if name == 'main':
import sys
if len(sys.argv) < 2:
sys.argv.extend(['worker', '-l', 'info'])
app.main()

Versions

  • Python version: 3.11
  • Faust version: faust-streaming 0.11.1
  • Operating system macOS
  • Kafka version 2.8
  • RocksDB version (if applicable) None
主要语言
Python
星标
1.9k
派生
205
平均合并
2 小时 2 分钟
30 天内合并 PR
1

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

faust-streaming/faust 的其他 Issue

查看 faust-streaming/faust 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。