show example of queued calls on QAmqpExchange

This gives an example of how you can use QMetaObject::invokeMethod to
call a QAmqpExchange from another thread. Also, moved the qRegisterMetaType
for QAmqpMessage::PropertyHash to the ctor of QAmqpClientPrivate
This commit is contained in:
Matt Broadstone 2015-02-27 09:13:17 -05:00
parent 4379e991c6
commit a4bc1b5f4e
3 changed files with 19 additions and 1 deletions

View File

@ -31,6 +31,7 @@ QAmqpClientPrivate::QAmqpClientPrivate(QAmqpClient *q)
error(QAMQP::NoError),
q_ptr(q)
{
qRegisterMetaType<QAmqpMessage::PropertyHash>();
}
QAmqpClientPrivate::~QAmqpClientPrivate()

View File

@ -7,7 +7,6 @@ QAmqpMessagePrivate::QAmqpMessagePrivate()
: deliveryTag(0),
leftSize(0)
{
qRegisterMetaType<QAmqpMessage::PropertyHash>("QAmqpMessage::PropertyHash");
}
//////////////////////////////////////////////////////////////////////////

View File

@ -27,6 +27,7 @@ private Q_SLOTS:
void confirmDontLoseMessages();
void passiveDeclareNotFound();
void cleanupOnDeletion();
void testQueuedPublish();
private:
QScopedPointer<QAmqpClient> client;
@ -217,5 +218,22 @@ void tst_QAMQPExchange::cleanupOnDeletion()
QVERIFY(waitForSignal(exchange, SIGNAL(closed())));
}
void tst_QAMQPExchange::testQueuedPublish()
{
QAmqpExchange *defaultExchange = client->createExchange();
defaultExchange->enableConfirms();
QVERIFY(waitForSignal(defaultExchange, SIGNAL(confirmsEnabled())));
QAmqpMessage::PropertyHash properties;
properties[QAmqpMessage::DeliveryMode] = "2"; // make message persistent
for (int i = 0; i < 10000; ++i) {
QMetaObject::invokeMethod(defaultExchange, "publish", Qt::QueuedConnection,
Q_ARG(QString, "noop"), Q_ARG(QString, "confirms-test"),
Q_ARG(QAmqpMessage::PropertyHash, properties));
}
QVERIFY(defaultExchange->waitForConfirms());
}
QTEST_MAIN(tst_QAMQPExchange)
#include "tst_qamqpexchange.moc"