2015-02-10 02:45:05 +08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2012-2014 Alexey Shcherbakov
|
|
|
|
|
* Copyright (C) 2014-2015 Matt Broadstone
|
|
|
|
|
* Contact: https://github.com/mbroadst/qamqp
|
|
|
|
|
*
|
|
|
|
|
* This file is part of the QAMQP Library.
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
|
*/
|
2014-08-27 03:05:39 +08:00
|
|
|
#ifndef QAMQPQUEUE_H
|
|
|
|
|
#define QAMQPQUEUE_H
|
2014-05-29 00:25:28 +08:00
|
|
|
|
2014-06-10 21:05:42 +08:00
|
|
|
#include <QQueue>
|
|
|
|
|
|
2014-08-27 03:05:39 +08:00
|
|
|
#include "qamqpchannel.h"
|
|
|
|
|
#include "qamqpmessage.h"
|
|
|
|
|
#include "qamqpglobal.h"
|
2016-02-04 17:59:09 +08:00
|
|
|
#include "qamqptable.h"
|
2014-05-29 00:25:28 +08:00
|
|
|
|
2014-09-15 23:51:48 +08:00
|
|
|
class QAmqpClient;
|
|
|
|
|
class QAmqpClientPrivate;
|
|
|
|
|
class QAmqpExchange;
|
|
|
|
|
class QAmqpQueuePrivate;
|
|
|
|
|
class QAMQP_EXPORT QAmqpQueue : public QAmqpChannel, public QQueue<QAmqpMessage>
|
2014-05-29 00:25:28 +08:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
Q_ENUMS(QueueOptions)
|
2014-06-07 00:10:51 +08:00
|
|
|
Q_PROPERTY(int options READ options CONSTANT)
|
2014-05-29 00:25:28 +08:00
|
|
|
Q_PROPERTY(QString consumerTag READ consumerTag WRITE setConsumerTag)
|
2014-06-07 00:10:51 +08:00
|
|
|
Q_ENUMS(QueueOption)
|
|
|
|
|
Q_ENUMS(ConsumeOption)
|
|
|
|
|
Q_ENUMS(RemoveOption)
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
enum QueueOption {
|
|
|
|
|
NoOptions = 0x0,
|
|
|
|
|
Passive = 0x01,
|
|
|
|
|
Durable = 0x02,
|
2014-06-24 03:36:03 +08:00
|
|
|
Exclusive = 0x04,
|
|
|
|
|
AutoDelete = 0x08,
|
2014-05-29 00:25:28 +08:00
|
|
|
NoWait = 0x10
|
|
|
|
|
};
|
|
|
|
|
Q_DECLARE_FLAGS(QueueOptions, QueueOption)
|
2014-06-07 00:10:51 +08:00
|
|
|
int options() const;
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
enum ConsumeOption {
|
2014-06-24 03:36:03 +08:00
|
|
|
coNoLocal = 0x01,
|
2014-05-29 00:25:28 +08:00
|
|
|
coNoAck = 0x02,
|
|
|
|
|
coExclusive = 0x04,
|
2014-06-24 03:36:03 +08:00
|
|
|
coNoWait = 0x08
|
2014-05-29 00:25:28 +08:00
|
|
|
};
|
|
|
|
|
Q_DECLARE_FLAGS(ConsumeOptions, ConsumeOption)
|
|
|
|
|
|
2014-06-07 00:10:51 +08:00
|
|
|
enum RemoveOption {
|
2014-06-11 09:27:59 +08:00
|
|
|
roForce = 0x0,
|
2014-06-24 03:36:03 +08:00
|
|
|
roIfUnused = 0x01,
|
2014-06-07 00:10:51 +08:00
|
|
|
roIfEmpty = 0x02,
|
|
|
|
|
roNoWait = 0x04
|
|
|
|
|
};
|
|
|
|
|
Q_DECLARE_FLAGS(RemoveOptions, RemoveOption)
|
|
|
|
|
|
2014-09-15 23:51:48 +08:00
|
|
|
~QAmqpQueue();
|
2014-05-29 00:25:28 +08:00
|
|
|
|
2014-06-24 22:30:05 +08:00
|
|
|
bool isConsuming() const;
|
2015-02-01 01:44:25 +08:00
|
|
|
bool isDeclared() const;
|
2015-01-20 02:51:20 +08:00
|
|
|
|
2014-06-06 02:10:29 +08:00
|
|
|
void setConsumerTag(const QString &consumerTag);
|
|
|
|
|
QString consumerTag() const;
|
|
|
|
|
|
2015-02-16 05:36:16 +08:00
|
|
|
Q_SIGNALS:
|
|
|
|
|
void declared();
|
|
|
|
|
void bound();
|
|
|
|
|
void unbound();
|
|
|
|
|
void removed();
|
|
|
|
|
void purged(int messageCount);
|
|
|
|
|
|
|
|
|
|
void messageReceived();
|
|
|
|
|
void empty();
|
|
|
|
|
void consuming(const QString &consumerTag);
|
|
|
|
|
void cancelled(const QString &consumerTag);
|
|
|
|
|
|
|
|
|
|
public Q_SLOTS:
|
2014-06-06 02:10:29 +08:00
|
|
|
// AMQP Queue
|
2016-02-04 21:21:45 +08:00
|
|
|
void declare(int options = Durable|AutoDelete, const QAmqpTable& arguments);
|
2014-05-30 23:12:09 +08:00
|
|
|
void bind(const QString &exchangeName, const QString &key);
|
2014-09-15 23:51:48 +08:00
|
|
|
void bind(QAmqpExchange *exchange, const QString &key);
|
2014-05-30 23:12:09 +08:00
|
|
|
void unbind(const QString &exchangeName, const QString &key);
|
2014-09-15 23:51:48 +08:00
|
|
|
void unbind(QAmqpExchange *exchange, const QString &key);
|
2014-06-06 02:10:29 +08:00
|
|
|
void purge();
|
2014-06-07 00:10:51 +08:00
|
|
|
void remove(int options = roIfUnused|roIfEmpty|roNoWait);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
2014-06-06 02:10:29 +08:00
|
|
|
// AMQP Basic
|
2014-06-24 22:30:05 +08:00
|
|
|
bool consume(int options = NoOptions);
|
2014-06-25 09:09:45 +08:00
|
|
|
void get(bool noAck = true);
|
2014-06-24 23:09:19 +08:00
|
|
|
bool cancel(bool noWait = false);
|
2015-01-20 02:51:20 +08:00
|
|
|
void ack(const QAmqpMessage &message);
|
|
|
|
|
void ack(qlonglong deliveryTag, bool multiple);
|
2015-02-01 22:49:39 +08:00
|
|
|
void reject(const QAmqpMessage &message, bool requeue);
|
|
|
|
|
void reject(qlonglong deliveryTag, bool requeue);
|
2015-01-20 02:51:20 +08:00
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
protected:
|
2014-06-04 01:00:25 +08:00
|
|
|
// reimp Channel
|
|
|
|
|
virtual void channelOpened();
|
|
|
|
|
virtual void channelClosed();
|
2014-05-29 00:25:28 +08:00
|
|
|
|
|
|
|
|
private:
|
2014-09-15 23:51:48 +08:00
|
|
|
explicit QAmqpQueue(int channelNumber = -1, QAmqpClient *parent = 0);
|
2014-05-29 00:25:28 +08:00
|
|
|
|
2014-09-15 23:51:48 +08:00
|
|
|
Q_DISABLE_COPY(QAmqpQueue)
|
|
|
|
|
Q_DECLARE_PRIVATE(QAmqpQueue)
|
|
|
|
|
friend class QAmqpClient;
|
2015-11-20 06:43:31 +08:00
|
|
|
friend class QAmqpClientPrivate;
|
|
|
|
|
|
2014-05-29 00:25:28 +08:00
|
|
|
};
|
|
|
|
|
|
2014-08-27 03:05:39 +08:00
|
|
|
#endif // QAMQPQUEUE_H
|