Getting Started¶
1. Start three clusters¶
cd src/mesh
deploy/scripts/up.sh
Each cluster has a NATS server, a leaf node, a signing agent and a bridge. They share only a relay and a DHT. Cluster c keeps its key in a wallet.
2. Open a Python shell¶
bash -c '. deploy/scripts/lib.sh; load_env; compose --profile test run --rm smoke python -m asyncio'
This container can reach all three clusters, which is convenient for trying things out.
3. Serve a subject in cluster b¶
import os
from mesh_sdk import Mesh
T = os.environ["AGENT_TOKEN"]
b = Mesh("cluster-b", "nats://nats-b:4222", "http://bridge-b:8080", T)
async def hello(data, msg): return b"hello " + data
await b.advertise("cluster-b.hello", hello, inter_cluster=True, services=["greeting"])
4. Call it from cluster a¶
a = Mesh("cluster-a", "nats://nats-a:4222", "http://bridge-a:8080", T)
await a.send_recv("cluster-b.hello", b"mesh", timeout=60)
b'hello mesh'
The first call waits until the bridges found each other and connected.
5. Stop¶
Leave the shell, then:
deploy/scripts/down.sh