Skip to content

Transports

A transport implements ITransportAdaptersubscribe, publish, plus optional extensions (invoke, getWireTopicInfo, etc.). The SDK ships three: an in-process broker for tests and demos, a Node-side NATS adapter for runners and headless tools, and a browser-side NATS adapter that opens a WebSocket and refreshes JWTs.

Pages in this section

PageWhat you'll learn
In-memory transportInMemoryBroker + InMemoryTransport — how the in-process bus works, queueing, latency injection.
NATS transportNatsTransport — root-prefix grammar, validation, JSON encoding, the INatsLikeConnection adapter.
Browser transportcreateBrowserNatsTransport — WebSocket connect, JWT refresh, token/user-pass fallbacks.
Transport testingStubbing transports for actor unit tests, real-NATS harness for integration tests.

Picking a transport

SituationUse
Unit test, single-process actor systemInMemoryTransport (with InMemoryBroker).
Production Node-side runtime, supervised by Host ServiceNatsTransport over the bundled NATS sibling (the runner wires it for you).
Browser tab connected to a Host's NATScreateBrowserNatsTransport over /nats-ws.
Federation: actor invokes across rootsFederationTransportAdapter wrapping the underlying transport.

You almost never construct a transport by hand in production code. The runner (Host Service) constructs the right transport and passes it into MatrixRuntime. You construct transports yourself in tests.

Wire format, briefly

All three transports carry MxEnvelope JSON:

json
{ "op": "market.quote", "payload": { "symbol": "TSLA" }, "from": "<sender>", "lamport": 42 }

InMemoryTransport passes the object reference directly — no serialization. NatsTransport encodes/decodes via TextEncoder/TextDecoder + JSON.stringify/JSON.parse. The browser variant uses the same NATS adapter under the hood with a WebSocket connection.

Subject prefixing

NATS-backed transports prepend an authority root to every subject:

<root>.<mount>.$inbox       ← inbox
<root>.<mount>.$events      ← events
<root>.$reply.<corrId>       ← reply

The root is a DNS-style identifier like COM.NIMBLETEC.RICHARD-SANTOMAURO. InMemoryTransport does not prefix — its topicPrefix is the empty string.

getWireTopicInfo(topic) (ITransportAdapter extension) lets a caller inspect what wire subject a logical topic resolves to. Useful for debugging.

Source: projects/matrix-3/packages/core/src/engine/messaging/TopicRouter.ts (subject grammar), projects/matrix-3/packages/core/src/transport/{InMemoryTransport,NatsTransport,createBrowserNatsTransport}.ts (each adapter).