On 26/05/17 16:07, mottese wrote:
Hi,Suppose I have a consumer listening to amq.topic/mySubject. Can I use QMF to tell if I have a consumer listening to that address? Right now I am trying to use a message formatted like this: Message request; request.setReplyTo(replyToAddress); request.setProperty("x-amqp-0-10.app-id", "qmf2"); request.setProperty("qmf.opcode", "_query_request"); Variant::Map schemaId, content; schemaId["_class_name"] = "queue"; schemaId["_object_name"] = "org.apache.qpid.broker:queue:amq.topic/mySubject"; content["_what"] = "OBJECT"; content["_object_id"] = schemaId; request.setContentObject(content); Is there some way to modify this QMF request to get the information I'm looking for? Thanks
You need to query the bindings. The attached program will list all the bindings. You could modify the approach to filter out all but those where the exchange is "amq.topic". (You can't have the query do that filtering for you with QMF).
/* * * 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; std::string getName(const std::string& id) { //object id consists of a package, class and name triple, separated by ':' //note: would probably want some checking in a real program! return id.substr(id.find_last_of(":")+1); } int main(int argc, char** argv) { Connection c(argc > 1 ? argv[1] : "localhost", "{protocol:amqp1.0}"); try { c.open(); Session session = c.createSession(); Address responses("#; {create: always, node: {x-declare: {auto-delete:True}}}"); Receiver r = session.createReceiver(responses); Sender s = session.createSender("qmf.default.direct/broker"); Message request; request.setReplyTo(responses); request.setContentType("amqp/map"); request.setProperty("x-amqp-0-10.app-id", "qmf2"); request.setProperty("qmf.opcode", "_query_request"); Variant::Map schemaId; schemaId["_class_name"] = "binding"; Variant::Map content; content["_what"] = "OBJECT"; content["_schema_id"] = schemaId; encode(content, request); s.send(request); Message response = r.fetch(); Variant::List contentIn; decode(response, contentIn); for (Variant::List::const_iterator i = contentIn.begin(); i != contentIn.end(); ++i) { Variant::Map item = i->asMap(); Variant::Map values = item["_values"].asMap(); std::string queue = getName(values["queueRef"].asMap()["_object_name"]); std::string exchange = getName(values["exchangeRef"].asMap()["_object_name"]); std::string key = values["bindingKey"]; std::cout << exchange << " " << queue << " " << key << 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]
