Broker Router#
Sometimes you want to:
- split an application into includable modules
- separate business logic from your handler registration
- apply some decoder/middleware/dependencies to a subscribers group
For these reasons, FastStream has a special Broker Router.
Router Usage#
First, you need to import the Broker Router from the same module from where you imported the broker.
When creating a Broker Router, you can specify a prefix that will be automatically applied to all subscribers and publishers of this router.
Now you can use the created router to register handlers and publishers as if it were a regular broker
Then you can simply include all the handlers declared using the router in your broker
Please note that when publishing a message, you now need to specify the same prefix that you used when creating the router
Tip
Also, when creating a Broker Router, you can specify middleware, dependencies, parser and decoder to apply them to all subscribers declared via this router.
Delay Handler Registration#
If you want to separate your application's core logic from FastStream's routing logic, you can write some core functions and use them as Broker Router handlers
later:
Warning
Be careful, this way you won't be able to test your handlers with a mock
object.