fuCtor / QAMQP

AMQP implementation for Qt
Other
28 stars 3 forks source link

Problems using message headers #27

Closed cakovacs closed 11 years ago

cakovacs commented 11 years ago

I wrote a EmitFileDirect and ReceiveFileDirect test code and check it into the repo under my branch. I was unable to figure out how to use the message headers. I put in a workaround by embedding the filename in the message, but I would really like to take advantage of the headers. If I'm doing something wrong, please help me with the interface. If it's a bug in the backend code, please fix it if possible.

In the Emit class, I added the following code:

QVariantHash headers;
headers["fname"] = file;
headers["A"] = "AAAAAAAAAAA";
headers["B"] = "BBBBB";
headers["C"] = "CCCCCCCCCCCCCCCCC";

qDebug() << "EmitFileDirect::EmitFileMessage() headers=" << headers;

    // use the QByteArray method and pass the headers to publish
    exchange_->publish(ba_message, key, headers, mime_type, m_prop);

When I run the EmitFileDirect test, it prints out the correct information in the headers:

EmitFileDirect::EmitFileMessage() headers= QHash(("fname", QVariant(QString, "event0000001.bin") ) ( "A" , QVariant(QString, "AAAAAAAAAAA") ) ( "B" , QVariant(QString, "BBBBB") ) ( "C" , QVariant(QString, "CCCCCCCCCCCCCCCCC") ) )

The problem is in the Receiver. In the ReceiveFileDirect.h, I have the following snip-it of code:

    QAMQP::MessagePtr message = queue_->getMessage();
QVariant headers = message->property[QAMQP::Content::cpHeaders];
qDebug() << "ReceiverFileDirect::newMessage() headers=" << headers;

When I run it, it gets all of the keys, but the values are all null:

ReceiverFileDirect::newMessage() headers= QVariant(QVariantHash, QHash(("fname", QVariant(QString, "") ) ( "A" , QVariant(QString, "") ) ( "B" , QVariant(QString, "") ) ( "C" , QVariant(QString, "") ) ) )

I added the following debug code to verify that they were actually null:

QHash<QString, QVariant> hash = headers.toHash ();
QHashIterator<QString, QVariant> it(hash);
while (it.hasNext()) {
    it.next();
    qDebug() << it.key() << ": " << it.value();
}

And it printed out the following:

"fname" : QVariant(QString, "") "A" : QVariant(QString, "") "B" : QVariant(QString, "") "C" : QVariant(QString, "")

cakovacs commented 11 years ago

I added the debugging code in {Emit,Receive}FileDirect.h if it helps resolve the problem.

Branch: https://github.com/cakovacs/QAMQP.git

ximply commented 11 years ago

If you want to send file and receive file over the qamqp, you can try this: void publish(const QByteArray & message, const QString & key, const QString &mimeType, const MessageProperties &property = MessageProperties());

Note: mimeType mustn't be "text/plain", you can set it to "image/jpeg" or other binary mimetypes. Then you can receive all the file data.

cakovacs commented 11 years ago

ximply,

That's not my problem. I did set the mimeType to a binary type and able to correctly send/receive binary files using the publish method.

My problem is that I would like to send the filename in the message headers, which fails. My workaround was to include the filename in the payload and extracting the filename in the receiver (ie., payload = "[" + filename + "]" + file_contains).

I'm trying to use the following interface to send the filename inside the QVariantHash &headers argument:

void publish(const QByteArray & message, const QString & key, const QVariantHash &headers, const QString &mimeType, const MessageProperties &property = MessageProperties());

When I print the headers in the sender, the keys and values are present. When I print the headers in the receiver, the keys are there, but the values are all empty.

cakovacs commented 11 years ago

I added debugging info in EmitFileDirect.h and ReceiveFileDirect.h and push it to my branch. I'm hoping someone can tell me what I'm doing wrong.

fuCtor commented 11 years ago

I fix it. Update to revision 1a05e873cbb414ff75dd6a2ffd5eaf05587234f0

cakovacs commented 11 years ago

I verified the fix on my branch and pushed my changes. Thanks fuCtor