Requests and Events¶
Request¶
reply = await mesh.send_recv("cluster-b.add", b'{"a": 1, "b": 2}', timeout=30, headers={"Trace": "x"})
Publish¶
await mesh.send("cluster-b.events", b"data")
Agents of every connected cluster can publish on an advertised subject.
Subscribe¶
async def show(data, msg):
print(msg.subject, data)
await mesh.subscribe("cluster-b.events", show)
Each subscriber in each cluster receives an event once. Events are delivered at most once. Subscriptions that were just created may miss events until the bridges know about them.
Receive one message¶
data = await mesh.recv("cluster-b.events", timeout=30)
Wildcards¶
NATS wildcards such as cluster-b.> work for advertised subjects with any NATS client connected to the local server.
Errors¶
| Exception | Meaning |
|---|---|
NotAdvertised |
No trusted cluster advertises the subject |
Unreachable |
The cluster is not connected, nobody serves the subject, or a policy refused the message |
TimeoutError |
No reply in time |
MeshError |
The handler failed, or the call was wrong |