Skip to content

Commit

Permalink
Use print function syntax, in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alexchandel committed Jun 11, 2013
1 parent 4624ab9 commit 5c1b0d0
Show file tree
Hide file tree
Showing 7 changed files with 180 additions and 180 deletions.
4 changes: 2 additions & 2 deletions examples/consume.py
Expand Up @@ -6,11 +6,11 @@ def on_message(channel, method_frame, header_frame, body):
if body.startswith("queue:"):
queue = body.replace("queue:", "")
key = body + "_key"
print "Declaring queue %s bound with key %s" %(queue, key)
print("Declaring queue %s bound with key %s" %(queue, key))
channel.queue_declare(queue=queue, auto_delete=True)
channel.queue_bind(queue=queue, exchange="test_exchange", routing_key=key)
else:
print "Message body", body
print("Message body", body)

channel.basic_ack(delivery_tag=method_frame.delivery_tag)

Expand Down
36 changes: 18 additions & 18 deletions examples/consumer_queued.py
@@ -1,22 +1,22 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

import pika
import pika
import json
import threading


buffer = []
lock = threading.Lock()

print ('pika version: %s') % pika.__version__
print('pika version: %s' % pika.__version__)


connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))

main_channel = connection.channel()
consumer_channel = connection.channel()
bind_channel = connection.channel()
main_channel = connection.channel()
consumer_channel = connection.channel()
bind_channel = connection.channel()

if pika.__version__=='0.9.5':
main_channel.exchange_declare(exchange='com.micex.sten', type='direct')
Expand All @@ -28,39 +28,39 @@
queue = main_channel.queue_declare(exclusive=True).method.queue
queue_tickers = main_channel.queue_declare(exclusive=True).method.queue

main_channel.queue_bind(exchange='com.micex.sten', queue=queue, routing_key='order.stop.create')
main_channel.queue_bind(exchange='com.micex.sten', queue=queue, routing_key='order.stop.create')



def process_buffer():
if not lock.acquire(False):
print 'locked!'
if not lock.acquire(False):
print('locked!')
return
try:
while len(buffer):
body = buffer.pop(0)

ticker = None
if 'ticker' in body['data']['params']['condition']: ticker = body['data']['params']['condition']['ticker']
if not ticker: continue
print 'got ticker %s, gonna bind it...' % ticker
bind_channel.queue_bind(exchange='com.micex.lasttrades', queue=queue_tickers, routing_key=str(ticker))
print 'ticker %s binded ok' % ticker

print('got ticker %s, gonna bind it...' % ticker)
bind_channel.queue_bind(exchange='com.micex.lasttrades', queue=queue_tickers, routing_key=str(ticker))
print('ticker %s binded ok' % ticker)
finally:
lock.release()


def callback(ch, method, properties, body):
body = json.loads(body)['order.stop.create']
buffer.append(body)
process_buffer()
process_buffer()



consumer_channel.basic_consume(callback,
queue=queue, no_ack=True)

try:
consumer_channel.start_consuming()
try:
consumer_channel.start_consuming()
finally:
connection.close()
8 changes: 4 additions & 4 deletions examples/consumer_simple.py
Expand Up @@ -5,7 +5,7 @@
import json


print ('pika version: %s') % pika.__version__
print(('pika version: %s') % pika.__version__)


connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
Expand All @@ -28,7 +28,7 @@


def hello():
print 'Hello world'
print('Hello world')

connection.add_timeout(5, hello)

Expand All @@ -40,9 +40,9 @@ def callback(ch, method, properties, body):
if 'ticker' in body['data']['params']['condition']: ticker = body['data']['params']['condition']['ticker']
if not ticker: return

print 'got ticker %s, gonna bind it...' % ticker
print('got ticker %s, gonna bind it...' % ticker)
bind_channel.queue_bind(exchange='com.micex.lasttrades', queue=queue_tickers, routing_key=str(ticker))
print 'ticker %s binded ok' % ticker
print('ticker %s binded ok' % ticker)


import logging
Expand Down
4 changes: 2 additions & 2 deletions examples/producer.py
Expand Up @@ -5,7 +5,7 @@
import json
import random

print ('pika version: %s') % pika.__version__
print(('pika version: %s') % pika.__version__)

connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
main_channel = connection.channel()
Expand Down Expand Up @@ -36,6 +36,6 @@ def getticker(): return tickers.keys()[random.randrange(0,len(tickers)-1)]
body=json.dumps(msg),
properties=pika.BasicProperties(content_type='application/json')
)
print 'send ticker %s' % ticker
print('send ticker %s' % ticker)

connection.close()
6 changes: 3 additions & 3 deletions examples/publish.py
Expand Up @@ -10,21 +10,21 @@
channel.exchange_declare(exchange="test_exchange", exchange_type="direct",
passive=False, durable=True, auto_delete=False)

print "Sending message to create a queue"
print("Sending message to create a queue")
channel.basic_publish('test_exchange', 'standard_key', 'queue:group',
pika.BasicProperties(content_type='text/plain',
delivery_mode=1))

connection.sleep(5)

print "Sending text message to group"
print("Sending text message to group")
channel.basic_publish('test_exchange', 'group_key', 'Message to group_key',
pika.BasicProperties(content_type='text/plain',
delivery_mode=1))

connection.sleep(5)

print "Sending text message"
print("Sending text message")
channel.basic_publish('test_exchange', 'standard_key', 'Message to standard_key',
pika.BasicProperties(content_type='text/plain',
delivery_mode=1))
Expand Down
2 changes: 1 addition & 1 deletion examples/send.py
Expand Up @@ -10,7 +10,7 @@
channel = connection.channel()

def closeit():
print 'Close it'
print('Close it')
connection.close()

connection.add_timeout(5, closeit)
Expand Down

0 comments on commit 5c1b0d0

Please sign in to comment.