On 25/10/16 15:22, Flores, Paul A. wrote:
Hi,
As the subject line states: "How, from within a C++ application, is it possible to
'examine' and 'manage' a broker?"
It depends which broker you are using. The c++ broker uses a message
based management protocol (called QMF). The java broker has an HTTP
based protocol.
The rest of the answers assume the c++ broker is used.
The requirements are rather straightforward we would like to be able to answer
the following questions.:
* How many 'clients' (senders and receivers) are 'connected' to a 'broker'?
You can easily get a list of connections. With AMQP 0-10 there is no
explicit concept of a 'sender'. However the connection stats track the
number of messages sent to or from a the client over that connection.
* How many receivers/subscribers are attached/subscribed to a queue/ topic?
For a queue, you can list the subscriptions. For a topic, you would
instead need to list the queues bound to the underlying exchange.
* How many senders/publishers are writing/publishing to a queue/topic?
Unfortuantely this is not available for AMQP 0-10 based connections.
(AMQP 1.0 has the concept of a sending link - analogous to a
subscription - that does allow this to be tracked for connections using
that version of the protocol)
>Is it only one or can their be multiple senders/publishers to a
queue/topic?
You can get the details of a queue which would indicate whether it was
an exclusive queue. If it is, that doesn't strictly preclude anyone
sending to it, but it would mean it could not be declared in AMQP 0-10.
*When was the last time a message was retrieved from a queue/topic?
I don't believe this information is available for the c++ broker.
*How to 'empty/clear' messages from a queue/topic from within a C++
application?
There is a purge method on queues that will just drop the messages.
(Alternatively there is also a reroute method that lets you route those
messages through another exchange if desired).
As stated earlier we are replacing CORBA messaging with QPID. To that regard
the client has a considerable amount of message channel 'management' that is
'baked' into their 'framework'. While the goal is to shift away from the CORBA
paradigm we are faced with task of identifying. developing and implementing
'like' functionality and this is one area we would like some 'sage' advice and
guidance.
Using QMF is fairly easy, if a little verbose at times, as it just
involves sending map messages and getting back map- or list- messages
with the requested content in them.
See the attached example which lists management objects of various types
(connections by default, but you can pass in another type as the first
argument, e.g. queue or subscription).
/*
*
* 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: users-unsubscr...@qpid.apache.org
For additional commands, e-mail: users-h...@qpid.apache.org