1. John Mitchell
  2. amqp-ex

Commits

John Mitchell  committed 4b292ba

qecho/qlisten work for default broadcast exchange

  • Participants
  • Parent commits f1e6ba6
  • Branches default

Comments (0)

Files changed (6)

File Makefile

View file
 	sudo rabbitmqctl list_queues
 	sudo rabbitmqctl list_bindings
 	sudo rabbitmqctl list_exchanges
+%.html:	%.rst
+	rst2s5 $< $@

File messageq.txt

View file
+-*- outline -*-
+
+* questions
+** private keys?
+
+* intro
+
+Message Queues are used for routing and storing information across
+processes on one machine or several in a LAN.  Somewhat like email.
+
+** who am I
+*** Using Python since 1995
+*** C/C++, Java, PHP
+*** graphics, metadata, pipelines
+
+* overview
+
+* why MQ
+multiple news publishers, single receiver
+decentralized service
+distributed service
+durable single app
+actor model
+
+
+* msg queueing
+message orientation, queuing, routing (including point-to-point and
+publish-and-subscribe), reliability and security.
+Messages, not connections.
+
+* comparisons
+** D-Bus
+*** program registers a service
+*** routes hardware abstraction layer (HAL) msgs
+"disable screen saver when I watch a movie"
+"switch chat status from panel applet"
+** email
+
+* AMQP: Advanced Message Queuing Protocol
+** interoperability: wire level, not just API (vs: JMS)
+** financial
+
+* model:
+** broker/server
+** connection w/ user+auth
+** channel, virtual, per-thread
+** exchange: router recv msgs. named, typed
+*** properties: passive, durable, auto-delete
+** queues: holds msgs. named, properties, no types
+** message: unnamed. Header, opaque body
+*** key, immediate
+** binding: exch->queue mapping
+*** fanout (=broadcast), direct, topic matching
+
+
+* details
+** message: header(key), body (opaque)
+** key->exchange->queue
+** ex: fanout
+** types: fanout, direct, topic, others
+** ex: direct
+** topic diagram
+** extra features: persistent, ack, auto distribute?
+
+* AMQP/1.0
+** no exchanges & bindings, => links
+** addresses are first-class entities
+** service locations in DNS
+
+
+
+
+* implementations
+** RabbitMQ
+** Apache Qpid
+
+
+
+* TODO space diagram
+
+* in practice
+** useful problems
+
+** caveats
+
+*** multiple servers: round-robin. Tricky for development.
+** changes
+** no exchanges, now "queues + links"
+** addresses now first class entry
+
+* Further 
+** RedHat
+
+** help() is really good!
+
+http://blogs.digitar.com/jjww/2009/01/rabbits-and-warrens/
+
+http://www.redhat.com/docs/en-US/Red_Hat_Enterprise_MRG/1.0/html/Messaging_Tutorial/sect-Messaging_Tutorial-Writing_Fanout_Applications_in_Python-Running_the_Fanout_Examples.html
+
+

File qecho-dir.py

View file
+#!/usr/bin/env python
+
+'''
+qecho.py -- send words to AMQP routing key
+'''
+import sys, time
+from amqplib import client_0_8 as amqp
+
+conn = amqp.Connection()
+chan = conn.channel()
+
+args = sys.argv[1:]
+queuename = args.pop(0)
+msg = amqp.Message( ' '.join(args) )
+chan.basic_publish(msg, exchange="amq.direct", routing_key=queuename)
+
+chan.close()
+conn.close()

File qecho.py

-#!/usr/bin/env python
-
-'''
-qecho.py -- send words to AMQP routing key
-'''
-import sys, time
-from amqplib import client_0_8 as amqp
-
-conn = amqp.Connection()
-chan = conn.channel()
-
-args = sys.argv[1:]
-queuename = args.pop(0)
-msg = amqp.Message( ' '.join(args) )
-chan.basic_publish(msg, exchange="amq.direct", routing_key=queuename)
-
-chan.close()
-conn.close()

File qlisten.py

View file
+#!/usr/bin/env python
+
+'''
+qlisten.py -- listen to broadcast AMQP messages
+'''
+
+import logging, sys, time
+import amqplib.client_0_8 as amqp
+
+
+def recv(msg):
+    print time.ctime(),'C:', msg.properties, msg.body
+
+conn = amqp.Connection()
+chan = conn.channel()
+
+# declare new, private queue
+chan.queue_declare(exclusive=True)
+# route broadcast messages to it
+chan.queue_bind(queue='', exchange='amq.fanout')
+chan.basic_consume(callback=recv)
+
+print time.ctime(), 'listening'
+try:
+    while True:
+        chan.wait()
+except KeyboardInterrupt:
+    pass
+print time.ctime(), 'done'
+
+chan.close()
+conn.close()

File qtail.py

View file
 chan = conn.channel()
 
 chan.queue_declare(queuename, nowait=True)
-chan.exchange_declare(exchange="amq.fanout", type="fanout")
 
 # X: automatic routing: key "x" goes to queue "x"
 chan.queue_bind(queue=queuename, routing_key=queuename, exchange="amq.direct")