Skip to content

Instantly share code, notes, and snippets.

@snichme
Created May 26, 2025 14:38
Show Gist options
  • Save snichme/a2bfe7bd5893a44cb822bab313e5f956 to your computer and use it in GitHub Desktop.
Save snichme/a2bfe7bd5893a44cb822bab313e5f956 to your computer and use it in GitHub Desktop.
import pika
import json
LAVINMQ_HOST = "ada-workshop.rmq6.cloudamqp.com"
USERNAME = "workshop"
PASSWORD = "workshop"
VHOST = "ws"
QUEUE_NAME = "mange_booking_requests"
credentials = pika.PlainCredentials(USERNAME, PASSWORD)
connection = pika.BlockingConnection(pika.ConnectionParameters(
host=LAVINMQ_HOST,
virtual_host=VHOST,
credentials=credentials
))
channel = connection.channel()
def callback(ch, method, properties, body):
print(f"Received: {body.decode()}", flush=True)
json_obj = json.loads(body)
json_obj["distance"] = 5000
ch.basic_publish(exchange='', routing_key='mange_bookings', body=json.dumps(json_obj))
channel.queue_declare(queue='mange_bookings', durable=True)
channel.queue_declare(queue='mange_booking_requests', durable=True)
print("Waiting")
channel.basic_consume(queue='mange_booking_requests', on_message_callback=callback, auto_ack=True)
channel.start_consuming()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment