Zero Message is a lightweight ROS-like pub-sub tool for Python 3.4+.
- Provides a wrapper around ZeroMQ socket.
- Communicate between any Python program using publisher-subscriber protocol
You need zeromq
installed on your system. Refer to the official guide. For your convenience, here's some common ones:
# Debian-based
sudo apt-get install libzmq3-dev
# RHEL-based
sudo yum install libzmq3-devel
# Mac
brew install zmq
Then you can install this library
pip install zeromessage
Refer to the /examples
:
# listener.py
import asyncio
from zeromessage import EnvelopSocket
socket = EnvelopSocket.as_subscriber()
def doSomething(msg):
print(msg)
subscribe_coroutine = socket.subscribe('test', doSomething)
asyncio.get_event_loop().run_until_complete(subscribe_coroutine())
# talker.py
import time
from zeromessage import EnvelopSocket
socket = EnvelopSocket.as_publisher()
while True:
socket.publish('test', {
'data': [1, 2, 3]
})
time.sleep(1)
A rostopic
like tool is provided.
zerotopic echo -- --help
The document is currently broken. In the mean time you can just take a look at the well-documented source code.