On 05/26/2015 06:12 PM, Matt Broadstone wrote:
On Tue, May 26, 2015 at 12:06 PM, Matt Broadstone <[email protected]>
wrote:

Hi all,

I have two sample C++ applications (provided by chug on irc, previously
provided by gsim iirc) using the qpid C++ messaging api, that connect to a
broker and use qmf2 to retrieve broker statistics:

The first one, here (https://gist.github.com/mbroadst/4c24416bbaebdf56998a)
I believe uses amqp 0-10 (the default wire protocol), and indeed prints out
broker statistics when run.

The second one, here (
https://gist.github.com/mbroadst/54a3d75779c0c63ed30c) forces the use of
AMQP 1.0, by passing "{ protocol: amqp1.0 }" to the Connection ctor, and
does not work but simply spins waiting for responses once run.

This has been verified to be the case on ubuntu (where I am running it),
as well as Fedora (by mcpierce).

Cheers,
Matt


It looks like the error in this case is specific to the "#" identifier used
for the responses Address on L43. If I replace this with "test" I do indeed
get a response, however I also now get this error:

ERROR: illegal-argument: Not enough data for list, expected 3506438148
bytes but only 1137 available
(/build/buildd/qpid-cpp-0.32/src/qpid/framing/List.cpp:59)

The example you have relies on the way 0-10 works for temporary queue names and for encoding the map data.

For the first issue, just use "#" for the receiver and instead of an explicit Address object, use receiver.getAddress() as the value for reply-to. That will work whether the name is generated client side (as in 0-10) or server side (as in 1.0).

For the second use the get-/set-ContentObject() methods rather than decode/encode. The 'usual' 1.0 encoding of structured is not based on a content-type which necessitated a small APi change. The content object approach works with either protocol.

E.g. see attached example that is mostly the same as yours (I think) other than these fixes.

/*
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 */


#include <qpid/messaging/Address.h>
#include <qpid/messaging/Connection.h>
#include <qpid/messaging/Message.h>
#include <qpid/messaging/Receiver.h>
#include <qpid/messaging/Sender.h>
#include <qpid/messaging/Session.h>
#include <qpid/types/Variant.h>
#include <iostream>

using namespace qpid::messaging;
using namespace qpid::types;

using std::string;

int main(int argc, char** argv)
{
    Connection c(argc > 1 ? argv[1] : "localhost", "{protocol:amqp1.0}");
    try {
        c.open();
        Session session = c.createSession();
        Receiver r = session.createReceiver("#");
        Sender s = session.createSender("qmf.default.direct/broker");

    	Message request;
        request.setReplyTo(r.getAddress());
        request.setProperty("x-amqp-0-10.app-id", "qmf2");
        request.setProperty("qmf.opcode", "_query_request");
        Variant::Map schemaId;
        schemaId["_class_name"] = "broker";
        Variant::Map content;
        content["_what"] = "OBJECT";
        content["_schema_id"] = schemaId;
        request.setContentObject(content);
        s.send(request);

        Message response = r.fetch();
        Variant::List contentIn = response.getContentObject().asList();
        for (Variant::List::const_iterator i = contentIn.begin(); i != contentIn.end(); ++i) {
            Variant::Map item = i->asMap();
            std::cout << item["_values"] << std::endl;
        }
        session.acknowledge();
    } catch(const std::exception& error) {
        std::cout << "ERROR: " << error.what() << std::endl;
    }
    c.close();
    return 0;
}



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to