Exemplo n.º 1
0
while True:
    disconnected1 = False
    disconnected2 = False

    print('checking producers presence...')
    time.sleep(3)

    channels=cl.get_channels()

    if not channels:
        disconnected1=True
        disconnected2=True
    elif not filter(lambda users: users['user'] == pri_prod, channels):
        disconnected1=True

    if disconnected1:
        print('producer ' + pri_prod + ' not connected, trying to switch to ' + sec_prod + '...')
        if not channels:
            disconnected2 = True
        elif not filter(lambda users: users['user'] == sec_prod, channels):
            disconnected2 = True

        if disconnected2:
            print('no producers available!')
        else:
            bindings=cl.get_queue_bindings('vhost1','q-adaas-top-1')

            print('producer ' + sec_prod + ' connected, switching to ' + sec_prod + '...')
            cl.create_binding(vhost='vhost1',exchange='ex-adaas-topic',queue="q-adaas-top-1",rt_key='top-2')

Exemplo n.º 2
0
                          exchange=a_exchange,
                          queue=a_Q1,
                          rt_key=a_key2)
    except http.HTTPError:
        print("no binding " + pub2 + " to " + a_Q1)

    try:
        cl.delete_binding(vhost=a_vhost,
                          exchange=a_exchange,
                          queue=a_Q2,
                          rt_key=a_key1)
    except http.HTTPError:
        print("no binding " + pub1 + " to " + a_Q2)

    cl.create_binding(vhost=a_vhost,
                      exchange=a_exchange,
                      queue=a_Q1,
                      rt_key=a_key1)
    cl.create_binding(vhost=a_vhost,
                      exchange=a_exchange,
                      queue=a_Q2,
                      rt_key=a_key2)

while True:
    pub1_conn = True
    pub2_conn = True

    print('checking publishers presence...')
    time.sleep(a_delay)

    channels = cl.get_channels()