How Can I get stream one value in HTTP Request?

Đang mở
#637 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
12/100
Loại issue
Tài liệu
Độ rõ ràng
Cần làm rõ
Mức độ hoạt động
Đình trệ
Công nghệ
kafka, python
Lĩnh vực
backend, stream-processing

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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
Ngôn ngữ chính
Python
Star
1.9k
Fork
205
Merge trung bình
2 giờ 2 phút
Pull request đã merge (30 ngày)
1

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của faust-streaming/faust

Tất cả issue của faust-streaming/faust

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.