import pika

EXCHANGE_NAME = 'inhub'
EXCHANGE_TYPE = 'direct'
ROUTING_KEY = 'trace-retrieval'

connection = pika.BlockingConnection(pika.ConnectionParameters('143.205.173.36', 30302, heartbeat=60, blocked_connection_timeout=30))
channel = connection.channel()

channel.exchange_declare(exchange=EXCHANGE_NAME, exchange_type=EXCHANGE_TYPE)
result = channel.queue_declare(queue=ROUTING_KEY, exclusive=False, auto_delete=False)
queue_name = result.method.queue
channel.queue_bind(exchange=EXCHANGE_NAME, queue=queue_name, routing_key=ROUTING_KEY)

def callback(ch, method, properties, body):
    print(f"### Received: {body}")
    ch.basic_ack(delivery_tag=method.delivery_tag)

channel.basic_consume(queue=queue_name,
                        auto_ack=False,
                        on_message_callback=callback)

channel.start_consuming()
