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:
Dan Buch
2012-11-14 17:56:40 -05:00
parent 7155d76a11
commit 1120412e45
10 changed files with 2 additions and 1 deletions

2
sylvilagus/python/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
/.env
/*.egg-info/

View 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'
]
)

View File

View 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())

View File

@@ -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())