Redis Stream Publishing with FastStream#
Publishing Data to Redis Stream#
To publish messages to a Redis Stream, you implement a function that processes the incoming data and applies the @broker.publisher(...)
decorator along with the Redis stream name to it. The function will then publish its return value to the specified stream.
-
Create your RedisBroker instance
-
Initiate your FastStream application with the RedisBroker
-
Define your data model
-
Set up the function for data processing and publishing
Using the
@broker.publisher(...)
decorator in conjunction with the@broker.subscriber(...)
decorator allows seamless message processing and republishing to a different stream.By decorating a function with
@broker.publisher(...)
, we tell FastStream to publish the function's returned data to the designated"output stream"
. The defined function also serves as a subscriber to the"input-stream"
, thereby setting up a straightforward data pipeline within Redis streams.
Here's the complete example that showcases the use of decorators for both subscribing and publishing to Redis streams: