Namespacing work by implementation language
which just might be a horrible idea, but it was feeling cluttered at just two languages and I'm about to add a third...
This commit is contained in:
2
sylvilagus/python/.gitignore
vendored
Normal file
2
sylvilagus/python/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/.env
|
||||
/*.egg-info/
|
13
sylvilagus/python/setup.py
Normal file
13
sylvilagus/python/setup.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from setuptools import setup
|
||||
|
||||
setup(
|
||||
name='sylvilagus',
|
||||
version='0.1.0',
|
||||
author='Dan Buch',
|
||||
author_email='dan@meatballhat.com',
|
||||
description='crap accumulated while reading through RabbitMQ in Action',
|
||||
packages=['sylvilagus'],
|
||||
install_requires=[
|
||||
'pika >= 0.9.6'
|
||||
]
|
||||
)
|
0
sylvilagus/python/sylvilagus/__init__.py
Normal file
0
sylvilagus/python/sylvilagus/__init__.py
Normal file
@@ -0,0 +1,46 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
import pika
|
||||
|
||||
|
||||
def msg_consumer(channel, method, header, body):
|
||||
channel.basic_ack(delivery_tag=method.delivery_tag)
|
||||
if body == 'quit':
|
||||
channel.basic_cancel(consumer_tag='hello-consumer')
|
||||
channel.stop_consuming()
|
||||
else:
|
||||
print(body)
|
||||
return
|
||||
|
||||
|
||||
def main():
|
||||
credentials = pika.PlainCredentials('guest', 'guest')
|
||||
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_bind(queue='hello-queue',
|
||||
exchange='hello-exchange',
|
||||
routing_key='hola')
|
||||
|
||||
channel.basic_consume(msg_consumer,
|
||||
queue='hello-queue',
|
||||
consumer_tag='hello-consumer')
|
||||
|
||||
print('consuming...')
|
||||
channel.start_consuming()
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
@@ -0,0 +1,34 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
import pika
|
||||
|
||||
|
||||
def main(args=sys.argv[:]):
|
||||
credentials = pika.PlainCredentials('guest', 'guest')
|
||||
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_props = pika.BasicProperties()
|
||||
msg_props.content_type = 'text/plain'
|
||||
|
||||
channel.basic_publish(body=msg,
|
||||
exchange='hello-exchange',
|
||||
properties=msg_props,
|
||||
routing_key='hola')
|
||||
print('published {!r}'.format(msg))
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
Reference in New Issue
Block a user