publish-subscribe pattern distributed message sender sending messages from many machines now that we have arrived at clean implementation of the pubsub patternlet' use the ideas we have developed so far to build our own simple message sender for thiswe are going to use the socket package from the python standard library we use xml-rpc to handle the remote connectionsit lets us make calls to remote procedures as if they were part of the local system in order to make our dispatcher work with messageswe need to send dictionaries as parameters rather than as python objectswhich we do the code below illustrates how we do that dispatcher py from xmlrpc client import serverproxy from xmlrpc server import simplexmlrpcserver class dispatcher(simplexmlrpcserver)def __init__(self)self topic_subscribers dict(super(dispatcherself__init__(("localhost" )print("listening on port "self register_function(self subscribe"subscribe"self register_function(self unsubscribe"unsubscribe"self register_function(self unsubscribe_all"unsubscribe_all"self register_function(self send"send"def subscribe(selfsubscribertopic)print('subscribing {to {}format(subscribertopic)self topic_subscribers setdefault(topicset()add(subscriberreturn "okdef unsubscribe(selfsubscribertopic)print('unsubscribing {from {}format(subscribertopic)self topic_subscribers setdefault(topicset()discard(subscriberreturn "okdef unsubscribe_all(selftopic)print('unsubscribing all from {}format(topic)