A package wrap NNG
Project description
omq
Omq is a IPC that uses Nanomsg under the hood. It likes MQTT in some degree.
Concept
nanomsg is a socket library that provides several common communication patterns. It aims to make the networking layer fast, scalable, and easy to use. Implemented in C, it works on a wide range of operating systems with no further dependencies. But its sub-pub mode is not very good for us to use. So, omq bornd. Through omq, you can easily publish and subscribe message like MQTT.
Installation
pip install git+https://cloud.orca-tech.cn:9091/rty813/omq.git
Omq requires python 3.6+ and CMake 3.13+
Usage
Bus
# node1.py
import omq
with omq.Bus() as node:
node.publish('test', 'hello world')
# node2.py
import omq
def on_message(topic, payload):
print(f'{topic} - {payload}')
with omq.Bus() as node:
node.on_message = on_message
node.subscribe(['test', 'test/#'])
node.loop_forever()
REQ/REP
# rep.py
import omq
def handler(topic, payload):
print(topic, payload)
# Handle data...
return 'ok'
with omq.Rep(omq.Addr.MAIN, handler) as node:
node.loop_forever()
# req.py
import omq
res = omq.req(omq.Addr.MAIN, 'test', 'req data')
print(res) # ok
Supernode/Slavenode
# Supernode.py
import omq
count = 0
node = omq.SuperNode()
def on_message(slave_id, payload):
global count
count += 1
if count % 3 == 0:
print(f'send: {slave_id}')
node.publish(slave_id, 'Recv')
print(f'recv: {slave_id} - {payload}')
node.on_message = on_message
node.loop_forever()
# Slave.py
import omq
import time
node = omq.SlaveNode('node1', '127.0.0.1')
def on_message(payload):
print('recv: ' + payload)
node.on_message = on_message
node.loop_start()
while True:
try:
node.publish({'a': time.time(), 'b': 2})
time.sleep(1)
except:
node.close()
break
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file omq-0.5.5.tar.gz.
File metadata
- Download URL: omq-0.5.5.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de548acd256a74646e5271749f2c3a82d6f2cc569df805265b32edade8aa3cc4
|
|
| MD5 |
23ca592ba05c239d856865c717ad9942
|
|
| BLAKE2b-256 |
fe9af6702104788eb5215841ae39ae2c2ea3e07ed3f4e825a22ebd9aae17616c
|
File details
Details for the file omq-0.5.5-py3-none-any.whl.
File metadata
- Download URL: omq-0.5.5-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/51.0.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1eecaa3b67894a58db731c46f1bcd8922aebff313983d72b3b5bc287f28edcf
|
|
| MD5 |
0b21b38382d8514a32e2d1d1c94729f9
|
|
| BLAKE2b-256 |
41da7f0cd24c4e9abc4990697e4fa05e7e2da990442a06cbd0cb36ce1bc124ea
|