From fa452a3b7e8a19424307f82c7859ea0a54317ac8 Mon Sep 17 00:00:00 2001 From: Thomas Darimont Date: Sun, 5 May 2024 11:10:42 +0200 Subject: [PATCH] Revise nats examples --- deployments/local/dev/nats/readme.md | 63 ++++++++++++++++++++++++-- deployments/local/dev/nats/server.conf | 5 +- 2 files changed, 63 insertions(+), 5 deletions(-) diff --git a/deployments/local/dev/nats/readme.md b/deployments/local/dev/nats/readme.md index a55723f0..e4bd3d21 100644 --- a/deployments/local/dev/nats/readme.md +++ b/deployments/local/dev/nats/readme.md @@ -20,7 +20,64 @@ Select context nats ctx select localhost ``` -Nats subscribe to keycloak subject +Nats subscribe to subject with prefix ``` -nats sub acme.iam.keycloak> -``` \ No newline at end of file +nats sub "acme.iam.keycloak.>" +``` + + +--- + +# Misc + +## Create stream +``` +nats stream add KEYCLOAK --subjects "acme.iam.keycloak.*" --ack --max-msgs=-1 --max-bytes=-1 --max-age=1y --storage file --retention limits --max-msg-size=-1 --discard=old + +nats stream info KEYCLOAK +``` + +## Add consumers +``` +nats consumer add KEYCLOAK USER --filter "acme.iam.keycloak.user" --ack explicit --pull --deliver all --max-deliver=-1 --sample 100 +nats consumer add KEYCLOAK ADMIN --filter "acme.iam.keycloak.admin" --ack explicit --pull --deliver all --max-deliver=-1 --sample 100 +nats consumer add KEYCLOAK MONITOR --filter '' --ack none --target monitor.KEYCLOAK --deliver last --replay instant +``` + +## Stream Status + +https://docs.nats.io/running-a-nats-service/configuration/clustering/jetstream_clustering/administration + +``` +nats stream report + +nats server report jetstream --user "admin" --password "password" +``` + +## Read consumer + +``` +nats consumer next KEYCLOAK USER --count 1000 +``` + +## Subscribe to subject +``` +nats sub "acme.iam.keycloak.user" --translate 'jq .' --count 10 +``` + +--- + +# Misc + +nats stream add IOT --subjects "iot.*" --ack --max-msgs=-1 --max-bytes=-1 --max-age=1y --storage file --retention limits --max-msg-size=-1 --discard=old + +nats consumer add IOT CMD --filter "iot.cmd" --ack explicit --pull --deliver last --max-deliver=-1 --sample 100 + +nats consumer next IOT CMD --count 3 + +nats pub iot.cmd --count=6 --sleep 1s "iot cmd #{{Count}} @ {{TimeStamp}}" + +nats sub iot.cmd --last +nats sub iot.cmd --new + +nats sub "iot.*" --last-per-subject \ No newline at end of file diff --git a/deployments/local/dev/nats/server.conf b/deployments/local/dev/nats/server.conf index 32f503c8..13e03bf2 100644 --- a/deployments/local/dev/nats/server.conf +++ b/deployments/local/dev/nats/server.conf @@ -5,14 +5,15 @@ accounts: { ] }, KEYCLOAK: { - jetstream: enabled, + jetstream: true, users: [ { user: "keycloak", password: "keycloak" } ] } } -jetstream {} +jetstream: { +} #cluster: { # name: LOCAL,