@@ -0,0 +1,2336 @@
+#!/usr/bin/env python%0A%22%22%22%0AAMQP Clock%0A%0AFires off simple messages at one-minute intervals to a topic%0Aexchange named 'clock', with the topic of the message being%0Athe local time as 'year.month.date.dow.hour.minute',%0Afor example: '2007.11.26.1.12.33', where the dow (day of week)%0Ais 0 for Sunday, 1 for Monday, and so on (similar to Unix crontab).%0A%0AA consumer could then bind a queue to the routing key '#.0'%0Afor example to get a message at the beginning of each hour.%0A%0A2007-11-26 Barry Pederson %3Cbp@barryp.org%3E%0A%0A%22%22%22%0Afrom datetime import datetime%0Afrom optparse import OptionParser%0Afrom time import sleep%0A%0Aimport amqplib.client_0_8 as amqp%0AMessage = amqp.Message%0A%0AEXCHANGE_NAME = 'clock'%0ATOPIC_PATTERN = '%25Y.%25m.%25d.%25w.%25H.%25M' # Python datetime.strftime() pattern%0A%0Adef main():%0A    parser = OptionParser()%0A    parser.add_option('--host', dest='host',%0A                        help='AMQP server to connect to (default: %25default)',%0A                        default='localhost')%0A    parser.add_option('-u', '--userid', dest='userid',%0A                        help='AMQP userid to authenticate as (default: %25default)',%0A                        default='guest')%0A    parser.add_option('-p', '--password', dest='password',%0A                        help='AMQP password to authenticate with (default: %25default)',%0A                        default='guest')%0A    parser.add_option('--ssl', dest='ssl', action='store_true',%0A                        help='Enable SSL with AMQP server (default: not enabled)',%0A                        default=False)%0A%0A    options, args = parser.parse_args()%0A%0A    conn = amqp.Connection(options.host, options.userid, options.password)%0A    ch = conn.channel()%0A    ch.access_request('/data', write=True, active=True)%0A    ch.exchange_declare(EXCHANGE_NAME, type='topic')%0A%0A    # Make sure our first message is close to the beginning%0A    # of a minute%0A    now = datetime.now()%0A    if now.second %3E 0:%0A        sleep(60 - now.second)%0A%0A    while True:%0A        now = datetime.now()%0A        msg = Message(timestamp=now)%0A        topic = now.strftime(TOPIC_PATTERN)%0A        ch.basic_publish(msg, EXCHANGE_NAME, routing_key=topic)%0A%0A        # Don't know how long the basic_publish took, so%0A        # grab the time again.%0A        now = datetime.now()%0A        sleep(60 - now.second)%0A%0A    ch.close()%0A    conn.close()%0A%0Aif __name__ == '__main__':%0A    main()%0A

Add another demo program, one that spits out messages at regular intervals.