Publisher Object#
The Publisher Object provides a full-featured way to publish messages. It has an AsyncAPI representation and includes testability features. This method creates a reusable Publisher object.
Additionally, this object can be used as a decorator. The order of Subscriber and Publisher decorators doesn't matter, but @publisher
can be used only with functions already decorated by a @broker.subscriber(...)
.
Note
It uses the handler function's return type annotation to cast the function's return value before sending, so be accurate with it.
Message Broadcasting#
The decorator can be used multiple times with one function to broadcast the function's return:
This way, you will send a copy of your return to all output topics.
Note
Also, if this subscriber consumes a message with RPC mode, it sends a reply not only to the RPC channel but also to all publishers as well.
Details#
Additionally, @publisher
automatically sends a message with the same correlation_id
as the incoming message. This way, you get the same correlation_id
for the entire message pipeline process across all services, allowing you to collect a trace.