Commits

John Mitchell committed f88f338

qecho correctly dies on nonexistent server

Comments (0)

Files changed (3)

 all:
 
+test-fast:
+	./qecho.py beer
+
 status:
 	sudo rabbitmqctl list_queues
 	sudo rabbitmqctl list_bindings
 conn = amqp.Connection()
 chan = conn.channel()
 
-args = sys.argv[1:]
-msg = amqp.Message( ' '.join(args) )
-chan.basic_publish(msg, exchange="amq.fanout")
-
-chan.close()
-conn.close()
+msg = amqp.Message( ' '.join(sys.argv[1:]) )
+try:
+    chan.basic_publish(msg, exchange="myfanout", immediate=True)
+    print 'C:',msg.body
+    chan.close()
+except amqp.AMQPChannelException as exc:
+    print sys.argv[0],exc[1]
+    sys.exit(1)
+finally:
+    conn.close()
 conn = amqp.Connection()
 chan = conn.channel()
 
+# configure my exchange to receive messages, and croak if it's already there
+chan.exchange_declare('myfanout', 'fanout', auto_delete=True, nowait=True)
 # declare new, private queue
 chan.queue_declare(exclusive=True)
 # route broadcast messages to it
-chan.queue_bind(queue='', exchange='amq.fanout')
+chan.queue_bind(queue='', exchange='myfanout')
 chan.basic_consume(callback=recv)
 
 print time.ctime(), 'listening'