Pulling out channel setup into common bits
as was suggested in book.
This commit is contained in:
parent
1120412e45
commit
26ec865dd7
0
sylvilagus/python/sylvilagus/chapter02/__init__.py
Normal file
0
sylvilagus/python/sylvilagus/chapter02/__init__.py
Normal file
16
sylvilagus/python/sylvilagus/chapter02/hello_world.py
Normal file
16
sylvilagus/python/sylvilagus/chapter02/hello_world.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import pika
|
||||||
|
|
||||||
|
|
||||||
|
def get_channel():
|
||||||
|
credentials = pika.PlainCredentials('guest', 'guest')
|
||||||
|
conn_params = pika.ConnectionParameters('localhost',
|
||||||
|
credentials=credentials)
|
||||||
|
channel = pika.BlockingConnection(conn_params).channel()
|
||||||
|
channel.exchange_declare(exchange='hello-exchange',
|
||||||
|
type='direct',
|
||||||
|
passive=False,
|
||||||
|
durable=True,
|
||||||
|
auto_delete=False)
|
||||||
|
|
||||||
|
return channel
|
||||||
|
|
@ -4,6 +4,8 @@ import sys
|
|||||||
|
|
||||||
import pika
|
import pika
|
||||||
|
|
||||||
|
from sylvilagus.chapter02 import hello_world
|
||||||
|
|
||||||
|
|
||||||
def msg_consumer(channel, method, header, body):
|
def msg_consumer(channel, method, header, body):
|
||||||
channel.basic_ack(delivery_tag=method.delivery_tag)
|
channel.basic_ack(delivery_tag=method.delivery_tag)
|
||||||
@ -16,16 +18,7 @@ def msg_consumer(channel, method, header, body):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
credentials = pika.PlainCredentials('guest', 'guest')
|
channel = hello_world.get_channel()
|
||||||
conn_params = pika.ConnectionParameters('localhost',
|
|
||||||
credentials=credentials)
|
|
||||||
conn_broker = pika.BlockingConnection(conn_params)
|
|
||||||
channel = conn_broker.channel()
|
|
||||||
channel.exchange_declare(exchange='hello-exchange',
|
|
||||||
type='direct',
|
|
||||||
passive=False,
|
|
||||||
durable=True,
|
|
||||||
auto_delete=False)
|
|
||||||
|
|
||||||
channel.queue_declare(queue='hello-queue')
|
channel.queue_declare(queue='hello-queue')
|
||||||
channel.queue_bind(queue='hello-queue',
|
channel.queue_bind(queue='hello-queue',
|
||||||
|
@ -4,18 +4,11 @@ import sys
|
|||||||
|
|
||||||
import pika
|
import pika
|
||||||
|
|
||||||
|
from sylvilagus.chapter02 import hello_world
|
||||||
|
|
||||||
|
|
||||||
def main(args=sys.argv[:]):
|
def main(args=sys.argv[:]):
|
||||||
credentials = pika.PlainCredentials('guest', 'guest')
|
channel = hello_world.get_channel()
|
||||||
conn_params = pika.ConnectionParameters('localhost',
|
|
||||||
credentials=credentials)
|
|
||||||
conn_broker = pika.BlockingConnection(conn_params)
|
|
||||||
channel = conn_broker.channel()
|
|
||||||
channel.exchange_declare(exchange='hello-exchange',
|
|
||||||
type='direct',
|
|
||||||
passive=False,
|
|
||||||
durable=True,
|
|
||||||
auto_delete=False)
|
|
||||||
|
|
||||||
msg = args[1]
|
msg = args[1]
|
||||||
msg_props = pika.BasicProperties()
|
msg_props = pika.BasicProperties()
|
||||||
|
Loading…
Reference in New Issue
Block a user