2014-06-18 22:31:28 +08:00
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QTimer>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
|
2014-08-27 03:05:39 +08:00
|
|
|
#include "qamqpclient.h"
|
|
|
|
|
#include "qamqpexchange.h"
|
|
|
|
|
#include "qamqpqueue.h"
|
2014-06-18 22:31:28 +08:00
|
|
|
|
|
|
|
|
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()));
|
2014-06-18 23:06:49 +08:00
|
|
|
connect(&m_client, SIGNAL(disconnected()), qApp, SLOT(quit()));
|
2014-06-18 22:31:28 +08:00
|
|
|
m_client.connectToHost();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
|
void clientConnected() {
|
2014-09-15 23:51:48 +08:00
|
|
|
QAmqpQueue *queue = m_client.createQueue("hello");
|
2014-06-18 22:31:28 +08:00
|
|
|
connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared()));
|
|
|
|
|
queue->declare();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void queueDeclared() {
|
2014-09-15 23:51:48 +08:00
|
|
|
QAmqpQueue *queue = qobject_cast<QAmqpQueue*>(sender());
|
2014-06-18 22:31:28 +08:00
|
|
|
if (!queue)
|
|
|
|
|
return;
|
2014-09-15 23:51:48 +08:00
|
|
|
QAmqpExchange *defaultExchange = m_client.createExchange();
|
2025-07-31 17:17:40 +08:00
|
|
|
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'";
|
2014-06-18 23:06:49 +08:00
|
|
|
m_client.disconnectFromHost();
|
2014-06-18 22:31:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2014-09-15 23:51:48 +08:00
|
|
|
QAmqpClient m_client;
|
2014-06-18 22:31:28 +08:00
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
|
{
|
|
|
|
|
QCoreApplication app(argc, argv);
|
|
|
|
|
Sender sender;
|
|
|
|
|
sender.start();
|
|
|
|
|
return app.exec();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "main.moc"
|