Skip to content

Commit abfbab7

Browse files
authored
Merge pull request #26 from compas-dev/zenoh
Add support for Zenoh transport
2 parents b9dd011 + 4ffabf0 commit abfbab7

18 files changed

Lines changed: 3554 additions & 141 deletions

.github/copilot-instructions.md

Lines changed: 0 additions & 119 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ jobs:
3131
if: "!contains(github.event.pull_request.labels.*.name, 'docs-only')"
3232
runs-on: 'ubuntu-latest'
3333
steps:
34-
- name: Set up docker container
34+
- name: Set up docker containers
3535
run: |
3636
docker run -d --name nanomq -p 1883:1883 -p 8083:8083 -p 8883:8883 emqx/nanomq:latest
37+
docker run -d --name zenoh --init -p 7447:7447/tcp -p 8000:8000/tcp eclipse/zenoh
3738
docker ps -a
3839
- uses: compas-dev/compas-actions.build@v4
3940
with:
@@ -49,6 +50,7 @@ jobs:
4950
- name: Tear down docker container
5051
run: |
5152
docker rm -f nanomq
53+
docker rm -f zenoh
5254
5355
build-cpython-components:
5456
runs-on: windows-latest

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Add support for Zenoh transport protocol.
13+
1214
### Changed
1315

1416
### Removed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ Or using `conda`:
4444
* Publisher/subscriber communication model (N-to-N communication)
4545
* In-process events
4646
* MQTT support
47+
* Zenoh support
4748
* Extensible codec system for message serialization (JSON, Protocol Buffers)
4849

4950
## Examples
@@ -87,6 +88,25 @@ for i in range(10):
8788
This example shows how to send and receive from a single script, but
8889
running publishers and subscribers on different scripts, different processes, or even different computers will work the exact same way.
8990

91+
### Zenoh
92+
93+
Apache Zenoh is a pub/sub/query protocol. In many ways, it is similar to MQTT but with some additional features and optimizations. COMPAS EVE also supports Zenoh as a transport protocol with an identical API to MQTT:
94+
95+
```python
96+
import compas_eve as eve
97+
from compas_eve.zenoh import ZenohTransport
98+
99+
tx = ZenohTransport()
100+
eve.set_default_transport(tx)
101+
102+
pub = eve.Publisher("/hello_world")
103+
sub = eve.EchoSubscriber("/hello_world")
104+
sub.subscribe()
105+
106+
for i in range(10):
107+
pub.publish(dict(text=f"Hello World {i}"))
108+
```
109+
90110
### Using different codecs
91111

92112
By default, COMPAS EVE uses JSON for message serialization. However, you can use different codecs for more efficient serialization:

docs/api.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ API Reference
99
api/compas_eve.codecs
1010
api/compas_eve.memory
1111
api/compas_eve.mqtt
12+
api/compas_eve.zenoh
1213
api/compas_eve.ghpython
1314

docs/api/compas_eve.zenoh.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
.. automodule:: compas_eve.zenoh
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import time
2+
3+
from compas_eve import Publisher
4+
from compas_eve import Topic
5+
from compas_eve.zenoh import ZenohTransport
6+
7+
topic = Topic("/hello/zenoh")
8+
tx = ZenohTransport()
9+
10+
publisher = Publisher(topic, transport=tx)
11+
12+
for i in range(20):
13+
msg = dict(text=f"Hello world #{i} over Zenoh")
14+
print(f"Publishing message: {msg}")
15+
publisher.publish(msg)
16+
time.sleep(1)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import time
2+
3+
from compas_eve import Subscriber
4+
from compas_eve import Topic
5+
from compas_eve.zenoh import ZenohTransport
6+
7+
topic = Topic("/hello/zenoh")
8+
tx = ZenohTransport()
9+
10+
subcriber = Subscriber(topic, callback=lambda msg: print(f"Received message: {msg}"), transport=tx)
11+
subcriber.subscribe()
12+
13+
print("Waiting for messages, press CTRL+C to cancel")
14+
try:
15+
while True:
16+
time.sleep(1)
17+
finally:
18+
subcriber.unsubscribe()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ classifiers = [
3636
[tool.setuptools.dynamic]
3737
version = { attr = "compas_eve.__version__" }
3838
dependencies = { file = "requirements.txt" }
39-
optional-dependencies = { dev = { file = "requirements-dev.txt" } }
39+
optional-dependencies = { dev = { file = "requirements-dev.txt" }, zenoh = { file = "requirements-zenoh.txt" } }
4040

4141
[project.entry-points.'compas_pb.plugins']
4242
serializers = 'compas_eve.codecs.conversions'

requirements-zenoh.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
eclipse-zenoh

0 commit comments

Comments
 (0)