Skip to content

Commit

Permalink
Ensure streams are created before source edits
Browse files Browse the repository at this point in the history
Signed-off-by: Byron Ruth <byron@nats.io>
  • Loading branch information
bruth committed Mar 27, 2023
1 parent 8014c81 commit 351f73a
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 184 deletions.
20 changes: 0 additions & 20 deletions examples/topologies/multi-region/cli/contexts/central-system.json

This file was deleted.

20 changes: 0 additions & 20 deletions examples/topologies/multi-region/cli/contexts/central-user.json

This file was deleted.

20 changes: 0 additions & 20 deletions examples/topologies/multi-region/cli/contexts/east-system.json

This file was deleted.

20 changes: 0 additions & 20 deletions examples/topologies/multi-region/cli/contexts/east-user.json

This file was deleted.

20 changes: 0 additions & 20 deletions examples/topologies/multi-region/cli/contexts/west-system.json

This file was deleted.

20 changes: 0 additions & 20 deletions examples/topologies/multi-region/cli/contexts/west-user.json

This file was deleted.

78 changes: 18 additions & 60 deletions examples/topologies/multi-region/cli/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,21 @@ version: '3'
services:
n1.east.example.net:
container_name: n1-east
image: nats
image: synadia/nats-server:nightly-main
dns_search: example.net
environment:
GATEWAY: c1
NAME: n1-east
ADVERTISE: localhost:10000
REGION: region:east
networks:
- nats-cluster1
- shared
volumes:
- "./configs/cluster-east.conf:/nats-server.conf"
- "./data/n1-east:/data"
- "./configs/cluster-east.conf:/nats/conf/nats-server.conf"
ports:
- 10000:4222
- 10100:7422
n2.east.example.net:
container_name: n2-east
image: nats
image: synadia/nats-server:nightly-main
dns_search: example.net
labels:
com.docker-tc.enabled: '1'
Expand All @@ -30,138 +26,106 @@ services:
NAME: n2-east
ADVERTISE: localhost:10001
REGION: region:east
networks:
- nats-cluster1
- shared
volumes:
- "./configs/cluster-east.conf:/nats-server.conf"
- "./data/n2-east:/data"
- "./configs/cluster-east.conf:/nats/conf/nats-server.conf"
ports:
- 10001:4222
- 10101:7422
n3.east.example.net:
container_name: n3-east
image: nats
image: synadia/nats-server:nightly-main
dns_search: example.net
environment:
GATEWAY: c1
NAME: n3-east
ADVERTISE: localhost:10002
REGION: region:east
networks:
- nats-cluster1
- shared
volumes:
- "./configs/cluster-east.conf:/nats-server.conf"
- "./data/n3-east:/data"
- "./configs/cluster-east.conf:/nats/conf/nats-server.conf"
ports:
- 10002:4222
- 10102:7422
n1.central.example.net:
container_name: n1-central
image: nats
image: synadia/nats-server:nightly-main
dns_search: example.net
environment:
GATEWAY: c1
NAME: n1-central
ADVERTISE: localhost:10003
REGION: region:central
networks:
- nats-cluster1
- shared
volumes:
- "./configs/cluster-central.conf:/nats-server.conf"
- "./data/n1-central:/data"
- "./configs/cluster-central.conf:/nats/conf/nats-server.conf"
ports:
- 10003:4222
- 10103:7422
n2.central.example.net:
container_name: n2-central
image: nats
image: synadia/nats-server:nightly-main
dns_search: example.net
environment:
GATEWAY: c1
NAME: n2-central
ADVERTISE: localhost:10004
REGION: region:central
networks:
- nats-cluster1
- shared
volumes:
- "./configs/cluster-central.conf:/nats-server.conf"
- "./data/n2-central:/data"
- "./configs/cluster-central.conf:/nats/conf/nats-server.conf"
ports:
- 10004:4222
- 10104:7422
n3.central.example.net:
container_name: n3-central
image: nats
image: synadia/nats-server:nightly-main
dns_search: example.net
environment:
GATEWAY: c1
NAME: n3-central
ADVERTISE: localhost:10005
REGION: region:central
networks:
- nats-cluster1
- shared
volumes:
- "./configs/cluster-central.conf:/nats-server.conf"
- "./data/n3-central:/data"
- "./configs/cluster-central.conf:/nats/conf/nats-server.conf"
ports:
- 10005:4222
- 10105:7422
n1.west.example.net:
container_name: n1-west
image: nats
image: synadia/nats-server:nightly-main
dns_search: example.net
environment:
GATEWAY: c1
NAME: n1-west
ADVERTISE: localhost:10006
REGION: region:west
networks:
- nats-cluster1
- shared
volumes:
- "./configs/cluster-west.conf:/nats-server.conf"
- "./data/n1-west:/data"
- "./configs/cluster-west.conf:/nats/conf/nats-server.conf"
ports:
- 10006:4222
- 10106:7422
n2.west.example.net:
container_name: n2-west
image: nats
image: synadia/nats-server:nightly-main
dns_search: example.net
environment:
GATEWAY: c1
NAME: n2-west
ADVERTISE: localhost:10007
REGION: region:west
networks:
- nats-cluster1
- shared
volumes:
- "./configs/cluster-west.conf:/nats-server.conf"
- "./data/n2-west:/data"
- "./configs/cluster-west.conf:/nats/conf/nats-server.conf"
ports:
- 10007:4222
- 10107:7422
n3.west.example.net:
container_name: n3-west
image: nats
image: synadia/nats-server:nightly-main
dns_search: example.net
environment:
GATEWAY: c1
NAME: n3-west
ADVERTISE: localhost:10008
REGION: region:west
networks:
- nats-cluster1
- shared
volumes:
- "./configs/cluster-west.conf:/nats-server.conf"
- "./data/n3-west:/data"
- "./configs/cluster-west.conf:/nats/conf/nats-server.conf"
ports:
- 10008:4222
- 10108:7422
Expand All @@ -177,9 +141,3 @@ services:
- n1.central.example.net
- n2.central.example.net
- n3.central.example.net
networks:
- shared

networks:
shared: {}
nats-cluster1: {}
25 changes: 21 additions & 4 deletions examples/topologies/multi-region/cli/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ set -euo pipefail

sleep 3

# Save a few contexts.
nats context save east-sys \
--server nats://n1.east.example.net:4222 \
--user system \
--password secret

nats context save east \
--server nats://n1.east.example.net:4222 \
--user one \
Expand All @@ -19,10 +25,17 @@ nats context save central \
--user one \
--password secret

# Report the servers.
nats --context east-sys server list

nats --context east stream add ORDERS_EAST --tag region:east --replicas 3 --subjects js.in.orders_east --defaults
nats --context west stream add ORDERS_WEST --tag region:west --replicas 3 --subjects js.in.orders_west --defaults
nats --context central stream add ORDERS_CENTRAL --tag region:central --replicas 3 --subjects js.in.orders_central --defaults

# Creating a region-local stream requires setting a tag for the desired region.
nats --context east stream add --config /app/ORDERS_EAST.json
nats --context west stream add --config /app/ORDERS_WEST.json
nats --context central stream add --config /app/ORDERS_CENTRAL.json
nats --context east stream edit ORDERS_EAST --force --config /app/ORDERS_EAST.json
nats --context west stream edit ORDERS_WEST --force --config /app/ORDERS_WEST.json
nats --context central stream edit ORDERS_CENTRAL --force --config /app/ORDERS_CENTRAL.json

# Creating a global stream involves ommitting the --tag option.
nats --context east stream add --config /app/GLOBAL.json
Expand All @@ -32,8 +45,8 @@ nats --context east stream report

# Publish a message from a client in each region.
nats --context east req js.in.orders 1
nats --context west req js.in.orders 1
nats --context central req js.in.orders 1
nats --context west req js.in.orders 1

# Publish a message to the global stream.
nats --context east req js.in.global.orders 1
Expand All @@ -42,3 +55,7 @@ sleep 1

# Let's see the stream report again.
nats --context east stream report

nats --context east stream view ORDERS_EAST
nats --context central stream view ORDERS_CENTRAL
nats --context west stream view ORDERS_WEST

1 comment on commit 351f73a

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for nats-by-example ready!

✅ Preview
https://nats-by-example-c5imeq9j1-connecteverything.vercel.app

Built with commit 351f73a.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.