|
|
2 nedēļas atpakaļ | |
|---|---|---|
| .. | ||
| client1 | 2 nedēļas atpakaļ | |
| client2 | 2 nedēļas atpakaļ | |
| node1 | 2 nedēļas atpakaļ | |
| node2 | 2 nedēļas atpakaļ | |
| README.md | 2 nedēļas atpakaļ | |
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.
key-1key-2You will need 4 terminal windows.
Terminal 1 (Node 1):
cd example/watch/node1
go run main.go
Terminal 2 (Node 2):
cd example/watch/node2
go run main.go
Wait a moment for them to elect a leader.
Terminal 3 (Client 1):
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):
cd example/watch/client2
go run main.go
This will start a listener and auto-subscribe to Node 2 for key-2.
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):
# 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):
# 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"}'
key-1, only Client 1 should output a notification.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.