events/send/main.cpp

61 lines
1.6 KiB
C++

#include <QCoreApplication>
#include <QTimer>
#include <QDebug>
#include "qamqpclient.h"
#include "qamqpexchange.h"
#include "qamqpqueue.h"
class Sender : public QObject
{
Q_OBJECT
public:
Sender(QObject *parent = 0) : QObject(parent) {}
public Q_SLOTS:
void start() {
connect(&m_client, SIGNAL(connected()), this, SLOT(clientConnected()));
connect(&m_client, SIGNAL(disconnected()), qApp, SLOT(quit()));
m_client.connectToHost();
}
private Q_SLOTS:
void clientConnected() {
QAmqpQueue *queue = m_client.createQueue("hello");
connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared()));
queue->declare();
}
void queueDeclared() {
QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
if (!queue)
return;
QAmqpExchange *defaultExchange = m_client.createExchange();
defaultExchange->publish("Hello World! A", "hello");
qDebug() << " [x] Sent 'Hello World! A'";
defaultExchange->publish("Hello World! B", "hello");
qDebug() << " [x] Sent 'Hello World! B'";
defaultExchange->publish("Hello World! C", "hello");
qDebug() << " [x] Sent 'Hello World! C'";
defaultExchange->publish("Hello World! D", "hello");
qDebug() << " [x] Sent 'Hello World! D'";
defaultExchange->publish("Hello World! E", "hello");
qDebug() << " [x] Sent 'Hello World! E'";
m_client.disconnectFromHost();
}
private:
QAmqpClient m_client;
};
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
Sender sender;
sender.start();
return app.exec();
}
#include "main.moc"