Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jacopen committed Aug 5, 2016
1 parent b533126 commit 5bc4100
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 36 deletions.
19 changes: 0 additions & 19 deletions helloworld/recive.py

This file was deleted.

17 changes: 0 additions & 17 deletions helloworld/send.py

This file was deleted.

Empty file added lib/__init__.py
Empty file.
Binary file added lib/__init__.pyc
Binary file not shown.
25 changes: 25 additions & 0 deletions lib/connection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import sys
import pika
import argparse

parser = argparse.ArgumentParser(description='MQ')
parser.add_argument('-H', '--host', \
default='localhost', \
type=str)

parser.add_argument('-P', '--port', \
default=5672, \
type=int)

parser.add_argument('-q', '--queue', \
default='hello', \
type=str)
parser.add_argument('-r', '--routing', \
default='hello', \
type=str)
parser.add_argument('-b', '--body', \
default='Hello world', \
type=str)
args = parser.parse_args()

connection = pika.BlockingConnection(pika.ConnectionParameters(args.host, args.port))
Binary file added lib/connection.pyc
Binary file not shown.
19 changes: 19 additions & 0 deletions receive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env python
import sys
from lib import connection

# If you wanted to connect to a broker on a differentmachine,
# you simply specify itsname or IP address here.
channel = connection.connection.channel()

channel.queue_declare(queue=connection.args.queue)

def callback(ch, method, properties, body):
print(" [x] Received %r" % body)

channel.basic_consume(callback,
queue=connection.args.queue ,
no_ack=True)

print(' [*] Waiting for messages. To exit press CTRL+C')
channel.start_consuming()
17 changes: 17 additions & 0 deletions send.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env python

import sys
from lib import connection

# If you wanted to connect to a broker on a differentmachine,
# you simply specify itsname or IP address here.
channel = connection.connection.channel()

channel.queue_declare(queue=connection.args.queue)
channel.basic_publish(exchange='',
routing_key=connection.args.routing,
body=connection.args.body)

print(" [x] Sent '%s'" % connection.args.body)

connection.connection.close()

0 comments on commit 5bc4100

Please sign in to comment.