Skip to content

Commit f01d019

Browse files
authored
PubSub: use channel definition as prefix if defined, update docs (#1196)
1 parent aa9d92f commit f01d019

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

docs/pubsub.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Example directive:
2828
type: mqtt
2929
url: mqtt://localhost:1883
3030
channel: messages/a/data # optional
31+
show_link: false # default true
3132
3233
HTTP
3334
----
@@ -41,6 +42,7 @@ Example directive:
4142
type: http
4243
url: https://ntfy.sh
4344
channel: messages-a-data # optional
45+
show_link: true # default true
4446
4547
.. note::
4648

@@ -51,6 +53,8 @@ Example directive:
5153

5254
.. note::
5355

54-
If no ``channel`` is defined, the relevant OGC API endpoint is used.
56+
If a ``channel`` is defined, it is used as a prefix to the relevant OGC API endpoint is used.
57+
58+
If a ``channel`` is not defined, only the relevant OGC API endpoint is used.
5559

5660
.. _`OGC API Publish-Subscribe Workflow - Part 1: Core`: https://docs.ogc.org/DRAFTS/25-030.html

pycsw/broker/http.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ def pub(self, channel: str, message: str, qos: int = 1) -> bool:
8787
LOGGER.debug(f'Publishing to broker {self.broker_safe_url}')
8888
LOGGER.debug(f'Channel: {channel}')
8989
LOGGER.debug(f'Message: {message}')
90+
LOGGER.debug(f'Santizing channel for HTTP')
91+
channel = channel.replace('/', '-')
92+
LOGGER.debug(f'Santized channel: {channel}')
9093

9194
url = f'{self.broker}/{channel}'
9295

pycsw/ogc/pubsub/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ def publish_message(pubsub_client, action: str, collection: str = None,
4848
:returns: `bool` of whether message publishing was successful
4949
"""
5050

51-
channel = pubsub_client.channel or f'collections/{collection}'
51+
if pubsub_client.channel is not None:
52+
channel = f'{pubsub_client.channel}/collections/{collection}'
53+
else:
54+
channel = f'collections/{collection}'
55+
5256
type_ = f'org.ogc.api.collection.item.{action}'
5357

5458
if action in ['create', 'update']:

0 commit comments

Comments
 (0)