Last active
November 30, 2020 22:30
-
-
Save e-roux/0042434182a15dfb68e7fbb11bf94df7 to your computer and use it in GitHub Desktop.
Revisions
-
e-roux revised this gist
Nov 30, 2020 . 1 changed file with 6 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -23,4 +23,9 @@ def callback(ch, method, properties, body): try: sys.exit(0) except SystemExit: os._exit(0)#!/usr/bin/env python -
e-roux revised this gist
Nov 30, 2020 . 1 changed file with 19 additions and 9 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,26 @@ #!/usr/bin/env python import pika, sys, os def main(): connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost')) channel = connection.channel() channel.queue_declare(queue='hello') def callback(ch, method, properties, body): print(" [x] Received %r" % body) channel.basic_consume(queue='hello', on_message_callback=callback, auto_ack=True) print(' [*] Waiting for messages. To exit press CTRL+C') channel.start_consuming() if __name__ == '__main__': try: main() except KeyboardInterrupt: print('Interrupted') try: sys.exit(0) except SystemExit: os._exit(0)#!/usr/bin/env python -
e-roux revised this gist
Nov 30, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ def callback(ch, method, properties, body): print(f" [x] Received {body:r}":) with pika.BlockingConnection(pika.ConnectionParameters("localhost")) as connection: -
e-roux revised this gist
Nov 30, 2020 . No changes.There are no files selected for viewing
-
e-roux revised this gist
Nov 30, 2020 . No changes.There are no files selected for viewing
-
e-roux revised this gist
Nov 30, 2020 . 1 changed file with 0 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -10,7 +10,6 @@ def callback(ch, method, properties, body): channel = connection.channel() channel.queue_declare(queue="hello") channel.basic_consume(queue="hello", auto_ack=True, on_message_callback=callback) print(" [*] Waiting for messages. To exit press CTRL+C") -
e-roux created this gist
Nov 5, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ #!/usr/bin/env python import pika def callback(ch, method, properties, body): print(" [x] Received %r" % body) with pika.BlockingConnection(pika.ConnectionParameters("localhost")) as connection: channel = connection.channel() channel.queue_declare(queue="hello") channel.basic_consume(queue="hello", auto_ack=True, on_message_callback=callback) print(" [*] Waiting for messages. To exit press CTRL+C") channel.start_consuming() This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ #!/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}'")