On 17/10/18 17:15, trivedi_ravi13 wrote:
Hi,
I've a requirement to monitor if a particular client is connected
successfully to the broker or not periodically. Is there a way using C++
APIs to get the status of all connected clients on Qpid 0.24 ?
Yes. Different brokers have different schemas and management protocols,
but I think all of them allow management via some message based protocol.
The qpid c++ broker, it uses a protocol called QMF (qpid management
framework), which is a message based protocol that you can use with any
amqp client.
Attached is a simple example using the qpid::messaging API for listing
connections (or indeed other types) using qmf. You could also use the
proton cpp api sending the same request message.
/*
*
* 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)
{
std::string type = argc > 1 ? argv[1] : "connection";
Connection c(argc > 2 ? argv[2] : "localhost", argc > 3 ? argv[3] : "{}");
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"] = type;
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]