Disaptch a message
📤 Dispatching a Message
Messages can be dispatched from anywhere in your application—such as services, controllers, scheduled jobs, or event listeners. This allows for clean, decoupled communication between parts of your system.
🚀 Example: Dispatch from an HTTP Controller
Here’s a simple example of dispatching a message when an HTTP request is made:
📦 Components Explained
Component
Purpose
@MessageBus()
Injects a specific message bus by name.
RoutingMessage
Wraps the message and defines the route it should be sent to.
SendMessage
Your custom message class with data to transmit.
dispatch()
Sends the message to all subscribed handlers matching the route.
💡 Best Practices
Use meaningful routing keys (e.g.,
user.created
,notification.send
).Define routing keys as the Enum
Always wrap domain objects in proper message classes instead of sending raw payloads.
Last updated