Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Byron Ruth <[email protected]>
  • Loading branch information
bruth committed Nov 4, 2022
1 parent 881727d commit 043c91c
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 0 deletions.
12 changes: 12 additions & 0 deletions examples/use-cases/faux-active-active/cli/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM natsio/nats-box:0.12.0

RUN apk add bash curl

COPY --from=nats:2.9.5 /nats-server /usr/local/bin/

COPY . .

ENTRYPOINT ["bash"]

CMD ["main.sh"]

34 changes: 34 additions & 0 deletions examples/use-cases/faux-active-active/cli/central-edit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "ORDERS-CENTRAL",
"subjects": [
"orders.central.\u003e"
],
"retention": "limits",
"max_consumers": -1,
"max_msgs_per_subject": -1,
"max_msgs": -1,
"max_bytes": -1,
"max_age": 0,
"max_msg_size": -1,
"storage": "file",
"discard": "old",
"num_replicas": 1,
"duplicate_window": 12000000000,
"placement": {
"cluster": "central"
},
"sealed": false,
"deny_delete": false,
"deny_purge": false,
"allow_rollup_hdrs": true,
"sources": [
{
"name": "ORDERS-WEST",
"filter_subject": "orders.west.\u003e"
},
{
"name": "ORDERS-EAST",
"filter_subject": "orders.east.\u003e"
}
]
}
24 changes: 24 additions & 0 deletions examples/use-cases/faux-active-active/cli/central.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "ORDERS-CENTRAL",
"subjects": [
"orders.central.\u003e"
],
"retention": "limits",
"max_consumers": -1,
"max_msgs_per_subject": -1,
"max_msgs": -1,
"max_bytes": -1,
"max_age": 0,
"max_msg_size": -1,
"storage": "file",
"discard": "old",
"num_replicas": 1,
"duplicate_window": 12000000000,
"placement": {
"cluster": "central"
},
"sealed": false,
"deny_delete": false,
"deny_purge": false,
"allow_rollup_hdrs": true
}
40 changes: 40 additions & 0 deletions examples/use-cases/faux-active-active/cli/east-edit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "ORDERS-EAST",
"subjects": [
"orders.east.\u003e"
],
"retention": "limits",
"max_consumers": -1,
"max_msgs_per_subject": -1,
"max_msgs": -1,
"max_bytes": -1,
"max_age": 0,
"max_msg_size": -1,
"storage": "file",
"discard": "old",
"num_replicas": 1,
"duplicate_window": 12000000000,
"placement": {
"cluster": "east"
},
"sealed": false,
"deny_delete": false,
"deny_purge": false,
"allow_rollup_hdrs": true,
"sources": [
{
"name": "ORDERS-WEST",
"filter_subject": "orders.west.\u003e",
"opt_start_seq": 0,
"opt_start_time": "0001-01-01T00:00:00Z",
"external": null
},
{
"name": "ORDERS-CENTRAL",
"filter_subject": "orders.central.\u003e",
"opt_start_seq": 0,
"opt_start_time": "0001-01-01T00:00:00Z",
"external": null
}
]
}
24 changes: 24 additions & 0 deletions examples/use-cases/faux-active-active/cli/east.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "ORDERS-EAST",
"subjects": [
"orders.east.\u003e"
],
"retention": "limits",
"max_consumers": -1,
"max_msgs_per_subject": -1,
"max_msgs": -1,
"max_bytes": -1,
"max_age": 0,
"max_msg_size": -1,
"storage": "file",
"discard": "old",
"num_replicas": 1,
"duplicate_window": 12000000000,
"placement": {
"cluster": "east"
},
"sealed": false,
"deny_delete": false,
"deny_purge": false,
"allow_rollup_hdrs": true
}
161 changes: 161 additions & 0 deletions examples/use-cases/faux-active-active/cli/main.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
#!/bin/sh

set -euo pipefail

# Define the system account to be included by all configurations.
cat <<- EOF > sys.conf
accounts: {
SYS: {
users: [{user: sys, password: sys}]
}
APP: {
jetstream: true
users: [{user: app, password: app}]
}
}
system_account: SYS
EOF

# Create the *east*, *central*, and *west* server configurations.
# A requirement of JetStream is to have a cluster block with routes
# defined, even for single node clusters.
#
# In a production deployment, at least three nodes per cluster
# are recommended which supports creating R3 streams. In this
# test setup, only R1 streams can be created since streams replicas
# do not cross gateway connections.
#
# Similarity, across a supercluster, an odd number of servers must
# exist to support reaching consensus for the meta group leader.
cat <<- EOF > east.conf
port: 4222
http_port: 8222
server_name: n1
include sys.conf
jetstream: {}
cluster: {
name: east,
port: 6222,
routes: [
"nats-route://0.0.0.0:6222"
],
}
gateway: {
name: "east",
port: 7222,
gateways: [
{name: "east", urls: ["nats://0.0.0.0:7222"]},
{name: "central", urls: ["nats://0.0.0.0:7223"]},
{name: "west", urls: ["nats://0.0.0.0:7224"]},
]
}
EOF

cat <<- EOF > central.conf
port: 4223
http_port: 8223
server_name: n2
include sys.conf
jetstream: {}
cluster: {
name: central,
port: 6223,
routes: [
"nats-route://0.0.0.0:6223"
],
}
gateway: {
name: "central",
port: 7223,
gateways: [
{name: "east", urls: ["nats://0.0.0.0:7222"]},
{name: "central", urls: ["nats://0.0.0.0:7223"]},
{name: "west", urls: ["nats://0.0.0.0:7224"]},
]
}
EOF


cat <<- EOF > west.conf
port: 4224
http_port: 8224
server_name: n3
include sys.conf
jetstream: {}
cluster: {
name: west,
port: 6224,
routes: [
"nats-route://0.0.0.0:6224"
],
}
gateway: {
name: "west",
port: 7224,
gateways: [
{name: "east", urls: ["nats://0.0.0.0:7222"]},
{name: "central", urls: ["nats://0.0.0.0:7223"]},
{name: "west", urls: ["nats://0.0.0.0:7224"]},
]
}
EOF


# Start the servers and sleep for a few seconds to startup.
nats-server -c east.conf > /dev/null 2>&1 &
nats-server -c central.conf > /dev/null 2>&1 &
nats-server -c west.conf > /dev/null 2>&1 &

sleep 3


# Wait until the servers are healthy.
curl --fail --silent \
--retry 5 \
--retry-delay 1 \
http://localhost:8222/healthz > /dev/null

curl --fail --silent \
--retry 5 \
--retry-delay 1 \
http://localhost:8223/healthz > /dev/null

curl --fail --silent \
--retry 5 \
--retry-delay 1 \
http://localhost:8224/healthz > /dev/null


# Save a couple NATS CLI contexts for convenience.
nats context save app \
--server "nats://localhost:4222" --user app --password app > /dev/null

nats context select app

# Create a stream in east, west, and central with disjoint
nats stream add --config east.json
nats stream add --config west.json
nats stream add --config central.json

nats stream edit --force --config east-edit.json ORDERS-EAST
nats stream edit --force --config west-edit.json ORDERS-WEST
nats stream edit --force --config central-edit.json ORDERS-CENTRAL

nats req 'orders.east.1' ''
nats req 'orders.west.1' ''
nats req 'orders.central.1' ''

nats stream list
34 changes: 34 additions & 0 deletions examples/use-cases/faux-active-active/cli/west-edit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "ORDERS-WEST",
"subjects": [
"orders.west.\u003e"
],
"retention": "limits",
"max_consumers": -1,
"max_msgs_per_subject": -1,
"max_msgs": -1,
"max_bytes": -1,
"max_age": 0,
"max_msg_size": -1,
"storage": "file",
"discard": "old",
"num_replicas": 1,
"duplicate_window": 12000000000,
"placement": {
"cluster": "west"
},
"sealed": false,
"deny_delete": false,
"deny_purge": false,
"allow_rollup_hdrs": true,
"sources": [
{
"name": "ORDERS-CENTRAL",
"filter_subject": "orders.central.\u003e"
},
{
"name": "ORDERS-EAST",
"filter_subject": "orders.east.\u003e"
}
]
}
24 changes: 24 additions & 0 deletions examples/use-cases/faux-active-active/cli/west.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "ORDERS-WEST",
"subjects": [
"orders.west.\u003e"
],
"retention": "limits",
"max_consumers": -1,
"max_msgs_per_subject": -1,
"max_msgs": -1,
"max_bytes": -1,
"max_age": 0,
"max_msg_size": -1,
"storage": "file",
"discard": "old",
"num_replicas": 1,
"duplicate_window": 12000000000,
"placement": {
"cluster": "west"
},
"sealed": false,
"deny_delete": false,
"deny_purge": false,
"allow_rollup_hdrs": true
}
4 changes: 4 additions & 0 deletions examples/use-cases/faux-active-active/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: '3.9'
services:
app:
image: ${IMAGE_TAG}
2 changes: 2 additions & 0 deletions examples/use-cases/faux-active-active/meta.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
title: Faux active-active with stream sources
description: |-

1 comment on commit 043c91c

@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-agm19xyjk-connecteverything.vercel.app

Built with commit 043c91c.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.