{"result":{"depiction_url":null,"edges":{"subject":{"objects":[{"created":"2026-09-30T09:11:22Z","object_id":{"id":2555,"is_a":["categorization","keyword","keyword_information_type"],"name":"zotonic_topic_reference","title":"Reference","uri":"https:\/\/zotonic.com\/id\/2555"},"seq":1},{"created":"2026-09-30T09:11:22Z","object_id":{"id":2563,"is_a":["categorization","keyword","keyword_audience"],"name":"zotonic_topic_frontend_developer","title":"Frontend developer","uri":"https:\/\/zotonic.com\/id\/2563"},"seq":2},{"created":"2026-09-30T09:11:22Z","object_id":{"id":2655,"is_a":["categorization","keyword","keyword_task"],"name":"zotonic_topic_publish_and_subscribe","title":"Publish and subscribe","uri":"https:\/\/zotonic.com\/id\/2655"},"seq":3},{"created":"2026-09-30T09:11:22Z","object_id":{"id":2673,"is_a":["categorization","keyword","keyword_technology"],"name":"zotonic_topic_javascript","title":"JavaScript","uri":"https:\/\/zotonic.com\/id\/2673"},"seq":4},{"created":"2026-09-30T09:11:22Z","object_id":{"id":2716,"is_a":["categorization","keyword","keyword_architecture"],"name":"zotonic_topic_message_broker","title":"Message broker","uri":"https:\/\/zotonic.com\/id\/2716"},"seq":5},{"created":"2026-09-30T09:11:22Z","object_id":{"id":2718,"is_a":["categorization","keyword","keyword_technology"],"name":"zotonic_topic_cotonic","title":"Cotonic","uri":"https:\/\/zotonic.com\/id\/2718"},"seq":6}],"predicate":{"id":308,"is_a":["meta","predicate"],"name":"subject","title":{"_type":"trans","tr":{"en":"Keyword"}},"uri":"http:\/\/purl.org\/dc\/elements\/1.1\/subject"}}},"id":2727,"is_a":["text","documentation","reference","cotonic_reference"],"links":[{"rel":"self","target":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/2727"},{"rel":"hub","target":"https:\/\/zotonic.com\/.zotonic\/websub"}],"medium":null,"medium_url":null,"name":"doc_cotonic_cotonic_broker","page_url":{"en":"https:\/\/zotonic.com\/cotonic\/cotonic_broker","x-default":"https:\/\/zotonic.com\/cotonic\/cotonic_broker"},"preview_url":null,"resource":{"version":16,"pivot_location_lat":null,"title":"cotonic.broker","is_authoritative":true,"body":"<a name=\"cotonic.broker\"><\/a>\n\n            <p>\n            The broker module handles all local publish subscribe connections. The subscriptions\n            are stored in a trie datastructure allowing quick action. They are available in the\n            <tt>cotonic.broker<\/tt> namespace.\n            <\/p>\n\n            <!-- find_subscriptions_below -->\n            <a name=\"cotonic.broker.find_subscriptions_below\"><\/a><h2>find_subscriptions_below <code>cotonic.broker.find_subscriptions_below(topic)<\/code><\/h2><p>\n            Find all subscribers below a certain topic. Used by the bridge to collect all subscriptions\n            after a session restart. Returns a list with subscriptions.\n            <\/p>\n            <pre>\ncotonic.broker.find_subscriptions_below(&quot;truck&quot;);\n=&gt; [\n  {type: &quot;page&quot;, wid: 0, callback: function, sub: Object, topic: &quot;truck\/+\/speed&quot;}\n  {type: &quot;page&quot;, wid: 0, callback: function, sub: Object, topic: &quot;#&quot;}]<\/pre>\n\n            <!-- match -->\n            <a name=\"cotonic.broker.match\"><\/a><h2>match <code>cotonic.broker.match(topic)<\/code><\/h2><p>\n            Collect all subscribers which match the topic. Returns a list with subscriptions.\n            <\/p>\n            <pre>\ncotonic.broker.subscribe(&quot;truck\/+\/speed&quot;, function(msg) {\n    console.log(&quot;Some trucks speed&quot;, msg);\n});\ncotonic.broker.subscribe(&quot;truck\/#&quot;, function(msg) {\n    console.log(&quot;Some info of a truck&quot;, msg);\n});\ncotonic.broker.subscribe(&quot;truck\/02\/speed&quot;, function(msg) {\n    console.log(&quot;Speed of truck 2&quot;, msg);\n})\n\ncotonic.broker.match(&quot;truck\/01\/speed&quot;);\n=&gt; [Object, Object] \/\/ Returns two subscriptions, truck\/+\/speed, and truck\/#\ncotonic.broker.match(&quot;truck\/01\/speed&quot;)[0]\n=&gt; {type: &quot;page&quot;, wid: 0, callback: function, sub: Object, topic: &quot;truck\/+\/speed&quot;}\ncotonic.broker.match(&quot;truck\/02\/speed&quot;);\n=&gt; [Object, Object, Object] \/\/ Returns all subscriptions\ncotonic.broker.match(&quot;boat\/02\/speed&quot;);\n=&gt; [] \/\/ Has no subscribers<\/pre>\n\n            <!-- publish -->\n            <a name=\"cotonic.broker.publish\"><\/a><h2>publish <code>cotonic.broker.publish(topic, payload, [options])<\/code><\/h2><p>\n            Publish the message <tt>payload<\/tt> on a topic. The possible <tt>options<\/tt> are:\n            <\/p>\n            <dl>\n                <dt><tt>qos<\/tt><\/dt>\n                <dd>Quality of service. Can be 0, 1, or 2. 0 means at most once, 1 at least once, and 2 exactly once.<\/dd>\n                <dt><tt>retain<\/tt><\/dt>\n                <dd>When retain is true, the last message sent will be stored, and delivered immediately when\n                a new client subscribes to the topic.<\/dd>\n                <dt><tt>properties<\/tt><\/dt>\n                <dd>Extra properties which can be attached to the message<\/dd>\n            <\/dl>\n            <pre>\ncotonic.broker.publish(&quot;truck\/001\/temperature&quot;, 88);\n=&gt; All subscribers receive the message 88 on the topic.\ncotonic.broker.publish(&quot;truck\/001\/speed&quot;, 74, {retain: true});\n=&gt; All subscribers receive the message 74. New subscribers will immediately receive 74.\n            <\/pre>\n\n            <!-- subscribe -->\n            <a name=\"cotonic.broker.subscribe\"><\/a><h2>subscribe <code>cotonic.broker.subscribe(topics, callback, [options])<\/code><\/h2><p>\n            Subscribe to topics. Argument <tt>topics<\/tt> can either be a single topic, or a list of topics.\n            The function <tt>callback<\/tt> will be called when a message which matches\n            one of the topics is published. It is a function is called with two arguments, <tt>message<\/tt>\n            and <tt>info<\/tt>. Argument <tt>message<\/tt> is the received mqtt message, and <tt>info<\/tt>\n            the returned information object returned by <a href=\"\/id\/doc_cotonic_cotonic_mqtt#cotonic.mqtt.extract\">extract<\/a>.\n            This makes it possible to easily extract information from the topic.\n            Parameter <tt>options<\/tt> can be\n            <\/p>\n            <dl>\n                <dt><tt>wid<\/tt><\/dt>\n                <dd>The worker if used for making the scription. Can be used to differentiate\n                subscriptions from different components on the page. Defaults to: <tt>0<\/tt><\/dd>\n\n                <dt><tt>qos<\/tt><\/dt>\n                <dd>The quality-of-service of the subscription. Defaults to: <tt>0<\/tt><\/dd>\n\n                <dt><tt>retain_handling<\/tt><\/dt>\n                <dd>[todo]<\/dd>\n\n                <dt><tt>retain_as_published<\/tt><\/dt>\n                <dd>[todo]<\/dd>\n\n                <dt><tt>no_local<\/tt><\/dt>\n                <dd>[todo]<\/dd>\n\n                <dt><tt>properties<\/tt><\/dt>\n                <dd>[todo]<\/dd>\n            <\/dl>\n            <pre>\ncotonic.broker.subscribe(&quot;truck\/+truck_id\/speed&quot;,\n    function(msg, info) {\n         console.log(&quot;Truck&quot;, info.truckid, &quot;speed:&quot;, msg.payload);\n    },\n    {wid: &quot;example&quot;});\n=&gt; The function will now be called when a truck publishes its speed.<\/pre>\n\n            <!-- unsubscribe -->\n            <a name=\"cotonic.broker.unsubscribe\"><\/a><h2>unsubscribe <code>cotonic.broker.unsubscribe(topics, [options])<\/code><\/h2><p>\n            Unsubscribe from the topics. The parameter <tt>topics<\/tt> can be a single topic as a string,\n            or a list of topics. The optional parameter <tt>options<\/tt> is an object which has the following\n            properties.\n            <\/p>\n            <dl>\n                <dt>wid<\/dt>\n                <dd>The worker id from which to unsubscribe from. Defaults to: <tt>0<\/tt><\/dd>\n            <\/dl>\n            <pre>\ncotonic.broker.unsubscribe(&quot;truck\/+truck_id\/speed&quot;,\n                           {wid: &quot;example&quot;});\n=&gt; The subscriptions for topic &quot;truck\/+truck_id\/speed&quot; for worker &quot;example&quot; will not be called anymore.\n<\/pre>\n\n            <!-- call -->\n            <a name=\"cotonic.broker.call\"><\/a><h2>call <code>cotonic.broker.call(topic, payload, [options])<\/code><\/h2><p>\n            Call is a special kind of publish where the publisher expects an answer back. The <tt>payload<\/tt>\n            will be published on <tt>topic<\/tt> using the <tt>options<\/tt> as described in\n            <a href=\"\/id\/doc_cotonic_cotonic_broker#cotonic.broker.publish\">publish<\/a>.\n            The caller will be temporarily subscribed to a reply topic. When an answer is received on this\n            reply topic, the returned promise will be resolved. When no answer is received, the promise will\n            be rejected with a reason.\n            The option parameter can have the following extra options:\n            <\/p>\n            <dl>\n                <dt><tt>timeout<\/tt><\/dt>\n                <dd>\n                    The timeout in milliseconds to use before rejecting\n                    the returned promise.  Default: <tt>15000<\/tt>, or\n                    15 seconds.\n                <\/dd>\n            <\/dl>\n            <pre>\ncotonic.broker.call(&quot;model\/localStorage\/get\/username&quot;, {}, {timeout: 1000})\n.then(function(username) {\n    console.log(&quot;The username is:&quot;, username&quot;);\n})\n.catch(function(e) {\n    console.log(&quot;Could not get username within 1 second.&quot;, e);\n});<\/pre>\n\n            ","slug":"cotonic.broker","is_protected":false,"visible_for":0,"tz":"UTC","language":["en"],"doc_source_hash":"b91fe5574265689e0f1573a0abc70f371fb6f1625371a2c0fb242762726b8f13","is_featured":false,"content_group_id":{"id":2551,"is_a":["meta","content_group"],"name":"content_group_imported_docs","title":"Imported documentation","uri":"https:\/\/zotonic.com\/id\/content_group_imported_docs"},"category_id":{"id":2722,"is_a":["meta","category"],"name":"cotonic_reference","title":"Cotonic","uri":"https:\/\/zotonic.com\/id\/cotonic_reference"},"doc_source_path":"index.html","publication_start":"2026-09-30T09:11:22Z","page_path":"\/cotonic\/cotonic_broker","github_url":"https:\/\/github.com\/cotonic\/cotonic\/blob\/master\/index.html","pivot_location_lng":null,"doc_source_kind":"cotonic","name":"doc_cotonic_cotonic_broker","is_unfindable":false,"is_published":true,"pivot_geocode":null,"created":"2026-09-30T09:11:22Z","uri":null,"doc_source_anchor":"cotonic.broker","doc_status":"current","is_dependent":false,"publication_end":"9999-06-01T00:00:00Z","modifier_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"privacy":0,"doc_source_commit":"f88cc928b997d10f7f19e6bd0ede80e1c8c619bc","creator_id":{"id":1,"is_a":["person"],"name":"administrator","title":"Site Administrator","uri":"https:\/\/zotonic.com\/id\/1"},"modified":"2026-09-30T10:06:59Z","title_slug":"cotonic.broker"},"uri":"https:\/\/zotonic.com\/id\/2727","uri_template":"https:\/\/zotonic.com\/id\/:id","websub":{"hub":"https:\/\/zotonic.com\/.zotonic\/websub","topic":"https:\/\/zotonic.com\/.zotonic\/websub\/topic\/2727"}},"status":"ok"}