Add messages to services
A service in EventCatalog can receive (consume) or send (produce) messages (commands, events and queries).

Producing and consuming messages from your service
To add messages to your service you first have to define your messages, if you don't have any messages you can create one.
To add messages to a service you need to define them in either the sends or receives array within your service frontmatter API.
---
id: OrderService
... # other service frontmatter
receives:
# id of the message this service receives (consumes)
- id: PaymentProcessed
# (optional) The version of the message you want to add.
# Supports semver matching (e.g ^1.0.1, 1.x.x).
# But if no version is given the latest version of the message will be used.
version: 0.0.1
sends:
# id of the message this service sends (produces)
- id: OrderProcessed
version: 2.x.x
---
<!-- Markdown contents... -->
When you define your messages for your service you can define the version of them too. This can be powerful if you have multiple versions of your events, commands or queries. Example could be an API that you are consuming, maybe you are consuming an old version of this API you can specify that.
Routing messages through channels
Messages may also travel through channels (e.g message brokers, queues, buses).
To specify a channel you need to use the to and from fields in your service frontmatter.
This example shows :
- the
OrderServicesending anOrderPlacedmessage to theorders.eventschannel. - the
OrderServiceconsuming the aPaymentProcessedmessage from thepayments.eventschannel.
---
id: OrderService
... # other service frontmatter
# Service sends a message called OrderPlaced
# This message is published to the orders.events channel (e.g broker)
sends:
- id: OrderPlaced
to:
# The id of the channel (e.g queue)
- id: orders.events
# Service consumes a message called PaymentProcessed
# This message is consumed from the payments.events channel (e.g queue)
receives:
- id: PaymentProcessed
from:
# The id of the channel (e.g bus)
- id: payments.events
---
You can read more about routing messages through channels in the routing messages through channels guide.