Skip to content

compas_eve.memory ¤

Classes¤

InMemoryTransport ¤

InMemoryTransport(codec: MessageCodec | None = None, *args, **kwargs)

In-Memory transport is ideal for simple single-process apps and testing.

It will only distribute messages within the same process, not across different processes.

Parameters:

  • codec (MessageCodec | None, default: None ) –

    The codec to use for encoding and decoding messages. If not provided, defaults to JsonMessageCodec.

Functions¤

advertise ¤
advertise(topic: Topic)

Announce this code will publish messages to the specified topic.

This call has no effect on the in-memory transport.

on_ready ¤
on_ready(callback: Callable)

In-memory transport is always ready, it will immediately trigger the callback.

publish ¤
publish(topic: Topic, message: Message)

Publish a message to a topic.

Parameters:

  • topic (Topic) –

    Instance of the topic to publish to.

  • message (Message) –

    Instance of the message to publish.

subscribe ¤
subscribe(topic: Topic, callback: Callable) -> str

Subscribe to a topic.

Every time a new message is received on the topic, the callback will be invoked.

Parameters:

  • topic (Topic) –

    Instance of the topic to subscribe to.

  • callback (Callable) –

    Callback to invoke whenever a new message arrives. The callback should receive only one msg argument, e.g. lambda msg: print(msg).

Returns:

  • str

    Returns an identifier of the subscription.

unadvertise ¤
unadvertise(topic: Topic)

Announce that this code will stop publishing messages to the specified topic.

This call has no effect on the in-memory transport.

unsubscribe ¤
unsubscribe(topic: Topic)

Unsubscribe from the specified topic.

Parameters:

  • topic (Topic) –

    Instance of the topic to unsubscribe from.

unsubscribe_by_id ¤
unsubscribe_by_id(subscribe_id: str)

Unsubscribe from the specified topic based on the subscription id.