channel

command
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2025 License: MIT Imports: 16 Imported by: 0

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:

  1. 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"}'

  2. 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"}'

  3. 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

  4. 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"}'

  5. 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"}'

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL