Client to broker connection status using C++ API

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Client to broker connection status using C++ API

trivedi_ravi13
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 ?

Regards,
Ravi Trivedi



--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

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

Reply | Threaded
Open this post in threaded view
|

Re: Client to broker connection status using C++ API

Gordon Sim
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.




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

list.cpp (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Client to broker connection status using C++ API

trivedi_ravi13
Yeah got some idea from this
http://apache-qpid-users.2158936.n2.nabble.com/Number-of-messages-in-a-queue-td6382025.html
<http://apache-qpid-users.2158936.n2.nabble.com/Number-of-messages-in-a-queue-td6382025.html>
.

Just changed schemas and it's working for me, Thanks !



--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

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

Reply | Threaded
Open this post in threaded view
|

Re: Client to broker connection status using C++ API

Chris Richardson-3
In reply to this post by Gordon Sim
On Wed, 17 Oct 2018 at 18:00, Gordon Sim <[hidden email]> wrote:

> 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.
>
>
>
Further to Gordon's example code, I'd like to mention an open-source
library I've written which does exactly this:
https://github.com/fourceu/fourc-qpid-manager

This is based on the QMF protocol Gordon mentioned.

There's an example which gets all bindings:
https://github.com/fourceu/fourc-qpid-manager/blob/master/examples/Bindings.cxx
Substituting "Connections" for "Bindings" here should give you what you're
after.

I have tested it only on the later 1.36-1.38 versions but there's no reason
I know of that would prevent it from working with 0.24.


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
Reply | Threaded
Open this post in threaded view
|

Re: Client to broker connection status using C++ API

trivedi_ravi13
In reply to this post by Gordon Sim
Hi Gordan,

   I am using following code to get the list of connections. However, I
found it gives me only first 100 connections. When I use "qpid-stat" it
shows me all the connections even beyond 100. What's wrong with this code?

int main(int argc, char** argv)
{

    Connection c("127.0.0.1:5672");

    try {
        c.open();
        Session session = c.createSession();
        Address
responses("qmf.default.topic/direct.amqpagent;{node:{type:topic},
link:{x-declare:{auto-delete:True,exclusive:True}}}");
        Receiver r = session.createReceiver(responses);
        Sender s = session.createSender("qmf.default.direct/broker");

        Message request;
        request.setReplyTo(responses);
        request.setSubject("broker");
        request.setContentType("amqp/map");
        request.setProperty("x-amqp-0-10.app-id", "qmf2");
        request.setProperty("qmf.opcode", "_query_request");
        request.setProperty("method", "request");
        Variant::Map oid;
        Variant::Map content;
        oid["_class_name"] = "connection";
        content["_what"] = "OBJECT";
        content["_schema_id"] = oid;

        encode(content, request);
        s.send(request);
        Message response = r.fetch();
        Variant::List contentIn;
        decode(response, contentIn);

        for(Variant::List::iterator it = contentIn.begin(); it !=
contentIn.end(); it++) {
            Variant::Map details = it->asMap()["_values"].asMap();
            std::cout << details << std::endl;
        }

        session.acknowledge();

    } catch(const std::exception& error) {
        std::cout << "ERROR: " << error.what() << std::endl;
    }

    c.close();
    return 0;
}




--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

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

Reply | Threaded
Open this post in threaded view
|

Re: Client to broker connection status using C++ API

Gordon Sim
On 01/03/2019 9:53 am, trivedi_ravi13 wrote:
> Hi Gordan,
>
>     I am using following code to get the list of connections. However, I
> found it gives me only first 100 connections. When I use "qpid-stat" it
> shows me all the connections even beyond 100. What's wrong with this code?

If there is a lot of data, it may be sent back in multiple response
messages (though 100 seems rather low to be triggering that on the
normal frame size). Check whether the response has the 'partial'
property set, and if so keep fetching another response until it does not.

You can also compare the protocol traces for qpid-stat and your code.


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

Reply | Threaded
Open this post in threaded view
|

Re: Client to broker connection status using C++ API

trivedi_ravi13
Yes it's indeed fragmented. One message contains 100 records. It worked after
handling "partial". Thank you.



--
Sent from: http://qpid.2158936.n2.nabble.com/Apache-Qpid-users-f2158936.html

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