Introduction: pydispatcher 1 2

PyDispatcher provides the Python programmer with a multiple-producer-multiple-consumer signal-registration and routing infrastructure for use in multiple contexts. The mechanism of PyDispatcher started life as a highly rated recipe in the Python Cookbook. The project aims to include various enhancements to the recipe developed during use in various applications. It is primarily maintained by Mike Fletcher. A derivative of the project provides the Django web framework's "signal" system.

Used by Django community

Usage 1

# To set up a function to receive signals:
from pydispatch import dispatcher

SIGNAL = 'my-first-signal'

def handle_event(sender):
    """Simple event handler"""
    print 'Signal was sent by', sender

dispatcher.connect(handle_event, signal=SIGNAL, sender=dispatcher.Any)

# The use of the Any object allows the handler to listen for messages
# from any Sender or to listen to Any message being sent.
# To send messages:
first_sender = object()
second_sender = {}

def main():
    dispatcher.send(signal=SIGNAL, sender=first_sender)
    dispatcher.send(signal=SIGNAL, sender=second_sender)

    # Which causes the following to be printed:

    # Signal was sent by <object object at 0x196a090>
    # Signal was sent by {}


Conda link Docker link Github - pubSubService Github - pubSubClient Pypi link

Python Publish - Subscribe Pattern Implementation:

Step by Step to run PubSub:

Step 1: Pull pubsub image from docker hub & run it:

docker pull hunguyen/pubsub:latest
docker run -d -p 8000:8000 hunguyen/pubsub

Step 2: To run client first install pyconfiguration from conda

conda install -c rain1024 pyconfiguration

Step 3: Install pubSubClient package from conda

conda install -c hunguyen pubsubclient

Step 4: Create config.json file


Step 5: Run pubsubclient

# create and register or sync a publisher
publisher = Publisher('P1')
# create a new topic
topic = Topic('A')
# create an event of a topic
event = Event(topic)
# publisher publishes an event
# create and register or sync a subscriber
subscriber = Subscriber('S1')
# subscriber subscribes to a topic
# subscriber get all new events by time stamp of topics which it has subscribed
events = subscriber.get_events()