diff --git a/qamqp.pro b/qamqp.pro index ddb7595..ca0e9c3 100644 --- a/qamqp.pro +++ b/qamqp.pro @@ -1,4 +1,5 @@ TEMPLATE = subdirs SUBDIRS += src \ - tests + tests \ + tutorials CONFIG += ordered diff --git a/tutorials/helloworld/helloworld.pro b/tutorials/helloworld/helloworld.pro new file mode 100644 index 0000000..bb957d8 --- /dev/null +++ b/tutorials/helloworld/helloworld.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = \ + send \ + receive diff --git a/tutorials/helloworld/receive/main.cpp b/tutorials/helloworld/receive/main.cpp new file mode 100644 index 0000000..1d9db0c --- /dev/null +++ b/tutorials/helloworld/receive/main.cpp @@ -0,0 +1,60 @@ +#include +#include + +#include "amqp_client.h" +#include "amqp_exchange.h" +#include "amqp_queue.h" +using namespace QAMQP; + +class Receiver : public QObject +{ + Q_OBJECT +public: + Receiver(QObject *parent = 0) : QObject(parent) {} + +public Q_SLOTS: + void start() { + connect(&m_client, SIGNAL(connected()), this, SLOT(clientConnected())); + m_client.connectToHost(); + } + +private Q_SLOTS: + void clientConnected() { + Queue *queue = m_client.createQueue("hello"); + connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared())); + queue->declare(); + } + + void queueDeclared() { + Queue *queue = qobject_cast(sender()); + if (!queue) + return; + + connect(queue, SIGNAL(messageReceived()), this, SLOT(messageReceived())); + queue->consume(Queue::coNoAck); + qDebug() << " [*] Waiting for messages. To exit press CTRL+C"; + } + + void messageReceived() { + Queue *queue = qobject_cast(sender()); + if (!queue) + return; + + Message message = queue->dequeue(); + qDebug() << " [x] Received " << message.payload(); + } + +private: + Client m_client; + +}; + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + Receiver receiver; + receiver.start(); + return app.exec(); +} + +#include "main.moc" diff --git a/tutorials/helloworld/receive/receive.pro b/tutorials/helloworld/receive/receive.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/helloworld/receive/receive.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/helloworld/send/main.cpp b/tutorials/helloworld/send/main.cpp new file mode 100644 index 0000000..73f3661 --- /dev/null +++ b/tutorials/helloworld/send/main.cpp @@ -0,0 +1,52 @@ +#include +#include +#include + +#include "amqp_client.h" +#include "amqp_exchange.h" +#include "amqp_queue.h" +using namespace QAMQP; + +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())); + m_client.connectToHost(); + } + +private Q_SLOTS: + void clientConnected() { + Queue *queue = m_client.createQueue("hello"); + connect(queue, SIGNAL(declared()), this, SLOT(queueDeclared())); + queue->declare(); + } + + void queueDeclared() { + Queue *queue = qobject_cast(sender()); + if (!queue) + return; + Exchange *defaultExchange = m_client.createExchange(); + defaultExchange->publish("Hello World!", "hello"); + qDebug() << " [x] Sent 'Hello World!'"; + QTimer::singleShot(25, qApp, SLOT(quit())); + } + +private: + Client m_client; + +}; + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + Sender sender; + sender.start(); + return app.exec(); +} + +#include "main.moc" diff --git a/tutorials/helloworld/send/send.pro b/tutorials/helloworld/send/send.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/helloworld/send/send.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/pubsub/emit_log/emit_log.pro b/tutorials/pubsub/emit_log/emit_log.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/pubsub/emit_log/emit_log.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/pubsub/emit_log/main.cpp b/tutorials/pubsub/emit_log/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/pubsub/emit_log/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/pubsub/pubsub.pro b/tutorials/pubsub/pubsub.pro new file mode 100644 index 0000000..95d33dc --- /dev/null +++ b/tutorials/pubsub/pubsub.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = \ + receive_logs \ + emit_log diff --git a/tutorials/pubsub/receive_logs/main.cpp b/tutorials/pubsub/receive_logs/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/pubsub/receive_logs/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/pubsub/receive_logs/receive_logs.pro b/tutorials/pubsub/receive_logs/receive_logs.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/pubsub/receive_logs/receive_logs.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/routing/emit_log_direct/emit_log_direct.pro b/tutorials/routing/emit_log_direct/emit_log_direct.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/routing/emit_log_direct/emit_log_direct.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/routing/emit_log_direct/main.cpp b/tutorials/routing/emit_log_direct/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/routing/emit_log_direct/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/routing/receive_logs_direct/main.cpp b/tutorials/routing/receive_logs_direct/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/routing/receive_logs_direct/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/routing/receive_logs_direct/receive_logs_direct.pro b/tutorials/routing/receive_logs_direct/receive_logs_direct.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/routing/receive_logs_direct/receive_logs_direct.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/routing/routing.pro b/tutorials/routing/routing.pro new file mode 100644 index 0000000..c15c8db --- /dev/null +++ b/tutorials/routing/routing.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = \ + emit_log_direct \ + receive_logs_direct diff --git a/tutorials/rpc/rpc.pro b/tutorials/rpc/rpc.pro new file mode 100644 index 0000000..6216eb1 --- /dev/null +++ b/tutorials/rpc/rpc.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = \ + rpc_server \ + rpc_client diff --git a/tutorials/rpc/rpc_client/main.cpp b/tutorials/rpc/rpc_client/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/rpc/rpc_client/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/rpc/rpc_client/rpc_client.pro b/tutorials/rpc/rpc_client/rpc_client.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/rpc/rpc_client/rpc_client.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/rpc/rpc_server/main.cpp b/tutorials/rpc/rpc_server/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/rpc/rpc_server/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/rpc/rpc_server/rpc_server.pro b/tutorials/rpc/rpc_server/rpc_server.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/rpc/rpc_server/rpc_server.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/topics/emit_log_topic/emit_log_topic.pro b/tutorials/topics/emit_log_topic/emit_log_topic.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/topics/emit_log_topic/emit_log_topic.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/topics/emit_log_topic/main.cpp b/tutorials/topics/emit_log_topic/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/topics/emit_log_topic/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/topics/receive_logs_topic/main.cpp b/tutorials/topics/receive_logs_topic/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/topics/receive_logs_topic/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/topics/receive_logs_topic/receive_logs_topic.pro b/tutorials/topics/receive_logs_topic/receive_logs_topic.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/topics/receive_logs_topic/receive_logs_topic.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/topics/topics.pro b/tutorials/topics/topics.pro new file mode 100644 index 0000000..bd429e4 --- /dev/null +++ b/tutorials/topics/topics.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = \ + emit_log_topic \ + receive_logs_topic diff --git a/tutorials/tutorials.pro b/tutorials/tutorials.pro new file mode 100644 index 0000000..55f979e --- /dev/null +++ b/tutorials/tutorials.pro @@ -0,0 +1,8 @@ +TEMPLATE = subdirs +SUBDIRS = \ + helloworld \ + workqueues \ + pubsub \ + routing \ + topics \ + rpc diff --git a/tutorials/workqueues/new_task/main.cpp b/tutorials/workqueues/new_task/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/workqueues/new_task/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/workqueues/new_task/new_task.pro b/tutorials/workqueues/new_task/new_task.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/workqueues/new_task/new_task.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/workqueues/worker/main.cpp b/tutorials/workqueues/worker/main.cpp new file mode 100644 index 0000000..9c5f00c --- /dev/null +++ b/tutorials/workqueues/worker/main.cpp @@ -0,0 +1,9 @@ +#include +#include + +int main(int argc, char **argv) +{ + QCoreApplication app(argc, argv); + qDebug() << "testing"; + return EXIT_SUCCESS; +} diff --git a/tutorials/workqueues/worker/worker.pro b/tutorials/workqueues/worker/worker.pro new file mode 100644 index 0000000..6222eec --- /dev/null +++ b/tutorials/workqueues/worker/worker.pro @@ -0,0 +1,9 @@ +DEPTH = ../../.. +include($${DEPTH}/qamqp.pri) + +TEMPLATE = app +INCLUDEPATH += $${QAMQP_INCLUDEPATH} +LIBS += -L$${DEPTH}/src $${QAMQP_LIBS} +macx:CONFIG -= app_bundle + +SOURCES += main.cpp diff --git a/tutorials/workqueues/workqueues.pro b/tutorials/workqueues/workqueues.pro new file mode 100644 index 0000000..3f51159 --- /dev/null +++ b/tutorials/workqueues/workqueues.pro @@ -0,0 +1,4 @@ +TEMPLATE = subdirs +SUBDIRS = \ + new_task \ + worker