2014-05-29 00:25:28 +08:00
|
|
|
#include "amqp_queue.h"
|
|
|
|
|
#include "amqp_queue_p.h"
|
|
|
|
|
#include "amqp_exchange.h"
|
2014-06-06 03:34:08 +08:00
|
|
|
#include "amqp_message_p.h"
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
using namespace QAMQP;
|
|
|
|
|
|
|
|
|
|
#include <QCoreApplication>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QDataStream>
|
|
|
|
|
#include <QFile>
|
|
|
|
|
|
2014-06-04 21:46:15 +08:00
|
|
|
QueuePrivate::QueuePrivate(Queue *q)
|
|
|
|
|
: ChannelPrivate(q),
|
|
|
|
|
delayedDeclare(false),
|
|
|
|
|
declared(false),
|
|
|
|
|
noAck(true),
|
2014-06-24 22:30:05 +08:00
|
|
|
recievingMessage(false),
|
|
|
|
|
consuming(false)
|
2014-06-04 21:46:15 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QueuePrivate::~QueuePrivate()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool QueuePrivate::_q_method(const Frame::Method &frame)
|
|
|
|
|
{
|
|
|
|
|
Q_Q(Queue);
|
|
|
|
|
if (ChannelPrivate::_q_method(frame))
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
if (frame.methodClass() == Frame::fcQueue) {
|
|
|
|
|
switch (frame.id()) {
|
|
|
|
|
case miDeclareOk:
|
|
|
|
|
declareOk(frame);
|
|
|
|
|
break;
|
2014-06-07 00:10:51 +08:00
|
|
|
case miDeleteOk:
|
2014-06-04 21:46:15 +08:00
|
|
|
deleteOk(frame);
|
|
|
|
|
break;
|
|
|
|
|
case miBindOk:
|
|
|
|
|
bindOk(frame);
|
|
|
|
|
break;
|
|
|
|
|
case miUnbindOk:
|
|
|
|
|
unbindOk(frame);
|
|
|
|
|
break;
|
|
|
|
|
case miPurgeOk:
|
2014-06-11 01:04:57 +08:00
|
|
|
purgeOk(frame);
|
2014-06-04 21:46:15 +08:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (frame.methodClass() == Frame::fcBasic) {
|
|
|
|
|
switch(frame.id()) {
|
|
|
|
|
case bmConsumeOk:
|
|
|
|
|
consumeOk(frame);
|
|
|
|
|
break;
|
|
|
|
|
case bmDeliver:
|
|
|
|
|
deliver(frame);
|
|
|
|
|
break;
|
|
|
|
|
case bmGetOk:
|
|
|
|
|
getOk(frame);
|
|
|
|
|
break;
|
|
|
|
|
case bmGetEmpty:
|
|
|
|
|
Q_EMIT q->empty();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-06-11 01:04:57 +08:00
|
|
|
|
2014-06-04 21:46:15 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QueuePrivate::_q_content(const Frame::Content &frame)
|
|
|
|
|
{
|
2014-06-04 21:50:31 +08:00
|
|
|
Q_ASSERT(frame.channel() == channelNumber);
|
|
|
|
|
if (frame.channel() != channelNumber)
|
2014-06-04 21:46:15 +08:00
|
|
|
return;
|
|
|
|
|
|
2014-06-19 22:01:47 +08:00
|
|
|
if (!currentMessage.isValid()) {
|
|
|
|
|
qAmqpDebug() << "received content-header without delivered message";
|
2014-06-04 21:46:15 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 22:01:47 +08:00
|
|
|
currentMessage.d->leftSize = frame.bodySize();
|
2014-06-04 21:46:15 +08:00
|
|
|
QHash<int, QVariant>::ConstIterator it;
|
|
|
|
|
QHash<int, QVariant>::ConstIterator itEnd = frame.properties_.constEnd();
|
|
|
|
|
for (it = frame.properties_.constBegin(); it != itEnd; ++it)
|
2014-06-19 22:01:47 +08:00
|
|
|
currentMessage.d->properties[MessageProperty(it.key())] = it.value();
|
2014-06-04 21:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QueuePrivate::_q_body(const Frame::ContentBody &frame)
|
|
|
|
|
{
|
|
|
|
|
Q_Q(Queue);
|
2014-06-04 21:50:31 +08:00
|
|
|
Q_ASSERT(frame.channel() == channelNumber);
|
|
|
|
|
if (frame.channel() != channelNumber)
|
2014-06-04 21:46:15 +08:00
|
|
|
return;
|
|
|
|
|
|
2014-06-19 22:01:47 +08:00
|
|
|
if (!currentMessage.isValid()) {
|
|
|
|
|
qAmqpDebug() << "received content-body without delivered message";
|
2014-06-04 21:46:15 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-19 22:01:47 +08:00
|
|
|
currentMessage.d->payload.append(frame.body());
|
|
|
|
|
currentMessage.d->leftSize -= frame.body().size();
|
|
|
|
|
if (currentMessage.d->leftSize == 0) {
|
|
|
|
|
q->enqueue(currentMessage);
|
2014-06-06 03:40:17 +08:00
|
|
|
Q_EMIT q->messageReceived();
|
2014-06-19 22:01:47 +08:00
|
|
|
}
|
2014-06-04 21:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QueuePrivate::declareOk(const Frame::Method &frame)
|
|
|
|
|
{
|
|
|
|
|
Q_Q(Queue);
|
2014-06-19 22:01:47 +08:00
|
|
|
qAmqpDebug() << "declared queue: " << name;
|
2014-06-04 21:46:15 +08:00
|
|
|
declared = true;
|
|
|
|
|
|
|
|
|
|
QByteArray data = frame.arguments();
|
|
|
|
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
|
|
name = Frame::readField('s', stream).toString();
|
|
|
|
|
qint32 messageCount = 0, consumerCount = 0;
|
|
|
|
|
stream >> messageCount >> consumerCount;
|
2014-06-19 22:01:47 +08:00
|
|
|
qAmqpDebug("message count %d\nConsumer count: %d", messageCount, consumerCount);
|
2014-06-04 21:46:15 +08:00
|
|
|
|
|
|
|
|
Q_EMIT q->declared();
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-11 01:04:57 +08:00
|
|
|
void QueuePrivate::purgeOk(const Frame::Method &frame)
|
|
|
|
|
{
|
|
|
|
|
Q_Q(Queue);
|
|
|
|
|
qAmqpDebug() << "purged queue: " << name;
|
|
|
|
|
|
|
|
|
|
QByteArray data = frame.arguments();
|
|
|
|
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
|
|
|
|
|
|
|
|
|
qint32 messageCount = 0;
|
|
|
|
|
stream >> messageCount;
|
|
|
|
|
|
|
|
|
|
Q_EMIT q->purged(messageCount);
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-04 21:46:15 +08:00
|
|
|
void QueuePrivate::deleteOk(const Frame::Method &frame)
|
|
|
|
|
{
|
|
|
|
|
Q_Q(Queue);
|
2014-06-11 01:04:57 +08:00
|
|
|
qAmqpDebug() << "deleted queue: " << name;
|
2014-06-04 21:46:15 +08:00
|
|
|
declared = false;
|
|
|
|
|
|
|
|
|
|
QByteArray data = frame.arguments();
|
|
|
|
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
|
|
|
|
qint32 messageCount = 0;
|
|
|
|
|
stream >> messageCount;
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug("Message count %d", messageCount);
|
2014-06-04 21:46:15 +08:00
|
|
|
|
|
|
|
|
Q_EMIT q->removed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QueuePrivate::bindOk(const Frame::Method &frame)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(frame)
|
|
|
|
|
|
|
|
|
|
Q_Q(Queue);
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "bound to exchange";
|
2014-06-04 21:46:15 +08:00
|
|
|
Q_EMIT q->bound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QueuePrivate::unbindOk(const Frame::Method &frame)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(frame)
|
|
|
|
|
|
|
|
|
|
Q_Q(Queue);
|
2014-06-19 22:01:47 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "unbound from exchange";
|
2014-06-04 21:46:15 +08:00
|
|
|
Q_EMIT q->unbound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QueuePrivate::getOk(const Frame::Method &frame)
|
|
|
|
|
{
|
|
|
|
|
QByteArray data = frame.arguments();
|
|
|
|
|
QDataStream in(&data, QIODevice::ReadOnly);
|
|
|
|
|
|
2014-06-06 03:34:08 +08:00
|
|
|
Message message;
|
|
|
|
|
message.d->deliveryTag = Frame::readField('L',in).toLongLong();
|
|
|
|
|
message.d->redelivered = Frame::readField('t',in).toBool();
|
|
|
|
|
message.d->exchangeName = Frame::readField('s',in).toString();
|
|
|
|
|
message.d->routingKey = Frame::readField('s',in).toString();
|
2014-06-19 22:01:47 +08:00
|
|
|
currentMessage = message;
|
2014-06-04 21:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QueuePrivate::consumeOk(const Frame::Method &frame)
|
|
|
|
|
{
|
2014-06-24 22:30:05 +08:00
|
|
|
Q_Q(Queue);
|
2014-06-19 22:01:47 +08:00
|
|
|
qAmqpDebug() << "consume ok: " << name;
|
2014-06-04 21:46:15 +08:00
|
|
|
QByteArray data = frame.arguments();
|
|
|
|
|
QDataStream stream(&data, QIODevice::ReadOnly);
|
2014-06-24 22:30:05 +08:00
|
|
|
consumerTag = Frame::readField('s',stream).toString();
|
2014-06-19 22:01:47 +08:00
|
|
|
qAmqpDebug("consumer tag = %s", qPrintable(consumerTag));
|
2014-06-24 22:30:05 +08:00
|
|
|
consuming = true;
|
|
|
|
|
Q_EMIT q->consuming(consumerTag);
|
2014-06-04 21:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void QueuePrivate::deliver(const Frame::Method &frame)
|
|
|
|
|
{
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO;
|
2014-06-04 21:46:15 +08:00
|
|
|
QByteArray data = frame.arguments();
|
|
|
|
|
QDataStream in(&data, QIODevice::ReadOnly);
|
2014-06-19 22:01:47 +08:00
|
|
|
QString consumer = Frame::readField('s',in).toString();
|
2014-06-24 22:30:05 +08:00
|
|
|
if (consumerTag != consumer) {
|
2014-06-19 22:01:47 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "invalid consumer tag: " << consumer;
|
2014-06-04 21:46:15 +08:00
|
|
|
return;
|
2014-06-06 03:34:08 +08:00
|
|
|
}
|
2014-06-04 21:46:15 +08:00
|
|
|
|
2014-06-06 03:34:08 +08:00
|
|
|
Message message;
|
|
|
|
|
message.d->deliveryTag = Frame::readField('L',in).toLongLong();
|
|
|
|
|
message.d->redelivered = Frame::readField('t',in).toBool();
|
|
|
|
|
message.d->exchangeName = Frame::readField('s',in).toString();
|
|
|
|
|
message.d->routingKey = Frame::readField('s',in).toString();
|
2014-06-19 22:01:47 +08:00
|
|
|
currentMessage = message;
|
2014-06-04 21:46:15 +08:00
|
|
|
}
|
|
|
|
|
|
2014-06-07 00:10:51 +08:00
|
|
|
void QueuePrivate::declare()
|
|
|
|
|
{
|
|
|
|
|
Frame::Method frame(Frame::fcQueue, QueuePrivate::miDeclare);
|
|
|
|
|
frame.setChannel(channelNumber);
|
|
|
|
|
|
|
|
|
|
QByteArray arguments;
|
|
|
|
|
QDataStream out(&arguments, QIODevice::WriteOnly);
|
|
|
|
|
|
|
|
|
|
out << qint16(0); //reserved 1
|
|
|
|
|
Frame::writeField('s', out, name);
|
|
|
|
|
out << qint8(options);
|
|
|
|
|
Frame::writeField('F', out, Frame::TableField());
|
|
|
|
|
|
|
|
|
|
frame.setArguments(arguments);
|
|
|
|
|
sendFrame(frame);
|
|
|
|
|
|
|
|
|
|
if (delayedDeclare)
|
|
|
|
|
delayedDeclare = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2014-06-04 21:46:15 +08:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
Queue::Queue(int channelNumber, Client *parent)
|
|
|
|
|
: Channel(new QueuePrivate(this), parent)
|
|
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-29 00:25:28 +08:00
|
|
|
d->init(channelNumber, parent);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Queue::~Queue()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-04 01:00:25 +08:00
|
|
|
void Queue::channelOpened()
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-29 00:25:28 +08:00
|
|
|
if (d->delayedDeclare)
|
2014-06-07 00:10:51 +08:00
|
|
|
d->declare();
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
if (!d->delayedBindings.isEmpty()) {
|
|
|
|
|
typedef QPair<QString, QString> BindingPair;
|
|
|
|
|
foreach(BindingPair binding, d->delayedBindings)
|
2014-05-31 03:20:57 +08:00
|
|
|
bind(binding.first, binding.second);
|
2014-05-29 00:25:28 +08:00
|
|
|
d->delayedBindings.clear();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-04 01:00:25 +08:00
|
|
|
void Queue::channelClosed()
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-07 00:10:51 +08:00
|
|
|
int Queue::options() const
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(const Queue);
|
2014-05-29 00:25:28 +08:00
|
|
|
return d->options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Queue::setNoAck(bool noAck)
|
|
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-29 00:25:28 +08:00
|
|
|
d->noAck = noAck;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Queue::noAck() const
|
|
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(const Queue);
|
2014-05-29 00:25:28 +08:00
|
|
|
return d->noAck;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-07 01:37:36 +08:00
|
|
|
void Queue::declare(int options)
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-29 00:25:28 +08:00
|
|
|
d->options = options;
|
2014-05-31 03:36:11 +08:00
|
|
|
|
|
|
|
|
if (!d->opened) {
|
|
|
|
|
d->delayedDeclare = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-06-07 00:10:51 +08:00
|
|
|
d->declare();
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
2014-06-07 00:10:51 +08:00
|
|
|
void Queue::remove(int options)
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-31 03:36:11 +08:00
|
|
|
if (!d->declared) {
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "trying to remove undeclared queue, aborting...";
|
2014-05-31 03:36:11 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Frame::Method frame(Frame::fcQueue, QueuePrivate::miDelete);
|
2014-06-04 21:50:31 +08:00
|
|
|
frame.setChannel(d->channelNumber);
|
2014-05-31 03:36:11 +08:00
|
|
|
|
|
|
|
|
QByteArray arguments;
|
|
|
|
|
QDataStream out(&arguments, QIODevice::WriteOnly);
|
|
|
|
|
|
2014-06-06 03:34:08 +08:00
|
|
|
out << qint16(0); //reserved 1
|
2014-05-31 03:36:11 +08:00
|
|
|
Frame::writeField('s', out, d->name);
|
2014-06-07 00:10:51 +08:00
|
|
|
out << qint8(options);
|
2014-05-31 03:36:11 +08:00
|
|
|
|
|
|
|
|
frame.setArguments(arguments);
|
|
|
|
|
d->sendFrame(frame);
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Queue::purge()
|
|
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-31 02:51:44 +08:00
|
|
|
|
|
|
|
|
if (!d->opened)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Frame::Method frame(Frame::fcQueue, QueuePrivate::miPurge);
|
2014-06-04 21:50:31 +08:00
|
|
|
frame.setChannel(d->channelNumber);
|
2014-05-31 02:51:44 +08:00
|
|
|
|
|
|
|
|
QByteArray arguments;
|
|
|
|
|
QDataStream out(&arguments, QIODevice::WriteOnly);
|
2014-06-06 03:34:08 +08:00
|
|
|
out << qint16(0); //reserved 1
|
2014-05-31 02:51:44 +08:00
|
|
|
Frame::writeField('s', out, d->name);
|
|
|
|
|
out << qint8(0); // no-wait
|
|
|
|
|
|
2014-06-07 01:37:36 +08:00
|
|
|
frame.setArguments(arguments);
|
2014-05-31 02:51:44 +08:00
|
|
|
d->sendFrame(frame);
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
2014-05-31 03:20:57 +08:00
|
|
|
void Queue::bind(Exchange *exchange, const QString &key)
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-31 03:20:57 +08:00
|
|
|
if (!exchange) {
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "invalid exchange provided";
|
2014-05-31 03:20:57 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bind(exchange->name(), key);
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
2014-05-31 03:20:57 +08:00
|
|
|
void Queue::bind(const QString &exchangeName, const QString &key)
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-31 03:20:57 +08:00
|
|
|
if (!d->opened) {
|
|
|
|
|
d->delayedBindings.append(QPair<QString,QString>(exchangeName, key));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Frame::Method frame(Frame::fcQueue, QueuePrivate::miBind);
|
2014-06-04 21:50:31 +08:00
|
|
|
frame.setChannel(d->channelNumber);
|
2014-05-31 03:20:57 +08:00
|
|
|
|
|
|
|
|
QByteArray arguments;
|
|
|
|
|
QDataStream out(&arguments, QIODevice::WriteOnly);
|
|
|
|
|
|
2014-06-07 01:37:36 +08:00
|
|
|
out << qint16(0); // reserved 1
|
2014-05-31 03:20:57 +08:00
|
|
|
Frame::writeField('s', out, d->name);
|
|
|
|
|
Frame::writeField('s', out, exchangeName);
|
|
|
|
|
Frame::writeField('s', out, key);
|
|
|
|
|
|
2014-06-07 01:37:36 +08:00
|
|
|
out << qint8(0); // no-wait
|
2014-05-31 03:20:57 +08:00
|
|
|
Frame::writeField('F', out, Frame::TableField());
|
|
|
|
|
|
|
|
|
|
frame.setArguments(arguments);
|
|
|
|
|
d->sendFrame(frame);
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
2014-05-31 03:20:57 +08:00
|
|
|
void Queue::unbind(Exchange *exchange, const QString &key)
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-31 03:20:57 +08:00
|
|
|
if (!exchange) {
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "invalid exchange provided";
|
2014-05-31 03:20:57 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unbind(exchange->name(), key);
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
2014-05-31 03:20:57 +08:00
|
|
|
void Queue::unbind(const QString &exchangeName, const QString &key)
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-31 03:20:57 +08:00
|
|
|
if (!d->opened) {
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "queue is not open";
|
2014-05-31 03:20:57 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Frame::Method frame(Frame::fcQueue, QueuePrivate::miUnbind);
|
2014-06-04 21:50:31 +08:00
|
|
|
frame.setChannel(d->channelNumber);
|
2014-05-31 03:20:57 +08:00
|
|
|
|
|
|
|
|
QByteArray arguments;
|
|
|
|
|
QDataStream out(&arguments, QIODevice::WriteOnly);
|
2014-06-06 03:34:08 +08:00
|
|
|
out << qint16(0); //reserved 1
|
2014-05-31 03:20:57 +08:00
|
|
|
Frame::writeField('s', out, d->name);
|
|
|
|
|
Frame::writeField('s', out, exchangeName);
|
|
|
|
|
Frame::writeField('s', out, key);
|
|
|
|
|
Frame::writeField('F', out, Frame::TableField());
|
|
|
|
|
|
|
|
|
|
frame.setArguments(arguments);
|
|
|
|
|
d->sendFrame(frame);
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
2014-06-24 22:30:05 +08:00
|
|
|
bool Queue::consume(int options)
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-31 03:10:55 +08:00
|
|
|
if (!d->opened) {
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "queue is not open";
|
2014-06-24 22:30:05 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (d->consuming) {
|
|
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "already consuming with tag: " << d->consumerTag;
|
|
|
|
|
return false;
|
2014-05-31 03:10:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmConsume);
|
2014-06-04 21:50:31 +08:00
|
|
|
frame.setChannel(d->channelNumber);
|
2014-05-31 03:10:55 +08:00
|
|
|
|
|
|
|
|
QByteArray arguments;
|
|
|
|
|
QDataStream out(&arguments, QIODevice::WriteOnly);
|
|
|
|
|
|
2014-06-06 03:34:08 +08:00
|
|
|
out << qint16(0); //reserved 1
|
2014-05-31 03:10:55 +08:00
|
|
|
Frame::writeField('s', out, d->name);
|
2014-06-24 22:30:05 +08:00
|
|
|
Frame::writeField('s', out, d->consumerTag);
|
2014-05-31 03:10:55 +08:00
|
|
|
|
2014-06-11 01:04:57 +08:00
|
|
|
out << qint8(options);
|
2014-05-31 03:10:55 +08:00
|
|
|
Frame::writeField('F', out, Frame::TableField());
|
|
|
|
|
|
|
|
|
|
frame.setArguments(arguments);
|
|
|
|
|
d->sendFrame(frame);
|
2014-06-24 22:30:05 +08:00
|
|
|
return true;
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Queue::setConsumerTag(const QString &consumerTag)
|
|
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-06-24 22:30:05 +08:00
|
|
|
d->consumerTag = consumerTag;
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString Queue::consumerTag() const
|
|
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(const Queue);
|
2014-06-24 22:30:05 +08:00
|
|
|
return d->consumerTag;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Queue::isConsuming() const
|
|
|
|
|
{
|
|
|
|
|
Q_D(const Queue);
|
|
|
|
|
return d->consuming;
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Queue::get()
|
|
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-31 03:10:55 +08:00
|
|
|
if (!d->opened) {
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "queue is not open";
|
2014-05-31 03:10:55 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmGet);
|
2014-06-04 21:50:31 +08:00
|
|
|
frame.setChannel(d->channelNumber);
|
2014-05-31 03:10:55 +08:00
|
|
|
|
|
|
|
|
QByteArray arguments;
|
|
|
|
|
QDataStream out(&arguments, QIODevice::WriteOnly);
|
|
|
|
|
|
2014-06-06 03:34:08 +08:00
|
|
|
out << qint16(0); //reserved 1
|
2014-05-31 03:10:55 +08:00
|
|
|
Frame::writeField('s', out, d->name);
|
|
|
|
|
|
2014-06-06 03:34:08 +08:00
|
|
|
out << qint8(d->noAck ? 1 : 0); // noAck
|
2014-05-31 03:10:55 +08:00
|
|
|
|
|
|
|
|
frame.setArguments(arguments);
|
|
|
|
|
d->sendFrame(frame);
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|
|
|
|
|
|
2014-06-06 03:34:08 +08:00
|
|
|
void Queue::ack(const Message &message)
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
2014-05-29 01:52:27 +08:00
|
|
|
Q_D(Queue);
|
2014-05-31 03:10:55 +08:00
|
|
|
if (!d->opened) {
|
2014-06-07 01:46:08 +08:00
|
|
|
qAmqpDebug() << Q_FUNC_INFO << "queue is not open";
|
2014-05-31 03:10:55 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Frame::Method frame(Frame::fcBasic, QueuePrivate::bmAck);
|
2014-06-04 21:50:31 +08:00
|
|
|
frame.setChannel(d->channelNumber);
|
2014-05-31 03:10:55 +08:00
|
|
|
|
|
|
|
|
QByteArray arguments;
|
|
|
|
|
QDataStream out(&arguments, QIODevice::WriteOnly);
|
|
|
|
|
|
2014-06-06 03:34:08 +08:00
|
|
|
out << message.deliveryTag(); // reserved 1
|
|
|
|
|
out << qint8(0); // noAck
|
2014-05-31 03:10:55 +08:00
|
|
|
|
|
|
|
|
frame.setArguments(arguments);
|
|
|
|
|
d->sendFrame(frame);
|
2014-05-29 00:25:28 +08:00
|
|
|
}
|