Created
January 22, 2024 19:37
-
-
Save slayton/3467747c06eb633c3cd2d0064682a202 to your computer and use it in GitHub Desktop.
Consumer Group
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(stream=StreamSub(chan, group='group1', consumer='1')) | |
async def upper(word: str, logger: Logger) -> None: | |
upper = word.upper() | |
logger.info(f"UPPER:{upper}") | |
@broker.subscriber(stream=StreamSub(chan, group='group2', consumer='2')) | |
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