easypubsub package
proxy module
- class easypubsub.proxy.Proxy(publishers_address: str, subscribers_address: str)
The EasyPubSub Proxy acts as an intermediary between Publishers and Subscribers.
Example
>>> from easypubsub.proxy import Proxy >>> proxy = Proxy("tcp://localhost:5555", "tcp://localhost:5556") >>> proxy.launch() ... >>> proxy.stop()
- launch() None
Launch the Proxy.
This method will launch the Proxy in a separate thread, and return immediately. To stop the Proxy, call the
Proxy.stop()
method.
publisher module
- class easypubsub.publisher.Publisher(name: str, proxy_publishers_address: str, default_topic: str = '')
The EasyPubSub Publisher provides an interface to publish messages to a topic.
- name
The name of the publisher. This will be used as a prefix to all topics used by this publisher.
- Type
- default_topic
The default topic to use when publishing messages. By default, it uses “” (empty string), which means that the messages will be published using
name
as the topic .- Type
Example
>>> from easypubsub.publisher import Publisher >>> publisher = Publisher("my_publisher", "tcp://127.0.0.1:5555") >>> publisher.publish("Hello world!") This messsage will be published to the topic "my_publisher" >>> publisher.publish("Hello again, world.", "my_topic") This message will be published to the topic "my_publisher.my_topic"
subscriber module
- class easypubsub.subscriber.Subscriber(name: str, proxy_subscribers_address: str, topics: Union[str, List[str]] = '', receive_timeout: float = 0.1)
The EasyPubSub Subscriber provides an interface to subscribe to one or more topics.
- topics
The topics to subscribe to. If not specified, the subscriber will subscribe to all topics. If specified, it can be a string or a list of strings.
Example
>>> from easypubsub.subscriber import Subscriber >>> subscriber = Subscriber("my_subscriber", "tcp://127.0.0.1:5556") >>> subscriber.receive() [("my_publisher", "Hello world!"), ("my_publisher.my_topic", "Hello again, world.")]
- receive() List[Tuple[str, Any]]
Receive one or more messages from the subscriptions.
- Returns
A list of tuples, each containing the topic and the message.
- Return type
List[Tuple[str, Any]]
Example
>>> subscriber.receive() [("my_publisher", "Hello world!"), ("my_publisher.my_topic", "Hello again, world.")]