# Multi-Node Watch Example This example demonstrates how to use the WebHook notification feature in a 2-node Raft cluster. Each client registers to a specific node watching **different keys**, demonstrating independent notification channels. ## Architecture * **Cluster**: 2 Nodes * **Node 1**: Raft Port 9500, HTTP API Port 8500 * **Node 2**: Raft Port 9501, HTTP API Port 8501 * **Clients**: 2 Listeners * **Client 1**: Listens on 9600, Subscribes to Node 1 for `key-1` * **Client 2**: Listens on 9601, Subscribes to Node 2 for `key-2` ## Running the Example You will need 4 terminal windows. ### 1. Start the Cluster Nodes **Terminal 1 (Node 1):** ```bash cd example/watch/node1 go run main.go ``` **Terminal 2 (Node 2):** ```bash cd example/watch/node2 go run main.go ``` Wait a moment for them to elect a leader. ### 2. Start the Clients **Terminal 3 (Client 1):** ```bash cd example/watch/client1 go run main.go ``` *This will start a listener and auto-subscribe to Node 1 for `key-1`.* **Terminal 4 (Client 2):** ```bash cd example/watch/client2 go run main.go ``` *This will start a listener and auto-subscribe to Node 2 for `key-2`.* ### 3. Trigger Data Changes You can trigger changes by sending a request to **ANY** node's HTTP API. Since the clients are watching different keys, you can target specific clients. **Trigger Client 1 (via Node 1):** ```bash # Sets key-1, Client 1 should notify curl -X POST http://127.0.0.1:8500/kv \ -H "Content-Type: application/json" \ -d '{"key": "key-1", "value": "hello-client-1"}' ``` **Trigger Client 2 (via Node 1):** ```bash # Sets key-2, replicated to Node 2, Client 2 should notify curl -X POST http://127.0.0.1:8500/kv \ -H "Content-Type: application/json" \ -d '{"key": "key-2", "value": "hello-client-2"}' ``` ### 4. Expected Output * When you set `key-1`, only **Client 1** should output a notification. * When you set `key-2`, only **Client 2** should output a notification. This demonstrates that notifications are filtered by key and dispatched locally by the node holding the subscription, even though the data is consistent across the entire cluster.