tags:
- ready
- online
- reviewed
- microservices
- go
- frameworks
watermill
Contents
__Roadmap info from [ roadmap website ] (https://roadmap.sh/golang/go-microservices/watermill) __
Watermill
Watermill is an event streaming library for handling asynchronous requests in go. It provides multiple sets of implementations for pub/sub. e.g: You can use conventional pub/sub implementations like Kafka or RabbitMQ, but also HTTP or MySQL binlog, if that fits your use case.
Visit the following resources to learn more:
Watermill__
- Purpose: Event-driven systems, pub/sub architecture.
- Key Features: Messaging abstraction, integrates with Kafka, RabbitMQ, Google Cloud Pub/Sub.
- Best For: Microservices communicating via asynchronous events and messages.
Example:
pub, err := message.NewPublisher(
rabbitmq.NewPublisherConfig("amqp://guest:guest@localhost:5672/"),
nil,
)
Watermill__ - Event-Driven Systems
Solution Example: E-Commerce Order Processing
- Use Case: In an e-commerce platform, multiple services such as order management, inventory, and payment can communicate asynchronously using events.
- Framework Usage: Each service (e.g., OrderService, PaymentService, InventoryService) publishes or subscribes to messages via Watermill using message brokers like Kafka or RabbitMQ.
- Workflow:
-
OrderService publishes a message to the
order_createdtopic after a customer places an order. -
PaymentService subscribes to the
order_createdtopic and processes payments. -
InventoryService updates stock based on the
order_processedevent.
Example:
msg := message.NewMessage(watermill.NewUUID(), []byte(`{"order_id":123}`))
err := publisher.Publish("order_created", msg)