fuCtor / QAMQP

AMQP implementation for Qt
Other
28 stars 3 forks source link

NOTICE

Project moved to https://github.com/mbroadst/qamqp

QAMQP

Qt4/Qt5 implementation of AMQP 0.9.1.

Implement

Connection

work with socket connections

Channel

work with channels

Exchange

work with exchanges

Queue

work with queues

Basic

work with basic content

Usage

Test::Test()    
{
    QUrl con(QString("amqp://guest:guest@localhost:5672/"));
    client_ = new QAMQP::Client(this);
    connect(client_, SIGNAL(connected()), this, SLOT(connected()));
    client_->open(con);
    exchange_ =  client_->createExchange("test.test2");
    queue_ = client_->createQueue("test.my_queue", exchange_->channelNumber());

    connect(queue_, SIGNAL(declared()), this, SLOT(declared()));
    connect(queue_, SIGNAL(messageReceived(QAMQP::Queue * )), this, SLOT(newMessage(QAMQP::Queue *)));  

}

void Test::connected()
{
    exchange_->declare("fanout");       
    queue_->declare();
    exchange_->bind(queue_);
}

void Test::declared()
{
    exchange_->publish("Hello world", exchange_->name());
    queue_->setQOS(0,10);
    queue_->setConsumerTag("qamqp-consumer");
    queue_->consume(QAMQP::Queue::coNoAck);
}

void Test::newMessage(QAMQP::Queue * q)
{
    while (q->hasMessage())
    {
        QAMQP::MessagePtr message = q->getMessage();
        qDebug("+ RECEIVE MESSAGE");
        qDebug("| Exchange-name: %s", qPrintable(message->exchangeName));
        qDebug("| Routing-key: %s", qPrintable(message->routeKey));
        qDebug("| Content-type: %s", qPrintable(message->property[QAMQP::Frame::Content::cpContentType].toString()));
        if(!q->noAck())
        {
            q->ack(message);
        }
    }
}

Credits

Thank you @mdhooge for tutorials inspired by https://github.com/jonnydee/nzmqt

githalytics.com alpha