Documentation Index
Fetch the complete documentation index at: https://mintlify.com/microservices-patterns/ftgo-application/llms.txt
Use this file to discover all available pages before exploring further.
The Consumer Service in the FTGO application is responsible for managing the registered customers who place food orders. It stores consumer identity, exposes a REST API for registration and lookup, and participates in order creation sagas by validating that a given consumer is allowed to place an order of a given total. This page covers the service’s responsibilities, domain model, REST API, messaging interactions, and database schema.
Responsibilities
- Register new consumers and persist them as
Consumer aggregates
- Expose a read endpoint so other services (and the API gateway) can look up consumer details
- Publish a
ConsumerCreated event when a consumer registers
- Handle the
ValidateOrderByConsumer saga command, issued by the Order Service during CreateOrderSaga, to confirm the consumer is eligible to place an order
Domain Model
The core entity is Consumer, persisted to the consumers table.
| Field | Type | Notes |
|---|
id | Long | Auto-generated primary key |
name | PersonName | Embedded first/last name |
Consumer.create(PersonName) is a static factory method that returns a ResultWithEvents<Consumer> containing the new aggregate and a ConsumerCreated event. The validateOrderByConsumer(Money orderTotal) method contains extensible business logic for order eligibility checks.
The PersonName type is a shared value object from the ftgo-common module, containing firstName and lastName fields.
REST API
The service listens on port 8081. All endpoints are under the /consumers path.
| Method | Path | Description |
|---|
POST | /consumers | Register a new consumer; returns { consumerId } |
GET | /consumers/{consumerId} | Retrieve consumer name. Returns 404 if not found. |
Create consumer request body
{
"name": {
"firstName": "Jane",
"lastName": "Doe"
}
}
Get consumer response body
{
"name": {
"firstName": "Jane",
"lastName": "Doe"
}
}
Messaging
Events published
The DomainEventPublisher emits the following events on the net.chrisrichardson.ftgo.consumerservice.domain.Consumer channel:
| Event | Trigger |
|---|
ConsumerCreated | A new consumer registers via POST /consumers |
Saga commands handled
The service listens on the consumerService command channel and handles:
| Command | Handler | Reply |
|---|
ValidateOrderByConsumer | ConsumerServiceCommandHandlers.validateOrderForConsumer() | withSuccess() if eligible, withFailure() if ConsumerVerificationFailedException is thrown |
This command is sent by the Order Service’s CreateOrderSaga as its first step. A failure reply causes the saga to abort and the order to be rejected.
The Consumer Service is a saga participant, not an orchestrator. It reacts to commands issued by the Order Service and replies with a success or failure message consumed by the saga framework.
Database
The Consumer Service uses MySQL. Key tables:
| Table | Description |
|---|
consumers | The Consumer aggregate: auto-generated ID and embedded PersonName |
Transactional outbox messages for published events are stored in the Eventuate Tram message table and relayed by the CDC service.