2

I'm trying to get replies like bytes using Faust Stream. But it always encode replies as sting (because faust uses json codec for replies). Is it possible to get replies just as bytes?

import asyncio
import faust


app = faust.App(
    'raw-example',
    broker=...,
    value_serializer='raw',
    reply_create_topic=True,
    topic_partitions=1,
    topic_replication_factor=3,
)

@app.timer(2.0, on_leader=True)
async def publish_greetings():
    print('PUBLISHING ON LEADER!')
    res = await say.ask(value=b'some greeting')
    print(f'Reply: {res} type {type(res)}')

@app.agent()
async def say(greetings):
    async for greeting in greetings:
        print(f'In listener: {greeting} type {type(greeting)}')
        yield greeting

app.conf.web_enabled = False        

async def start_worker(worker):
    await worker.start()

def manage_loop():
    loop = asyncio.get_event_loop()
    worker = faust.Worker(app, loop=loop, loglevel='WARNING')
    try:
        loop.run_until_complete(start_worker(worker))
    finally:
        worker.stop_and_shutdown()


manage_loop()

Here it receives bytes in the listener say but it will be str in the value, returned by ask

Platform: Linux-4.15.0-1050-azure-x86_64-with-debian-stretch-sid

Python 3.7.3

Faust: 1.10.3

Роман Коптев
  • 1,555
  • 1
  • 13
  • 35

0 Answers0