Skip to content

Commit 348f506

Browse files
committed
Configurable qos_depth
1 parent 80ca469 commit 348f506

4 files changed

Lines changed: 20 additions & 4 deletions

File tree

rosbridge_library/src/rosbridge_library/capabilities/subscribe.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ def __init__(
7676
topic: str,
7777
publish: Callable[[OutgoingMessage[ROSMessageT], int | None, str], None] | None,
7878
node_handle: Node,
79+
qos_depth: int = 10,
7980
) -> None:
8081
"""
8182
Create a subscription.
@@ -92,6 +93,7 @@ def __init__(
9293
self.topic = topic
9394
self.publish = publish
9495
self.node_handle = node_handle
96+
self.subscriber_qos_depth = qos_depth
9597

9698
self.clients = {}
9799

@@ -156,6 +158,7 @@ def subscribe(
156158
self.node_handle,
157159
msg_type=msg_type,
158160
raw=raw,
161+
qos_depth=self.subscriber_qos_depth,
159162
)
160163

161164
def unsubscribe(self, sid: str | None = None) -> None:
@@ -248,9 +251,10 @@ class Subscribe(Capability):
248251
)
249252
unsubscribe_msg_fields = ((True, "topic", str),)
250253

251-
parameter_names = ("topics_glob",)
254+
parameter_names = ("topics_glob", "subscriber_qos_depth")
252255

253256
topics_glob: list[str] | None = None
257+
subscriber_qos_depth: int = 10
254258

255259
def __init__(self, protocol: Protocol) -> None:
256260
# Call superclass constructor
@@ -296,7 +300,7 @@ def subscribe(self, msg: dict[str, Any]) -> None:
296300
client_id = self.protocol.client_id
297301
cb = partial(self.publish, topic)
298302
self._subscriptions[topic] = Subscription(
299-
client_id, topic, cb, self.protocol.node_handle
303+
client_id, topic, cb, self.protocol.node_handle, qos_depth=self.subscriber_qos_depth
300304
)
301305

302306
# Register the subscriber

rosbridge_library/src/rosbridge_library/internal/subscribers.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def __init__(
7777
node_handle: Node,
7878
msg_type: str | None = None,
7979
raw: bool = False,
80+
qos_depth: int = 10,
8081
) -> None:
8182
"""
8283
Register a subscriber on the specified topic.
@@ -135,7 +136,7 @@ def __init__(
135136
# - https://github.com/RobotWebTools/rosbridge_suite/issues/551
136137
# - https://github.com/RobotWebTools/rosbridge_suite/issues/769
137138
qos = QoSProfile(
138-
depth=10,
139+
depth=qos_depth,
139140
durability=DurabilityPolicy.VOLATILE,
140141
reliability=ReliabilityPolicy.BEST_EFFORT,
141142
)
@@ -304,6 +305,7 @@ def subscribe(
304305
node_handle: Node,
305306
msg_type: str | None = None,
306307
raw: bool = False,
308+
qos_depth: int = 10,
307309
) -> None:
308310
"""
309311
Subscribe to a topic.
@@ -316,7 +318,13 @@ def subscribe(
316318
with self._lock:
317319
if topic not in self._subscribers:
318320
self._subscribers[topic] = MultiSubscriber(
319-
topic, client_id, callback, node_handle, msg_type=msg_type, raw=raw
321+
topic,
322+
client_id,
323+
callback,
324+
node_handle,
325+
msg_type=msg_type,
326+
raw=raw,
327+
qos_depth=qos_depth,
320328
)
321329
else:
322330
self._subscribers[topic].subscribe(client_id, callback)

rosbridge_server/launch/rosbridge_websocket_launch.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<arg name="services_glob" default="" />
2828
<arg name="params_glob" default="" />
2929
<arg name="params_timeout" default="5.0" />
30+
<arg name="subscriber_qos_depth" default="10" />
3031

3132
<arg name="respawn" default="false"/>
3233

@@ -53,6 +54,7 @@
5354
<param name="topics_glob" value="$(var topics_glob)"/>
5455
<param name="services_glob" value="$(var services_glob)"/>
5556
<param name="params_glob" value="$(var params_glob)"/>
57+
<param name="subscriber_qos_depth" value="$(var subscriber_qos_depth)"/>
5658
</node>
5759
</group>
5860

@@ -77,6 +79,7 @@
7779
<param name="topics_glob" value="$(var topics_glob)"/>
7880
<param name="services_glob" value="$(var services_glob)"/>
7981
<param name="params_glob" value="$(var params_glob)"/>
82+
<param name="subscriber_qos_depth" value="$(var subscriber_qos_depth)"/>
8083
</node>
8184
</group>
8285

rosbridge_server/scripts/rosbridge_websocket.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@
9090
("call_services_in_new_thread", bool, True, "Call services in a new threads."),
9191
("default_call_service_timeout", float, 5.0, "Default timeout for service calls."),
9292
("send_action_goals_in_new_thread", bool, True, "Send action goals in a new threads."),
93+
("subscriber_qos_depth", int, 10, "Default QoS queue depth for topic subscriptions."),
9394
)
9495

9596

0 commit comments

Comments
 (0)