From 854f0fecc29299c3abbd9a95331acc63fa7ada62 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Fri, 30 Nov 2007 17:11:47 +0000 Subject: Python examples git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@599876 13f79535-47bb-0310-9956-ffa450edef68 --- python/examples/direct/config_direct_exchange.py | 57 ++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 python/examples/direct/config_direct_exchange.py (limited to 'python/examples/direct/config_direct_exchange.py') diff --git a/python/examples/direct/config_direct_exchange.py b/python/examples/direct/config_direct_exchange.py new file mode 100644 index 0000000000..45af6f63b9 --- /dev/null +++ b/python/examples/direct/config_direct_exchange.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +""" + config_direct_exchange.py + + Creates and binds a queue on an AMQP direct exchange. + + All messages using the routing key "routing_key" are + sent to the queue named "message_queue". +""" + +import qpid +from qpid.client import Client +from qpid.content import Content +from qpid.queue import Empty + +#----- Initialization ----------------------------------- + +# Set parameters for login + +host="127.0.0.1" +port=5672 +amqp_spec="/usr/share/amqp/amqp.0-10-preview.xml" +user="guest" +password="guest" + +# Create a client and log in to it. + +client = Client(host, port, qpid.spec.load(amqp_spec)) +client.start({"LOGIN": user, "PASSWORD": password}) + +session = client.session() +session.session_open() + +#----- Create a queue ------------------------------------- + +# Create a queue named "listener" on channel 1, and bind it +# to the "amq.direct" exchange. +# +# queue_declare() creates an AMQP queue, which is held +# on the broker. Published messages are sent to the AMQP queue, +# from which messages are delivered to consumers. +# +# queue_bind() determines which messages are routed to a queue. +# Route all messages with the routing key "routing_key" to +# the AMQP queue named "message_queue". + +session.queue_declare(queue="message_queue") +session.queue_bind(exchange="amq.direct", queue="message_queue", routing_key="routing_key") + +#----- Cleanup --------------------------------------------- + +# Clean up before exiting so there are no open threads. +# +# Close Channel 1. +# Close the connection using Channel 0, which is used for all connection methods. +session.session_close() + -- cgit v1.2.1