Working through the confirmation example
albeit with code that works rather than what came with the book. Hmm...
This commit is contained in:
parent
26ec865dd7
commit
18a9674ec2
@ -8,6 +8,6 @@ setup(
|
|||||||
description='crap accumulated while reading through RabbitMQ in Action',
|
description='crap accumulated while reading through RabbitMQ in Action',
|
||||||
packages=['sylvilagus'],
|
packages=['sylvilagus'],
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'pika >= 0.9.6'
|
'pika == 0.9.6'
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
@ -1,16 +1,36 @@
|
|||||||
import pika
|
import pika
|
||||||
|
|
||||||
|
|
||||||
def get_channel():
|
def get_conn_params():
|
||||||
credentials = pika.PlainCredentials('guest', 'guest')
|
credentials = pika.PlainCredentials('guest', 'guest')
|
||||||
conn_params = pika.ConnectionParameters('localhost',
|
return pika.ConnectionParameters('localhost', credentials=credentials)
|
||||||
credentials=credentials)
|
|
||||||
channel = pika.BlockingConnection(conn_params).channel()
|
|
||||||
channel.exchange_declare(exchange='hello-exchange',
|
def get_nonblocking_channel(declare_exchange=True):
|
||||||
type='direct',
|
channel = pika.SelectConnection(get_conn_params()).channel()
|
||||||
|
|
||||||
|
if declare_exchange:
|
||||||
|
channel.exchange_declare(
|
||||||
|
exchange='hello-exchange',
|
||||||
|
exchange_type='direct',
|
||||||
passive=False,
|
passive=False,
|
||||||
durable=True,
|
durable=True,
|
||||||
auto_delete=False)
|
auto_delete=False
|
||||||
|
)
|
||||||
|
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
|
|
||||||
|
def get_channel(declare_exchange=True):
|
||||||
|
channel = pika.BlockingConnection(get_conn_params()).channel()
|
||||||
|
|
||||||
|
if declare_exchange:
|
||||||
|
channel.exchange_declare(
|
||||||
|
exchange='hello-exchange',
|
||||||
|
exchange_type='direct',
|
||||||
|
passive=False,
|
||||||
|
durable=True,
|
||||||
|
auto_delete=False
|
||||||
|
)
|
||||||
|
|
||||||
|
return channel
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import logging
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import pika
|
||||||
|
|
||||||
|
from sylvilagus.chapter02 import hello_world
|
||||||
|
|
||||||
|
|
||||||
|
def main(sysargs=sys.argv[:]):
|
||||||
|
msg = sysargs[1]
|
||||||
|
|
||||||
|
logging.basicConfig()
|
||||||
|
|
||||||
|
channel = hello_world.get_channel()
|
||||||
|
|
||||||
|
if channel.basic_publish(
|
||||||
|
body=msg,
|
||||||
|
exchange='hello-exchange',
|
||||||
|
properties=pika.BasicProperties(
|
||||||
|
content_type='text/plain',
|
||||||
|
delivery_mode=1
|
||||||
|
),
|
||||||
|
routing_key='hola',
|
||||||
|
mandatory=True):
|
||||||
|
print('Message delivered!')
|
||||||
|
else:
|
||||||
|
print('Message returned!')
|
||||||
|
|
||||||
|
channel.close()
|
||||||
|
|
||||||
|
return 0
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
sys.exit(main())
|
Loading…
Reference in New Issue
Block a user