@@ -1136,8 +1136,6 @@ finally:
11361136
11371137# 9. Message Broker
11381138
1139- This is under development: please check for updates.
1140-
11411139``` python
11421140from primitives import Broker # broker.py
11431141```
@@ -1148,7 +1146,7 @@ message. This enables one to one, one to many, many to one or many to many
11481146messaging.
11491147
11501148A task subscribes to a topic with an ` agent ` . This is stored by the broker. When
1151- the broker publishes a message, the ` agent ` of each task subscribed to its topic
1149+ the broker publishes a message, every ` agent ` subscribed to the message topic
11521150will be triggered. In the simplest case the ` agent ` is a ` Queue ` instance: the
11531151broker puts the topic and message onto the subscriber's queue for retrieval.
11541152
@@ -1173,18 +1171,20 @@ The `topic` arg is typically a string but may be any hashable object. A
11731171
11741172#### Agent types
11751173
1176- An ` agent ` may be an instance of any of the following:
1174+ An ` agent ` may be an instance of any of the following types. Args refers to any
1175+ arguments passed to the ` agent ` 's' subscription.
11771176
1178- * ` RingbufQueue ` Received messages are queued as a 2-tuple ` (topic, message) ` .
1177+ * ` RingbufQueue ` Received messages are queued as a 2-tuple ` (topic, message) `
1178+ assuming no args.
11791179* ` Queue ` Received messages are queued as a 2-tuple ` (topic, message) ` .
1180- * ` function ` Called when a message is received. Args: topic, message plus any
1181- further args.
1182- * ` bound method ` Called when a message is received. Args: topic, message plus any
1180+ * ` function ` Called when a message is received. Args: ` topic ` , ` message ` plus any
11831181further args.
1184- * ` coroutine ` Converted to a ` task ` when a message is received. Args: topic,
1185- message plus any further args.
1186- * ` bound coroutine ` Converted to a ` task ` when a message is received. Args: topic,
1187- message plus any further args.
1182+ * ` bound method ` Called when a message is received. Args: ` topic ` , ` message `
1183+ plus any further args.
1184+ * ` coroutine ` Converted to a ` task ` when a message is received. Args: ` topic ` ,
1185+ ` message ` plus any further args.
1186+ * ` bound coroutine ` Converted to a ` task ` when a message is received. Args: ` topic ` ,
1187+ ` message ` plus any further args.
11881188* ` user_agent ` Instance of a user class. See user agents below.
11891189* ` Event ` Set when a message is received.
11901190
@@ -1232,7 +1232,8 @@ async def messages(client):
12321232 broker.publish(topic.decode(), msg.decode())
12331233```
12341234Assuming the MQTT client is subscribed to multiple topics, message strings are
1235- directed to individual tasks each supporting one topic.
1235+ directed to agents, each dedicated to handling a topic. An ` agent ` might operate
1236+ an interface or queue the message for a running task.
12361237
12371238The following illustrates a use case for passing args to an ` agent ` (pin nos.
12381239are for Pyoard 1.1).
@@ -1322,14 +1323,15 @@ applications this behaviour is preferable. In general `RingbufQueue` is
13221323preferred as it is optimised for microcontroller use and supports retrieval by
13231324an asynchronous iterator.
13241325
1325- If either queue type is subscribed with args, publications will queued as a
1326- 3-tuple ` (topic, message, (args...)) ` . There is no obvious use case for this.
1326+ If either queue type is subscribed with args, a publication will create a queue
1327+ entry that is a 3-tuple ` (topic, message, (args...)) ` . There is no obvious use
1328+ case for this.
13271329
13281330#### exceptions
13291331
1330- An instance of an ` agent ` objects is owned by a subscribing tasks but is
1331- executed by a publishing task. If a function used as an ` agent ` throws an
1332- exception, the traceback will point to a ` Broker.publish ` call.
1332+ An ` agent ` instance is owned by a subscribing tasks but is executed by a
1333+ publishing task. If a function used as an ` agent ` throws an exception, the
1334+ traceback will point to a ` Broker.publish ` call.
13331335
13341336The ` Broker ` class throws a ` ValueError ` if ` .subscribe ` is called with an
13351337invalid ` agent ` type. There are a number of non-fatal conditions which can occur
0 commit comments