mbroadst / qamqp

AMQP 0.9.1 implementation for Qt
Other
152 stars 130 forks source link

Binding a queue to a headers exchange #47

Open kdawg14 opened 8 years ago

kdawg14 commented 8 years ago

I'm trying to bind a queue to a headers exchange with the bind matching on multiple headers and I'm a little bit stuck and wondering how to do this.

I've noticed that drivers in other languages have the queue bind function taking a third argument for arguments that can specify the headers to match on (e.g., http://stackoverflow.com/questions/19240290/how-do-i-implement-headers-exchange-in-rabbitmq-using-java) , but I don't see an equivalent in QAmqpQueue.

Is this something that's not currently implemented or I am just not understanding how I'm supposed to bind a queue to a headers exchange?

Thanks!

mbroadst commented 8 years ago

@kdawg14 yeah this is definitely just not currently implemented, and I'm not sure it's something I'd necessarily get around to. If you wanted to take a stab at this that would be great, it looks like it would be pretty easy. You just need to provide the right methods for it - something like:

    void bind(const QString &exchangeName, const QString &key, bool noWait, const QAmqpTable &arguments);
    void bind(QAmqpExchange *exchange, const QString &key, bool noWait, const QAmqpTable &arguments);

with an implementation like:

void QAmqpQueue::bind(const QString &exchangeName, const QString &key, bool noWait, const QAmqpTable &arguments) {
{
    Q_D(QAmqpQueue);
    if (!d->opened) {
        d->delayedBindings.append(QPair<QString,QString>(exchangeName, key));
        return;
    }

    QAmqpMethodFrame frame(QAmqpFrame::Queue, QAmqpQueuePrivate::miBind);
    frame.setChannel(d->channelNumber);

    QByteArray arguments;
    QDataStream out(&arguments, QIODevice::WriteOnly);

    out << qint16(0);   //  reserved 1
    QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, d->name);
    QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, exchangeName);
    QAmqpFrame::writeAmqpField(out, QAmqpMetaType::ShortString, key);

    out << qint8(noWait);    //  no-wait
    QAmqpFrame::writeAmqpField(out, QAmqpMetaType::Hash, arguments);

    qAmqpDebug("<- queue#bind( queue=%s, exchange=%s, routing-key=%s, no-wait=%d )",
               qPrintable(d->name), qPrintable(exchangeName), qPrintable(key),
               qPrintable(noWait));

    frame.setArguments(arguments);
    d->sendFrame(frame);
}

Obviously there would be some more work:

kdawg14 commented 8 years ago

Thanks for the quick reply. I will take a stab at adding this in.