Documentation
¶
Overview ¶
Package main demonstrates channel-based message passing between workflows.
This example shows three delivery modes: - Broadcast mode: All consumers receive all messages (fan-out) - Competing mode: Each message is delivered to exactly one consumer (load balancing) - Direct mode: SendTo delivers messages to a specific workflow instance
Usage:
go run ./examples/channel/
API Endpoints:
Start a broadcast consumer (all receive all messages): curl -X POST http://localhost:8084/start-consumer \ -H "Content-Type: application/json" \ -d '{"consumer_id": "alice", "mode": "broadcast"}'
Start a competing consumer (each message goes to one): curl -X POST http://localhost:8084/start-consumer \ -H "Content-Type: application/json" \ -d '{"consumer_id": "worker-1", "mode": "competing"}'
Start a direct message receiver (for SendTo): curl -X POST http://localhost:8084/start-consumer \ -H "Content-Type: application/json" \ -d '{"consumer_id": "bob", "mode": "direct"}' # Note the instance_id in the response for SendTo
Publish a message (broadcast/competing consumers receive it): curl -X POST http://localhost:8084/publish \ -H "Content-Type: application/json" \ -d '{"channel": "notifications", "message": "Hello everyone!", "from": "system"}'
Send a direct message to a specific instance: curl -X POST http://localhost:8084/send-to \ -H "Content-Type: application/json" \ -d '{"instance_id": "<instance-id-from-step-3>", "channel": "notifications", "message": "Private message"}'