summaryrefslogtreecommitdiff
path: root/python/examples/direct/direct_consumer.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/examples/direct/direct_consumer.py')
-rwxr-xr-xpython/examples/direct/direct_consumer.py51
1 files changed, 27 insertions, 24 deletions
diff --git a/python/examples/direct/direct_consumer.py b/python/examples/direct/direct_consumer.py
index 91d85cee1a..f2018bbbb8 100755
--- a/python/examples/direct/direct_consumer.py
+++ b/python/examples/direct/direct_consumer.py
@@ -12,7 +12,7 @@ import os
from random import randint
from qpid.util import connect
from qpid.connection import Connection
-from qpid.datatypes import Message, RangedSet
+from qpid.datatypes import Message, RangedSet, uuid4
from qpid.queue import Empty
@@ -20,11 +20,22 @@ from qpid.queue import Empty
# Set parameters for login
-host=len(sys.argv) > 1 and sys.argv[1] or "127.0.0.1"
-port=len(sys.argv) > 2 and int(sys.argv[2]) or 5672
+host="127.0.0.1"
+port=5672
user="guest"
password="guest"
-amqp_spec=""
+amqp_spec="/usr/share/amqp/amqp.0-10.xml"
+
+# If an alternate host or port has been specified, use that instead
+# (this is used in our unit tests)
+#
+# If AMQP_SPEC is defined, use it to locate the spec file instead of
+# looking for it in the default location.
+
+if len(sys.argv) > 1 :
+ host=sys.argv[1]
+if len(sys.argv) > 2 :
+ port=int(sys.argv[2])
try:
amqp_spec = os.environ["AMQP_SPEC"]
@@ -32,10 +43,10 @@ except KeyError:
amqp_spec="/usr/share/amqp/amqp.0-10.xml"
# Create a connection.
-conn = Connection (connect (host,port), qpid.spec.load(amqp_spec))
-conn.start()
-
-session = conn.session(str(randint(1,64*1024)))
+socket = connect(host, port)
+connection = Connection (sock=socket, spec=qpid.spec.load(amqp_spec))
+connection.start()
+session = connection.session(str(uuid4()))
#----- Read from queue --------------------------------------------
@@ -44,16 +55,17 @@ session = conn.session(str(randint(1,64*1024)))
# The consumer tag identifies the client-side queue.
-consumer_tag = "consumer1"
-queue = session.incoming(consumer_tag)
+local_queue_name = "local_queue"
+queue = session.incoming(local_queue_name)
-# Call message_consume() to tell the broker to deliver messages
+# Call message_subscribe() to tell the broker to deliver messages
# from the AMQP queue to this local client queue. The broker will
-# start delivering messages as soon as message_consume() is called.
+# start delivering messages as soon as credit is allocated using
+# session.message_flow().
-session.message_subscribe(queue="message_queue", destination=consumer_tag)
-session.message_flow(consumer_tag, 0, 0xFFFFFFFF) # Kill these?
-session.message_flow(consumer_tag, 1, 0xFFFFFFFF) # Kill these?
+session.message_subscribe(queue="message_queue", destination=local_queue_name)
+session.message_flow(local_queue_name, session.credit_unit.message, 0xFFFFFFFF)
+session.message_flow(local_queue_name, session.credit_unit.byte, 0xFFFFFFFF)
# Initialize 'final' and 'content', variables used to identify the last message.
@@ -67,15 +79,6 @@ while content != final:
session.message_accept(RangedSet(message.id))
print content
-# Messages are not removed from the queue until they are
-# acknowledged. Using cumulative=True, all messages from the session
-# up to and including the one identified by the delivery tag are
-# acknowledged. This is more efficient, because there are fewer
-# network round-trips.
-
-#message.complete(cumulative=True)
-# ? Is there an equivakent to the above in the new API ?
-
#----- Cleanup ------------------------------------------------
# Clean up before exiting so there are no open threads.