Last active
January 6, 2021 15:50
-
-
Save Gsantomaggio/ebeafade515a2788c8553223a4bdb0dc to your computer and use it in GitHub Desktop.
This file contains 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 characters
import pika | |
import time | |
import sys | |
## Execute the script and then send a message (using the ui) to the queue called myqueue | |
class PyPikaTest: | |
def callback(self, ch, method, properties, body): | |
print("[Message Received] %s" % (body)) | |
time.sleep(2.5 * 60) | |
print("[After 2.5 minutes] %s" % (body)) | |
ch.basic_ack(delivery_tag = method.delivery_tag) | |
def start_consumer(self): | |
credentials = pika.PlainCredentials('guest', 'guest') | |
connection = pika.BlockingConnection(pika.ConnectionParameters(host="localhost", port=5672, | |
virtual_host="/", | |
credentials=credentials)) | |
channel = connection.channel() | |
qname = "myqueue" | |
channel.queue_declare(queue=qname, auto_delete=False) | |
channel.basic_qos(prefetch_count=1) | |
channel.basic_consume( | |
queue=qname, | |
on_message_callback=self.callback, | |
auto_ack=False) | |
channel.start_consuming() | |
x = PyPikaTest() | |
x.start_consumer() | |
input("Press Enter to continue...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment