コード例 #1
0
def send_to_frontend(queue_name, response_message, request_id):
    try:
        Connection.channel.queue_declare(queue_name)
        msg_json = {
            'requestId': request_id,
            'result': response_message
        }
        print("\n================================== RESPONSE MESSAGE ==================================\n"
              + json.dumps(msg_json, indent=2) + "\n"
              "======================================================================================\n")
        Connection.channel.basic_publish(exchange='', routing_key=queue_name, body=json.dumps(msg_json))
        return True
    except StreamLostError:
        Connection.connect_to_rabbitmq()
        return False
コード例 #2
0
        else:
            print(op + " not succeeded")

    else:
        msg = "Error: operation not valid"
        print(msg)
        send_to_frontend(queue_name, msg, request_id)
    print("================================== Waiting for task message ==================================")


print("Initializing parameters...")
Config.initialize_parameters()
print("Parameters initialized")

print("Connecting to RabbitMQ...")
Connection.connect_to_rabbitmq()
print("Connection to RabbitMQ succeeded")

print("Connecting to the Database...")


db = DatabaseManager(Config.mysql_address, Config.mysql_db, Config.mysql_user, Config.mysql_pwd)
if db.isConnected() is False:
    print("Error database connection")
else:
    print("Connection to the Database succeeded")
    Connection.channel.queue_declare('tasks')
    Connection.channel.basic_consume(queue='tasks', on_message_callback=callback, auto_ack=True)
    print("Start consuming")
    print("================================== Waiting for task message ==================================")
    Connection.channel.start_consuming()