#!/usr/bin/env python import argparse import pika parser = argparse.ArgumentParser(description="Message to send") parser.add_argument("msg", metavar="msg", nargs="+", type=list, help="a message to send to the queue ") args = parser.parse_args() MESSAGE = " ".join(["".join(w) for w in args.msg]) with pika.BlockingConnection(pika.ConnectionParameters("localhost")) as connection: channel = connection.channel() channel.queue_declare(queue="hello") channel.basic_publish(exchange="", routing_key="hello", body=MESSAGE) print(f" [x] Sent '{MESSAGE}'")