Skip to content

Instantly share code, notes, and snippets.

@e-roux
Last active November 30, 2020 22:30
Show Gist options
  • Select an option

  • Save e-roux/0042434182a15dfb68e7fbb11bf94df7 to your computer and use it in GitHub Desktop.

Select an option

Save e-roux/0042434182a15dfb68e7fbb11bf94df7 to your computer and use it in GitHub Desktop.

Revisions

  1. e-roux revised this gist Nov 30, 2020. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion receive.py
    Original 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
    os._exit(0)#!/usr/bin/env python





  2. e-roux revised this gist Nov 30, 2020. 1 changed file with 19 additions and 9 deletions.
    28 changes: 19 additions & 9 deletions receive.py
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,26 @@
    #!/usr/bin/env python
    import pika
    import pika, sys, os

    def main():
    connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
    channel = connection.channel()

    def callback(ch, method, properties, body):
    print(f" [x] Received {body:r}":)
    channel.queue_declare(queue='hello')

    def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)

    with pika.BlockingConnection(pika.ConnectionParameters("localhost")) as connection:
    channel = connection.channel()
    channel.basic_consume(queue='hello', on_message_callback=callback, auto_ack=True)

    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()

    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
  3. e-roux revised this gist Nov 30, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion receive.py
    Original file line number Diff line number Diff line change
    @@ -3,7 +3,7 @@


    def callback(ch, method, properties, body):
    print(" [x] Received %r" % body)
    print(f" [x] Received {body:r}":)


    with pika.BlockingConnection(pika.ConnectionParameters("localhost")) as connection:
  4. e-roux revised this gist Nov 30, 2020. No changes.
  5. e-roux revised this gist Nov 30, 2020. No changes.
  6. e-roux revised this gist Nov 30, 2020. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion receive.py
    Original 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")
  7. e-roux created this gist Nov 5, 2020.
    17 changes: 17 additions & 0 deletions receive.py
    Original 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()
    20 changes: 20 additions & 0 deletions send.py
    Original 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}'")