Permalink
Browse files

Updated puka tutorial samples.

  • Loading branch information...
1 parent 0afac37 commit 1f5fd76014afa55e7a28852f6aef36f07b6c20a6 @majek majek committed Jul 6, 2011
Showing with 77 additions and 34 deletions.
  1. +18 −0 python-puka/emit_log.py
  2. +11 −8 python-puka/new_task.py
  3. +8 −8 python-puka/receive.py
  4. +24 −0 python-puka/receive_logs.py
  5. +9 −8 python-puka/send.py
  6. +7 −10 python-puka/worker.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+import puka
+import sys
+
+client = puka.Client("amqp://localhost/")
+promise = client.connect()
+client.wait(promise)
+
+
+promise = client.exchange_declare(exchange='logs', type='fanout')
+client.wait(promise)
+
+message = ' '.join(sys.argv[1:]) or "info: Hello World!"
+promise = client.basic_publish(exchange='logs', routing_key='', body=message)
+client.wait(promise)
+
+print " [x] Sent %r" % (message,)
+client.close()
@@ -3,16 +3,19 @@
import sys
client = puka.Client("amqp://localhost/")
-ticket = client.connect()
-client.wait(ticket)
+promise = client.connect()
+client.wait(promise)
-ticket = client.queue_declare(queue='task_queue')
-client.wait(ticket)
+
+promise = client.queue_declare(queue='task_queue', durable=True)
+client.wait(promise)
message = ' '.join(sys.argv[1:]) or "Hello World!"
-ticket = client.basic_publish(exchange='',
- routing_key='task_queue',
- body=message)
-client.wait(ticket)
+promise = client.basic_publish(exchange='',
+ routing_key='task_queue',
+ body=message,
+ headers={'delivery_mode': 2})
+client.wait(promise)
print " [x] Sent %r" % (message,)
+client.close()
@@ -2,17 +2,17 @@
import puka
client = puka.Client("amqp://localhost/")
-ticket = client.connect()
-client.wait(ticket)
+promise = client.connect()
+client.wait(promise)
-ticket = client.queue_declare(queue='hello')
-client.wait(ticket)
+promise = client.queue_declare(queue='hello')
+client.wait(promise)
+
print ' [*] Waiting for messages. To exit press CTRL+C'
-consume_ticket = client.basic_consume(queue='hello',
- no_ack=True)
+consume_promise = client.basic_consume(queue='hello', no_ack=True)
while True:
- msg_result = client.wait(consume_ticket)
- print " [x] Received %r %r" % (msg_result['body'], msg_result,)
+ msg_result = client.wait(consume_promise)
+ print " [x] Received %r" % (msg_result['body'],)
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+import puka
+
+client = puka.Client("amqp://localhost/")
+promise = client.connect()
+client.wait(promise)
+
+
+promise = client.exchange_declare(exchange='logs', type='fanout')
+client.wait(promise)
+
+promise = client.queue_declare(exclusive=True)
+queue_name = client.wait(promise)['queue']
+
+promise = client.queue_bind(exchange='logs', queue=queue_name)
+client.wait(promise)
+
+
+print ' [*] Waiting for logs. To exit press CTRL+C'
+
+consume_promise = client.basic_consume(queue=queue_name, no_ack=True)
+while True:
+ msg_result = client.wait(consume_promise)
+ print " [x] %r" % (msg_result['body'],)
View
@@ -2,16 +2,17 @@
import puka
client = puka.Client("amqp://localhost/")
-ticket = client.connect()
-client.wait(ticket)
+promise = client.connect()
+client.wait(promise)
-ticket = client.queue_declare(queue='hello')
-client.wait(ticket)
-ticket = client.basic_publish(exchange='',
- routing_key='hello',
- body="Hello world!")
-client.wait(ticket)
+promise = client.queue_declare(queue='hello')
+client.wait(promise)
+promise = client.basic_publish(exchange='',
+ routing_key='hello',
+ body="Hello World!")
+client.wait(promise)
print " [x] Sent 'Hello World!'"
+client.close()
View
@@ -3,21 +3,18 @@
import time
client = puka.Client("amqp://localhost/")
-ticket = client.connect()
-client.wait(ticket)
+promise = client.connect()
+client.wait(promise)
-ticket = client.queue_declare(queue='task_queue')
-client.wait(ticket)
+promise = client.queue_declare(queue='task_queue', durable=True)
+client.wait(promise)
print ' [*] Waiting for messages. To exit press CTRL+C'
-consume_ticket = client.basic_consume(queue='task_queue',
- prefetch_count=1)
+consume_promise = client.basic_consume(queue='task_queue', prefetch_count=1)
while True:
- msg_result = client.wait(consume_ticket)
- body = msg_result['body']
- print " [x] Received %r" % (body,)
+ msg_result = client.wait(consume_promise)
+ print " [x] Received %r" % (msg_result['body'],)
time.sleep( body.count('.') )
print " [x] Done"
client.basic_ack(msg_result)
-

0 comments on commit 1f5fd76

Please sign in to comment.