Message Router
Message Router PHP
Routers consume messages from a message channel and forward each consumed message to one or more different message channels depending on a defined conditions.
Router must return name of the channel, where the message should be routed too. It can be array of channel names, if there are more.
class OrderRouter
{
#[Router("make.order")]
public function orderSpecificType(string $orderType) : string
{
return $orderType === 'coffee' ? "orderInCoffeeShop" : "orderInGeneralShop";
}
}Possible options
endpointId- Endpoint identifierinputChannnelName- Required option, defines to which channel endpoint should be connectedisResolutionRequired- If true, will throw exception if there was no channel name returned
Routing to multiple Message Channels
class OrderRouter
{
#[Router("order.bought")]
public function distribute(string $order) : array
{
// list of Channel names to distribute Message too
return [
'audit.store',
'notification.send',
'order.close'
];
}
}What can be Router used for?
Router is powerful concept that is backing up Query/Command and Event Bus implementations. Together with Message Gateway, you may roll up your own Bus implementation or build workflow pipelines.
Own Bus implementation
Last updated
Was this helpful?