How Can I get stream one value in HTTP Request?

Aperta
#637 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
12/100
Tipo di issue
Documentazione
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
kafka, python

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
Python
Stelle
1.9k
Fork
205
Merge medio
2h 2m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di faust-streaming/faust

Tutte le issue di faust-streaming/faust

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.