1

My faust set up is not printing any messages to console. I originally thought this was an authorization issue, but I've been able retrieve raw messages following the example here (How to get faust to send raw replies). I want to be able to retrieve the messages using just await test()

This is my code...

import asyncio
import faust
from faust.types.auth import AuthProtocol

broker_credentials.protocol = AuthProtocol.SASL_SSL

app = faust.App(
    "TOPIC",
    broker=broker,
    value_serializer="json",
    broker_credentials=broker_credentials,
    topic_allow_declare=False, 
    topic_disable_leader=True,
)

test_topic = app.topic(TOPIC)

async def test():
  async for event in app.stream(test_topic):
    print(event)
    
await test()

Does anyone have any advice? Right now the loop just seems to hang

Sam Comber
  • 1,237
  • 1
  • 15
  • 35

1 Answers1

0

A function cannot be awaited like that. A method can be awaited only inside an async function. The await keyword needs to be present inside an async function. You can follow the Faust docs for an example.

import asyncio
import faust

app = faust.App("sample-agent",broker=broker_url)
test_topic = app.topic("sample-topic")

@app.agent(test_topic)
async def test(stream):
    async for event in stream:
        print(event)

if __name__ == "__main__":
    app.main()

After this you can run the script using the following command

python script.py worker -l info
Rahul Hindocha
  • 170
  • 2
  • 14