SPADE PubSub¶

PubSub: publish-subscribe communication for SPADE agents. Agents publish items in nodes of an XMPP PubSub service, and the agents subscribed to a node are notified of every new item.
Key features¶
-
One to many
A publisher does not need to know who listens: every agent subscribed to a node receives the items published in it, and agents subscribe and unsubscribe at any time.
-
Nodes
Create and delete nodes, list the nodes of a service and their subscribers, and purge their items.
-
Items
Publish text or any XML element, read the items stored in a node, and retract them.
-
Notifications
Register a callback and your agent is notified as soon as an item is published or retracted.
-
Standard XMPP
Based on XEP-0060: it works with the XMPP server built into SPADE and with servers such as Prosody, ejabberd or Openfire.
-
A SPADE plugin
Add
PubSubMixinto your agent class and useself.pubsub, fromsetup()or from any behaviour.
In a nutshell¶
from spade.agent import Agent
from spade_pubsub import PubSubMixin
class NewsAgent(PubSubMixin, Agent):
async def setup(self):
await self.pubsub.create("pubsub.localhost", "news")
await self.pubsub.publish("pubsub.localhost", "news", "Hello, subscribers!")
The quick start shows a complete program with a publisher and a subscriber.