forked from Ladicle/play-rabbitmq
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
61 additions
and
36 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |