Skip to content
Snippets Groups Projects
Commit b50ef650 authored by Mitchell Moore's avatar Mitchell Moore
Browse files

Allow robust command line args

parent 16b28c8d
No related branches found
No related tags found
2 merge requests!35Version 1b openstack rabbitmq,!30Refine Producer/Consumers Data Handling
#!/usr/bin/env python
import pika
import pika # python client
import sys
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost'))
pika.ConnectionParameters(host='localhost')) # connecting to a broker on the local machine
channel = connection.channel()
channel.exchange_declare(exchange='direct_logs', exchange_type='direct')
channel.exchange_declare(exchange='direct_logs', exchange_type='direct') # create exchange to pass messages
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue
queue_name = result.method.queue # creates a random name for the newly generated queue
severities = sys.argv[1:]
if not severities:
nodes = sys.argv[1:]
if not nodes:
sys.stderr.write("Usage: %s [info] [warning] [error]\n" % sys.argv[0])
sys.exit(1)
for severity in severities:
for node in nodes:
channel.queue_bind(
exchange='direct_logs', queue=queue_name, routing_key=severity)
exchange='direct_logs', queue=queue_name, routing_key=node) # combine exchange, queue, and define routing name
print(' [*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] %r:%r" % (method.routing_key, body))
print('[%r] User creation task is done.' % method.routing_key)
channel.basic_consume(
queue=queue_name, on_message_callback=callback, auto_ack=True)
queue=queue_name, on_message_callback=callback, auto_ack=True) # ingest messages, and assume delivered via auto_ack
channel.start_consuming()
\ No newline at end of file
channel.start_consuming() # initiate message ingestion
#!/usr/bin/env python
import pika # python client
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost')) # connecting to a broker on the local machine
channel = connection.channel()
channel.exchange_declare(exchange='direct_logs', exchange_type='direct') # create exchange to pass messages
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue # creates a random name for the newly generated queue
channel.queue_bind(
exchange='direct_logs', queue=queue_name, routing_key="manager") # combine exchange, queue, and define routing name
print(' [*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] %r:%r" % (method.routing_key, body))
print('[manager] User creation task is done.')
# Todo: Make message manager more functional
channel.basic_consume(
queue=queue_name, on_message_callback=callback, auto_ack=True) # ingest messages, and assume delivered via auto_ack
channel.start_consuming() # initiate message ingenstion
#!/usr/bin/env python
import pika # python client
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost')) # connecting to a broker on the local machine
channel = connection.channel()
channel.exchange_declare(exchange='direct_logs', exchange_type='direct') # create exchange to pass messages
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue # creates a random name for the newly generated queue
channel.queue_bind(
exchange='direct_logs', queue=queue_name, routing_key="ohpc") # combine exchange, queue, and define routing name
print(' [*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] %r:%r" % (method.routing_key, body))
# Todo: Make message manager more functional
print('[ohpc] User has been created')
channel.basic_publish(
exchange='direct_logs', routing_key="ood", body='{uid:1002,gid:1002}')
print(" [x] Sent %r:%r" % ("ood", '{uid:1002, gid:1002}'))
channel.basic_consume(
queue=queue_name, on_message_callback=callback, auto_ack=True) # ingest messages, and assume delivered via auto_ack
channel.start_consuming() # initiate message ingenstion
#!/usr/bin/env python
import pika # python client
credentials = pika.PlainCredentials('reggie', 'reggie')
parameters = pika.ConnectionParameters('ohpc',
5672,
'/',
credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.exchange_declare(exchange='direct_logs', exchange_type='direct') # create exchange to pass messages
result = channel.queue_declare(queue='', exclusive=True)
queue_name = result.method.queue # creates a random name for the newly generated queue
channel.queue_bind(
exchange='direct_logs', queue=queue_name, routing_key="ood") # combine exchange, queue, and define routing name
print(' [*] Waiting for logs. To exit press CTRL+C')
def callback(ch, method, properties, body):
print(" [x] %r:%r" % (method.routing_key, body))
# Todo: Make message manager more functional
print('[ood] User has been created')
channel.basic_publish(
exchange='direct_logs', routing_key="manager", body='{status:"done"}')
print(" [x] Sent %r:%r" % ("manager", '{status:done}'))
channel.basic_consume(
queue=queue_name, on_message_callback=callback, auto_ack=True) # ingest messages, and assume delivered via auto_ack
channel.start_consuming() # initiate message ingenstion
......@@ -8,10 +8,10 @@ channel = connection.channel()
channel.exchange_declare(exchange='direct_logs', exchange_type='direct')
message = "Hey need an account here" # todo: account info goes here
node = sys.argv[1] if len(sys.argv) > 1 else 'info'
message = ' '.join(sys.argv[2:]) or 'Hello World!'
channel.basic_publish(
exchange='direct_logs', routing_key="ohpc", body=message)
print(" [x] Sent %r:%r" % ("ohpc", message))
exchange='direct_logs', routing_key=node, body=message)
print(" [x] Sent %r:%r" % (node, message))
connection.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment