Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 0 additions & 119 deletions .github/copilot-instructions.md

This file was deleted.

4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ jobs:
if: "!contains(github.event.pull_request.labels.*.name, 'docs-only')"
runs-on: 'ubuntu-latest'
steps:
- name: Set up docker container
- name: Set up docker containers
run: |
docker run -d --name nanomq -p 1883:1883 -p 8083:8083 -p 8883:8883 emqx/nanomq:latest
docker run -d --name zenoh --init -p 7447:7447/tcp -p 8000:8000/tcp eclipse/zenoh
docker ps -a
- uses: compas-dev/compas-actions.build@v4
with:
Expand All @@ -49,6 +50,7 @@ jobs:
- name: Tear down docker container
run: |
docker rm -f nanomq
docker rm -f zenoh

build-cpython-components:
runs-on: windows-latest
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

* Add support for Zenoh transport protocol.

### Changed

### Removed
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Or using `conda`:
* Publisher/subscriber communication model (N-to-N communication)
* In-process events
* MQTT support
* Zenoh support
* Extensible codec system for message serialization (JSON, Protocol Buffers)

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

### Zenoh

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:

```python
import compas_eve as eve
from compas_eve.zenoh import ZenohTransport

tx = ZenohTransport()
eve.set_default_transport(tx)

pub = eve.Publisher("/hello_world")
sub = eve.EchoSubscriber("/hello_world")
sub.subscribe()

for i in range(10):
pub.publish(dict(text=f"Hello World {i}"))
```

### Using different codecs

By default, COMPAS EVE uses JSON for message serialization. However, you can use different codecs for more efficient serialization:
Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ API Reference
api/compas_eve.codecs
api/compas_eve.memory
api/compas_eve.mqtt
api/compas_eve.zenoh
api/compas_eve.ghpython

2 changes: 2 additions & 0 deletions docs/api/compas_eve.zenoh.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

.. automodule:: compas_eve.zenoh
16 changes: 16 additions & 0 deletions docs/examples/05_zenoh_distributed_world_pub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import time

from compas_eve import Publisher
from compas_eve import Topic
from compas_eve.zenoh import ZenohTransport

topic = Topic("/hello/zenoh")
tx = ZenohTransport()

publisher = Publisher(topic, transport=tx)

for i in range(20):
msg = dict(text=f"Hello world #{i} over Zenoh")
print(f"Publishing message: {msg}")
publisher.publish(msg)
time.sleep(1)
18 changes: 18 additions & 0 deletions docs/examples/05_zenoh_distributed_world_sub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import time

from compas_eve import Subscriber
from compas_eve import Topic
from compas_eve.zenoh import ZenohTransport

topic = Topic("/hello/zenoh")
tx = ZenohTransport()

subcriber = Subscriber(topic, callback=lambda msg: print(f"Received message: {msg}"), transport=tx)
subcriber.subscribe()

print("Waiting for messages, press CTRL+C to cancel")
try:
while True:
time.sleep(1)
finally:
subcriber.unsubscribe()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ classifiers = [
[tool.setuptools.dynamic]
version = { attr = "compas_eve.__version__" }
dependencies = { file = "requirements.txt" }
optional-dependencies = { dev = { file = "requirements-dev.txt" } }
optional-dependencies = { dev = { file = "requirements-dev.txt" }, zenoh = { file = "requirements-zenoh.txt" } }

[project.entry-points.'compas_pb.plugins']
serializers = 'compas_eve.codecs.conversions'
Expand Down
1 change: 1 addition & 0 deletions requirements-zenoh.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eclipse-zenoh
37 changes: 37 additions & 0 deletions src/compas_eve/ghpython/components/Ce_ZenohConnect/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# r: compas_eve>=2.1.1
"""
Initialize a Zenoh transport.
"""

from threading import Event

import Grasshopper
from compas_ghpython import create_id
from scriptcontext import sticky as st

from compas_eve.zenoh import ZenohTransport


class ZenohConnectComponent(Grasshopper.Kernel.GH_ScriptInstance):
def RunScript(self, connect: bool):
zenoh_transport = None

key = create_id(ghenv.Component, "zenoh_transport") # noqa: F821
zenoh_transport = st.get(key, None)

if zenoh_transport:
st[key].close()

if connect:
event = Event()
transport = ZenohTransport()
transport.on_ready(event.set)

if not event.wait(5):
raise Exception("Failed to initialize Zenoh router transport.")

st[key] = transport

zenoh_transport = st.get(key, None)
is_connected = zenoh_transport._is_connected if zenoh_transport else False
return (zenoh_transport, is_connected)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions src/compas_eve/ghpython/components/Ce_ZenohConnect/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Zenoh Transport",
"nickname": "Zenoh",
"category": "COMPAS EVE",
"subcategory": "Events",
"description": "Initialize a Zenoh transport.",
"exposure": 2,

"ghpython": {
"isAdvancedMode": true,
"iconDisplay": 2,
"inputParameters": [
{
"name": "connect",
"description": "If True, initializes a Zenoh transport. If False, removes it. Defaults to False.",
"typeHintID": "bool"
}
],
"outputParameters": [
{
"name": "zenoh_transport",
"description": "The Zenoh transport instance."
},
{
"name": "is_connected",
"description": "True if initialization has been processed."
}
]
}
}
22 changes: 22 additions & 0 deletions src/compas_eve/zenoh/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"""
********************************************************************************
compas_eve.zenoh
********************************************************************************

.. currentmodule:: compas_eve.zenoh


Classes
=======

.. autosummary::
:toctree: generated/
:nosignatures:

ZenohTransport

"""

from .zenoh_transport import ZenohTransport

__all__ = ["ZenohTransport"]
Loading
Loading