1. John Mitchell
  2. amqp-ex

Commits

John Mitchell  committed 789a413

works

  • Participants
  • Branches default

Comments (0)

Files changed (5)

File Makefile

View file
+all:
+
+status:
+	sudo rabbitmqctl list_queues
+	sudo rabbitmqctl list_bindings
+	sudo rabbitmqctl list_exchanges

File amqp_consumer.py

View file
+#!/usr/bin/python
+
+from amqplib import client_0_8 as amqp
+
+conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/", insist=False)
+chan = conn.channel()
+
+chan.queue_declare(queue="po_box", durable=True, exclusive=False, auto_delete=False)
+chan.exchange_declare(exchange="sorting_room", type="direct", durable=True, auto_delete=False,)
+
+chan.queue_bind(queue="po_box", exchange="sorting_room", routing_key="jason")
+
+def recv_callback(msg):
+    print 'Received: ' + msg.body + ' from channel #' + str(msg.channel.channel_id)
+
+chan.basic_consume(queue='po_box', no_ack=True, callback=recv_callback, consumer_tag="testtag")
+while True:
+    chan.wait()
+chan.basic_cancel("testtag")
+
+
+chan.close()
+conn.close()

File amqp_publisher.py

View file
+#!/usr/bin/python
+
+from amqplib import client_0_8 as amqp
+import sys
+
+conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/", insist=False)
+chan = conn.channel()
+
+msg = amqp.Message(sys.argv[1])
+msg.properties["delivery_mode"] = 2
+chan.basic_publish(msg,exchange="sorting_room",routing_key="jason")
+
+chan.close()
+conn.close()

File hello.py

View file
+#!/usr/bin/env python
+
+'''
+'''
+
+import amqplib.client_0_8 as amqp
+conn = amqp.Connection()
+chan = conn.channel()
+
+chan.queue_declare()
+chan.exchange_declare(exchange="amq.fanout", type="fanout")
+
+chan.queue_bind(queue="hello", exchange="amq.fanout")
+
+def recv_callback(msg):
+    print 'Received: ' + msg.body + ' from channel #' + str(msg.channel.channel_id)
+
+chan.basic_consume(
+    queue='hello', no_ack=True, callback=recv_callback, 
+    consumer_tag="testtag")
+while True:
+    chan.wait()
+chan.basic_cancel("testtag")
+
+
+# chan.close()
+# conn.close()

File z.py

View file
+#!/usr/bin/python
+
+from amqplib import client_0_8 as amqp
+import sys
+
+conn = amqp.Connection()
+chan = conn.channel()
+chan.queue_declare('hello', nowait=True)
+msg = amqp.Message('beer')
+chan.basic_publish(msg, exchange="amq.fanout")
+
+
+# conn = amqp.Connection(host="localhost:5672", userid="guest", password="guest", virtual_host="/", insist=False)
+# chan = conn.channel()
+
+# msg = amqp.Message(sys.argv[1])
+# msg.properties["delivery_mode"] = 2
+# chan.basic_publish(msg,exchange="sorting_room",routing_key="jason")
+
+chan.close()
+conn.close()