Skip to main content

Cross-language systems

This recipe publishes a StringFrame to one MQTT topic. Any Python, C++, or TypeScript implementation can be the publisher or subscriber because the frame envelope and default MessagePack representation are shared.

Common configuration​

Use the same values in every process:

Broker: mqtt://broker.example.com:1883
Topic: magpie/demo/greeting

Give each process a unique MQTT client ID when configuring production connections.

Publish​

from luxai.magpie.frames import StringFrame
from luxai.magpie.transport import MqttConnection, MqttStreamWriter

connection = MqttConnection("mqtt://broker.example.com:1883")
connection.connect()

writer = MqttStreamWriter(connection)
writer.write(
StringFrame(value="hello from Python").to_dict(),
topic="magpie/demo/greeting",
)

writer.close()
connection.disconnect()

Subscribe​

from luxai.magpie.frames import Frame
from luxai.magpie.transport import MqttConnection, MqttStreamReader

connection = MqttConnection("mqtt://broker.example.com:1883")
connection.connect()
reader = MqttStreamReader(connection, topic="magpie/demo/greeting")

raw, topic = reader.read(timeout=10)
frame = Frame.from_dict(raw)
print(topic, frame.value)

Add RPC​

For cross-language RPC, load the same JSON method schema on both sides. A C++ McpSchema server can be called by Python FastMCP or the TypeScript MCP SDK; a Python schema responder can be called from C++ or TypeScript through the corresponding schema-aware requester.

Keep one contract file, test it against every language, and avoid redefining method shapes independently in several repositories.

Integration-test checklist​

  • Each language can deserialize every frame type the deployment uses.
  • Integer ranges, byte arrays, image metadata, and timestamps survive a round trip.
  • Topic and service naming is identical.
  • Timeouts produce the expected language-specific exceptions.
  • JSON-RPC error codes remain stable.
  • WebRTC peers agree on signaling, media-channel settings, and codecs.
  • Mixed package versions are pinned and tested together before release.