Skip to content

Instantly share code, notes, and snippets.

@realjktu
Last active September 8, 2018 07:24
Show Gist options
  • Save realjktu/197bd8bcdcab38bff096f57c06176653 to your computer and use it in GitHub Desktop.
Save realjktu/197bd8bcdcab38bff096f57c06176653 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import pika, os, sys, argparse
arg_parser = argparse.ArgumentParser(description='Send message to RabbitMQ queue.', add_help=False)
arg_parser.add_argument('--host', '-h', required=True, help='RammbitMQ host name.')
arg_parser.add_argument('--port', '-p', default=5672, type=int, help='RammbitMQ port. Default: 5672')
arg_parser.add_argument('--queue', '-q', required=True, help='RammbitMQ queue name. Prod queue is "environments"')
arg_parser.add_argument('--data', '-d', required=True, help='Message to RammbitMQ.')
args = arg_parser.parse_args()
print("Sending data to %s:%s/%s"% (args.host, args.port, args.queue))
connection = pika.BlockingConnection(pika.ConnectionParameters(host=args.host, port=args.port))
channel = connection.channel()
channel.queue_declare(queue=args.queue)
channel.basic_publish(exchange='',
routing_key=args.queue,
body=args.data)
print("Sent: %s"%(args.data))
connection.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment