pamoja.loopback

Idiomatic loopback-broker facade.

An in-process broker: publish on one link, receive on another, with no broker process, no network, and no hardware. It is what makes a message flow testable from a unit test rather than only from a deployment.

 1"""Idiomatic loopback-broker facade.
 2
 3An in-process broker: publish on one link, receive on another, with no broker
 4process, no network, and no hardware. It is what makes a message flow testable
 5from a unit test rather than only from a deployment.
 6"""
 7
 8from __future__ import annotations
 9
10from pamoja._native import LoopbackBroker, LoopbackTransport, Message
11
12__all__ = [
13    "LoopbackBroker",
14    "LoopbackTransport",
15    "Message",
16]
class LoopbackBroker:

An in-process broker.

Every transport built from one broker shares its traffic, so a message one publishes reaches the others that subscribed to the topic.

def rung(self, /):

Creates a link to this broker as a transport, for composing into a ladder or a wrapper.

class LoopbackTransport:

One in-process link to a broker.

def connect(self, /):

Marks this link connected so it will carry traffic.

def send(self, /, topic, payload):

Publishes a payload to a topic on the broker.

def subscribe(self, /, topic):

Subscribes this link to a topic.

def recv(self, /):

Waits for the next message on a subscribed topic, or None once closed.

def is_connected(self, /):

Whether this link is connected.

def disconnect(self, /):

Marks this link disconnected, so sends over it fail.

class Message:

A message that arrived on a subscribed topic.

CoAP and the loopback broker both hand back a topic and a payload, so one class serves them rather than a near-identical type per transport.

payload

The raw payload bytes.

topic

The topic it was published to.