Last active
January 22, 2024 19:42
-
-
Save slayton/319507c77abc4d343591bcbfb221d55a to your computer and use it in GitHub Desktop.
consumer_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
from faststream import FastStream, Logger | |
from faststream.redis import RedisBroker, StreamSub | |
broker = RedisBroker("redis://localhost:6379") | |
app = FastStream(broker, logger=None) | |
chan = "chan" | |
word_publisher = broker.publisher(chan) | |
@broker.subscriber(chan) | |
async def lower(word: str, logger: Logger) -> None: | |
lower = word.lower() | |
logger.info(f"LOWER:{lower}") | |
async def send(word) -> None: | |
await word_publisher.publish(word) | |
@app.after_startup | |
async def run(): | |
words = ['APPle', 'banaNA'] | |
await asyncio.gather(*[send(w) for w in words]) |
Author
slayton
commented
Jan 22, 2024
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment