Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding a queue to a headers exchange #47

Open
kdawg14 opened this issue May 16, 2016 · 2 comments
Open

Binding a queue to a headers exchange #47

kdawg14 opened this issue May 16, 2016 · 2 comments

Comments

@kdawg14
Copy link

kdawg14 commented May 16, 2016

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
Copy link
Owner

mbroadst commented May 16, 2016

@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:

  • have all bind methods use this "complete" one
  • account for delayed bindings that specify noWait and arguments (currently delayed bindings are a QPair<QString, QString> iirc, it should just be a struct including noWait and arguments)
  • maybe print out arguments in the binding debug/trace message

@kdawg14
Copy link
Author

kdawg14 commented May 16, 2016

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants