QT and AMQP-CPP sample



  • Hi,

    We try to integrate https://github.com/CopernicaMarketingSoftware/AMQP-CPP AMQP-CPP with QT

    in the pro file:

    LIBS +=-L/usr/local/lib/ -lamqpcpp -ldl -lev
    INCLUDEPATH += /usr/local/include/amqpcpp
    INCLUDEPATH += /usr/local/opt/openssl/include

    so all is good for building.

    I create a thread with movetothread :

    mongoUpdate::mongoUpdate(QObject *parent) :
    
        QObject(parent)
    {
        // create event loop
            auto *loop = EV_DEFAULT;
    
            // construct handler
            AMQP::LibEvHandler handler(loop);
    
            // create tcp connection
            AMQP::TcpConnection Aconnection(&handler, AMQP::Address("amqp://alpullu:alpullu@192.168.1.103/"));
    
            // create a channel
            AMQP::TcpChannel channel(&Aconnection);
            channel.onReady([&channel]() {
    
                    // declare an exchange
                    channel.declareExchange("myexchange");
    
                    // create aqueue
                    channel.declareQueue("myqueue");
    
                    // bind exchange to queue
                    channel.bindQueue("myexchange", "zalpullu", "routingkey");
                    for(int i = 0; i < 10; i++)
                            {
                                // publish and sleep to highlight the problem
                                channel.publish("myexchange", "routingkey", "hello-alpullu");
                            }
    });
            // declare an exchange
            channel.declareExchange("myexchange");
    
            // create aqueue
            channel.declareQueue("myqueue");
    
            // bind exchange to queue
            channel.bindQueue("myexchange", "zalpullu", "routingkey");
            for(int i = 0; i < 10; i++)
                    {
                        // publish and sleep to highlight the problem
                        channel.publish("myexchange", "routingkey", "hello-alpullu");
                    }
    

    I try to make a thread and connect through signal slot mechanism to send amqp message (rabbitMQ).

    it is not worked. not send the example message.

    Is there a simple QT project for AMQP-CPP to start working.?

    thanks


  • Moderators

    @RahibeMeryem I don't see any call to moveToThread and I don't see any connect() calls...



  • movethrrad and the connect already in place. Working .

    I didt put here to make the code bigger.



  • @RahibeMeryem is a simpler Qt application (i.e. console app with all AMQP-CPP related code just in main.cpp) working fine?
    I'd create an Qt app based on examples from AMQP-CPP to be sure everything fits before jumping into the turbulent waters of threading...



  • Hi @Pablo-J.-Rogina,

    I'm not at all familiar with this library, but have worked quite a bit with the protocol.

    Not sure if this is the issue (or maybe just one of others), but where you have:

    // create aqueue
    channel.declareQueue("myqueue");
    
    // bind exchange to queue
    channel.bindQueue("myexchange", "zalpullu", "routingkey");
    

    You're binding a zalpullu queue, which is not the same as the queue you just created ('myqueue`) - was that the intention?

    Also, have you considered https://github.com/mbroadst/qamqp ? I haven't used it myself, but might be easier to integrate with a Qt project.

    Cheers.



  • @Paul-Colby said in QT and AMQP-CPP sample:

    https://github.com/mbroadst/qamqp

    yes I already fixed after saw. AMQP-cpp using some kind of event handler to execute publish message. libev, libuv etc.

    I am not so friendly with them :).

    I nevet thouht that its so hard to communicate with rabbitMQ :(. In scala/java we have lived in a hevan :)



  • @RahibeMeryem please don't forget to mark your post as solved if your issue is done. Thanks.



  • Still not solved.

    Couldnt find a way to work / example AMQP-CPP through QT threads


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.