Esempio n. 1
0
        retry_count = 0 if retry_count_bytes is None else int(retry_count_bytes.decode('utf-8'))
        if retry_count > KAFAK_CONSUMER_RETRY_LIMIT:
            new_headers = event.headers.copy()
            new_headers['Status'] = bytes(str('ERROR'), 'utf-8')
            new_headers['ErrorMsg'] = bytes(str('RETRY_LIMIT_EXCEEDED'), 'utf-8')
            await event.forward(dlq_topic, headers=new_headers)
        try:
            value = await process_message(event.value)
            new_headers = event.headers.copy()
            new_headers['Status'] = bytes(str('SUCCESS'), 'utf-8')
            # if forward_topic is not None:
            #     await event.forward(forward_topic, headers=new_headers)
            #     # await event.send(forward_topic, key=event.key, value=value, headers=new_headers)
            # else:
            yield value.output
            print('Event Replied')
        except Exception as ex:
            new_headers = event.headers.copy()
            new_headers['ErrorMsg'] = bytes(str(ex), 'utf-8')
            await event.forward(retry_topic, headers=new_headers)

from faust.cli import argument, option

@app.command(
    argument('input', type=str),
    argument('output', type=str),
)
async def send_value(self, input: str, output: str) -> None:
    reply = await segment.ask(SegmentMessage(input, output))

Esempio n. 2
0
    async for key, name in stream.items():
        print(f'- {name.capitalize()} joined {key}')
        table[key].add(name)
        print(f'TABLE CUR: {table[key]!r}')


@app.agent(leaving_topic)
async def leave(stream):
    async for key, name in stream.items():
        print(f'- {name.capitalize()} left {key}')
        table[key].discard(name)
        print(f'TABLE CUR: {table[key]!r}')


@app.command(
    argument('location'),
    argument('name'),
)
async def joining(self, location: str, name: str):
    await joining_topic.send(key=location, value=name)


@app.command(
    argument('location'),
    argument('name'),
)
async def leaving(self, location: str, name: str):
    await leaving_topic.send(key=location, value=name)


@app.timer(10.0)
Esempio n. 3
0
    async for value in stream:
        yield await mul.ask(value=value ** 2)


@app.agent(mul_topic)
async def mul(stream: StreamT[float]) -> AsyncIterable[float]:
    async for value in stream:
        yield value * 100.0


@app.timer(interval=10.0)
async def _sender() -> None:
    # join' gives list with order preserved.
    res = await pow.join([30.3, 40.4, 50.5, 60.6, 70.7, 80.8, 90.9])
    print(f'JOINED: {res!r}')

    # map' gives async iterator to stream results (unordered)
    #   note: the argument can also be an async iterator.
    async for value in pow.map([30.3, 40.4, 50.5, 60.6, 70.7, 80.8, 90.9]):
        print(f'RECEIVED REPLY: {value!r}')


@app.command(argument('x'))
async def x100(self, x):
    res = await mul.ask(float(x))
    print(f'{x} * 100 = {res}')


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