You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@qpid.apache.org by dmounessa <dm...@yahoo.com> on 2011/12/02 17:42:39 UTC
Jave Client with C++ Broker - Messages in Queue-size?
Is there a way to get Queue size from the JAVA Client?
I want to get notified when I can start sending messages on the queue?
Thanks
--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Jave-Client-with-C-Broker-Messages-in-Queue-size-tp7055301p7055301.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org
Re: Jave Client with C++ Broker - Messages in Queue-size?
Posted by Oleksandr Rudyy <or...@gmail.com>.
Hi,
You can get number of messages on a queue by invoking
AMQSession#getQueueDepth(AMQDestination) like following
Session myJMSSession = ...
Desionation myJMSDestination = ..
long queueDepth =
((AMQSession)myJMSSession).getQueueDepth(((AMQDestination)myJMSDestination));
Pls, be aware that this method is internal implementation specific and
can be changed or removed in following versions of qpid JMS client.
Kind Regards,
Alex
On 2 December 2011 16:42, dmounessa <dm...@yahoo.com> wrote:
> Is there a way to get Queue size from the JAVA Client?
>
> I want to get notified when I can start sending messages on the queue?
>
> Thanks
>
> --
> View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Jave-Client-with-C-Broker-Messages-in-Queue-size-tp7055301p7055301.html
> Sent from the Apache Qpid users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org
Re: Jave Client with C++ Broker - Messages in Queue-size?
Posted by Fraser Adams <fr...@blueyonder.co.uk>.
I'm afraid that I can't think on any really elegant solutions.
Re "I need some kind of notifications from JMS Client API that I am able
to send".
I don't think that the JMS API has a mechanism for doing this, though I
may be wrong.
The best approach that I can think of at the moment is to intercept the
queueThresholdExceeded Event, this would allow your producer client to
detect that the queue is about to fill up and stop producing.
You could then periodically poll the queue size as described previously
to decide when to start sending again.
It might be nice if QMF2 could be updated to have a "low water mark"
event similar to the threshold exceeded upper water mark event as that
would make polling in your scenario unnecessary. I don't think such a
thing exists yet - does anyone have any thoughts on whether that'd be
generally useful?
As an alternative approach you could look into flow control. I've not
tried this myself and obviously it'll depend on your overall Enterprise
scenario whether it's an appropriate approach, but it might be worth
looking at.
Sorry I can't be more help
Frase
dmounessa wrote:
> Thanks -- I need the queue size because I am not sure how to find out when i
> can send messages to a durable queue after i get JMS Exception that the
> queue is max-ed out.
> I was testing and I send 10000 message and I changed the jfile to 4 so I get
> Queue Filled Exception.
> Then I started a receiver to read the Messages from the queue. After the
> receiver has finished reading the sender should be able to start sending
> more messages --- But my test sender does not know when to do this. I need
> some kind of notifications from JMS Client API that I am able to send. B/C
> when I tried to send after the Queue is filled -- I get JMS Exception and i
> can not send any more until I restart the app.
>
> So I was thinking to prevent to get in to this situation - but this is not
> the best solution.
>
> Is there a way that I could get notification that Connection for queue is
> good to be sent and do you have sample code for this?
>
> Thanks
>
>
> --
> View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Jave-Client-with-C-Broker-Messages-in-Queue-size-tp7055301p7068113.html
> Sent from the Apache Qpid users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>
>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org
Re: Jave Client with C++ Broker - Messages in Queue-size?
Posted by dmounessa <dm...@yahoo.com>.
Thanks -- I need the queue size because I am not sure how to find out when i
can send messages to a durable queue after i get JMS Exception that the
queue is max-ed out.
I was testing and I send 10000 message and I changed the jfile to 4 so I get
Queue Filled Exception.
Then I started a receiver to read the Messages from the queue. After the
receiver has finished reading the sender should be able to start sending
more messages --- But my test sender does not know when to do this. I need
some kind of notifications from JMS Client API that I am able to send. B/C
when I tried to send after the Queue is filled -- I get JMS Exception and i
can not send any more until I restart the app.
So I was thinking to prevent to get in to this situation - but this is not
the best solution.
Is there a way that I could get notification that Connection for queue is
good to be sent and do you have sample code for this?
Thanks
--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Jave-Client-with-C-Broker-Messages-in-Queue-size-tp7055301p7068113.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org
Re: Jave Client with C++ Broker - Messages in Queue-size?
Posted by Fraser Adams <fr...@blueyonder.co.uk>.
Hi,
Long post follows, hope it's useful....
Cheers,
Frase
IIRC C++ brokers from 0.10 onwards have both QMF1 and QMF2 enabled by
default, the 0.8 broker needs to have it explicitly enabled with
"--mgmt-qmf2 yes"
if you do qpidd -h you'll see all the options.
Re "where can I get the list of messages that I could send to broker for
configurations/stats?" the best place to look is here:
https://cwiki.apache.org/qpid/qmf-map-message-protocol.html
The QMF2 API is specified here:
https://cwiki.apache.org/qpid/qmfv2-api-proposal.html
The latter is what I've just finished writing a Java implementation for.
My implementation contains "the full works" including all the
subscription stuff. I keep promising to release it but unfortunately I
keep getting sidetracked - the other week I got bogged down trying to
build the 0.12 broker 'cause I wanted to test against that...
I'm nearly there, the main thing holding me up at the moment is that I'm
writing a bunch of Java QMF2 demo tools, so I've written Java ports of
qpid-config, qpid-printevents and qpid-queue-stats (that was written to
demo QMF2 subscriptions) I've also written a port of qpid-ctrl so you
can send QMF2 methods to the broker from the command line. I'm currently
working on qpid-fuse, which is a demo that intercepts the
queueThresholdExceeded Event and remove bindings from the queue to
protect producers. It's nearly there, but not quite.
I really ought to finish it this weekend or next (the day job means I
can only really do this at weekends :-( ).
How often do you need to find the number of messages in your queue BTW?
I'm not aware of a way to find the number of messages in a queue other
than via QMF (you could *possibly* browse the queue, but IIRC the JMS
browse API doesn't give size so I think you'd have to iterate and count,
which isn't efficient).
With QMF2 there's two options, one is to subscribe to data indications
from the broker (this is actually what I do to emulate QMF2 query
subscriptions on the ManagementAgent as that doesn't currently support
real query subscriptions). The problem with that (and why I asked how
often you need to find the number of messages) is that the broker only
pushes data every 10 seconds (though you can change this via a config
option). The other option is to use the QMF2 "_query_request" described
earlier in this thread to "poll" the issues with that is that for a
*specific* queue you'd need to first retrieve the list of all queues
using the _schema_id query then find the queue you care about by
iterating and looking up the "name" property. However once you've found
the queue object that you want you can continually get updates by doing
an _object_id query.
_object_id queries are "fairly" efficient as you only get a response for
the object that you want also on the broker side it's a Map lookup keyed
by _object_id (the _schema_id lookups iterate to find matching objects).
However I say "fairly" efficient as it's still a message request and
response over the network to get the info from the broker so clearly
that's something to bear in mind. In the QMF2 API the procedure I've
described is quite simple - you just need to invoke the "refresh()"
method on the QmfConsoleData object that represents the queue you care
about.
My code for this is as follows (this code is actually delegated to from
my QMFConsoleData class cause it's my Console class that does all the
JMS stuff):
The following should have most of the stuff that you need in lieu of me
finally actually publishing the API. Clearly it's a bit disjoint. The
_reply_address and _async_reply_address etc are created using the
following (just snippets) - pretty standard JMS really. I use two
sessions so I can mix synchronous calls with async stuff from my
MessageListener thread safely.
.........
{
String topicBase = "qmf." + _domain + ".topic";
_asyncSession = _connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
_syncSession = _connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
// Create a MessageProducer for the QMF topic address used
to broadcast requests
Destination topicAddress = _syncSession.createQueue(topicBase);
_broadcaster = _syncSession.createProducer(topicAddress);
// Set up MessageListener on the Event Address
Destination eventAddress =
_asyncSession.createQueue(topicBase + "/agent.ind.#");
_eventConsumer = _asyncSession.createConsumer(eventAddress);
_eventConsumer.setMessageListener(this);
// Create the asynchronous JMSReplyTo _replyAddress and
MessageConsumer
_asyncReplyAddress = _asyncSession.createQueue(_address +
".async");
_asyncResponder =
_asyncSession.createConsumer(_asyncReplyAddress);
_asyncResponder.setMessageListener(this);
// I've extended the synchronized block to include creating
the _requester and _responder. I don't believe
// that this is strictly necessary, but it stops findbugs
moaning about inconsistent synchronization
// so makes sense if only to get that warm and fuzzy feeling
of keeping findbugs happy :-)
synchronized(this)
{
// Create a MessageProducer for the QMF direct address,
mainly used for request/response
Destination directAddress =
_syncSession.createQueue("qmf." + _domain + ".direct");
_requester = _syncSession.createProducer(directAddress);
// Create the JMSReplyTo _replyAddress and MessageConsumer
_replyAddress = _syncSession.createQueue(_address);
_responder = _syncSession.createConsumer(_replyAddress);
_connection.start();
.............
/**
* Request that the Agent update the value of an object's contents.
*
* @param agent the Agent to get the refresh from.
* @param objectId the ObjectId being queried for
* @param replyHandle the correlation handle used to tie
asynchronous method requests with responses
* @param timeout the time to wait for a reply from the Agent, a
value of -1 means use the default timeout
* @return the refreshed object
*/
public QmfConsoleData refresh(final Agent agent, final ObjectId
objectId, final String replyHandle, final int timeout)
{
List<QmfConsoleData> objects = getObjects(agent, objectId,
replyHandle, timeout);
return (objects.size() == 0) ? null : objects.get(0);
}
/**
* Perform a query for QmfConsoleData objects. Returns a list
(possibly empty) of matching objects.
* If replyHandle is null this method will block until the agent
replies, or the timeout expires.
* Once the timeout expires, all data retrieved to date is returned.
If replyHandle is non-null an
* asynchronous request is performed
*
* @param agent the Agent being queried
* @param query the ObjectId or SchemaClassId being queried for.
* @param replyHandle the correlation handle used to tie
asynchronous method requests with responses
* @param timeout the time to wait for a reply from the Agent, a
value of -1 means use the default timeout
* @return a List of QMF Objects describing that class
*/
private List<QmfConsoleData> getObjects(final Agent agent, final
QmfData query,
final String replyHandle,
int timeout)
{
String agentName = agent.getName();
timeout = (timeout < 1) ? _replyTimeout : timeout;
List<QmfConsoleData> results = Collections.emptyList();
try
{
Destination destination = (replyHandle == null) ?
_replyAddress : _asyncReplyAddress;
MapMessage request = _syncSession.createMapMessage();
request.setJMSReplyTo(destination);
request.setJMSCorrelationID(replyHandle);
request.setStringProperty("x-amqp-0-10.app-id", "qmf2");
request.setStringProperty("method", "request");
request.setStringProperty("qmf.opcode", "_query_request");
request.setStringProperty("qpid.subject", agentName);
// Create a QMF Query for an "OBJECT" target using either a
schema ID or object ID
String queryType = (query instanceof SchemaClassId) ?
"_schema_id" : "_object_id";
request.setObject("_what", "OBJECT");
request.setObject(queryType, query.mapEncode());
// Wrap request & response in synchronized block in case any
other threads invoke a request
// it would be somewhat unfortunate if their response got
interleaved with ours!!
synchronized(this)
{
_requester.send(request);
if (replyHandle == null)
{
Message response = _responder.receive(timeout*1000);
if (response == null)
{
log.info("No response received in getObjects()");
return Collections.emptyList();
}
if (response instanceof MapMessage)
{ // Error responses are returned as MapMessages
//QmfData exception = new
QmfData(AMQPMessage.getMap(response));
//System.out.println(agentName + " " +
exception.getStringValue("error_text"));
}
else
{
List<Map> mapResults =
AMQPMessage.getList(response);
results = new
ArrayList<QmfConsoleData>(mapResults.size());
for (Map content : mapResults)
{
results.add(new QmfConsoleData(content, agent));
}
}
}
}
}
catch (JMSException jmse)
{
log.info("JMSException {} caught in getObjects()",
jmse.getMessage());
}
return results;
}
/**
* JMS QMF returns amqp/list types as a BytesMessage this method
decodes that into a java.util.List
* <p>
* Taken from Gordon Sim's initial JMS QMF Example using the BBDecoder
* <p>
* Trivia: This block of code from Gordon Sim is the seed that
spawned the whole of this Java QMF2 API
* implementation - cheers Gordon.
*
* @param message amqp/list encoded JMS Message
* @return a java.util.List decoded from Message
*/
@SuppressWarnings("unchecked")
public static <T> List<T> getList(final Message message) throws
JMSException
{
if (message == null)
{
throw new MessageFormatException("Attempting to do
AMQPMessage.getList() on null Message");
}
else if (message instanceof BytesMessage)
{
BytesMessage msg = (BytesMessage)message;
//only handles responses up to 2^31-1 bytes long
byte[] data = new byte[(int) msg.getBodyLength()];
msg.readBytes(data);
BBDecoder decoder = new BBDecoder();
decoder.init(ByteBuffer.wrap(data));
return (List<T>)decoder.readList();
}
else
{
return null;
}
}
dmounessa wrote:
> Thanks -- do I need to start the broker with any special module (qmf?) or
> does the standard C++ broker will support the QMF messages?
>
> Also, where can I get the list of messages that I could send to broker for
> configurations/stats?
>
> Thanks for your help?
>
> --
> View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Jave-Client-with-C-Broker-Messages-in-Queue-size-tp7055301p7067715.html
> Sent from the Apache Qpid users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>
>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org
Re: Jave Client with C++ Broker - Messages in Queue-size?
Posted by dmounessa <dm...@yahoo.com>.
Thanks -- do I need to start the broker with any special module (qmf?) or
does the standard C++ broker will support the QMF messages?
Also, where can I get the list of messages that I could send to broker for
configurations/stats?
Thanks for your help?
--
View this message in context: http://apache-qpid-users.2158936.n2.nabble.com/Jave-Client-with-C-Broker-Messages-in-Queue-size-tp7055301p7067715.html
Sent from the Apache Qpid users mailing list archive at Nabble.com.
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org
Re: Jave Client with C++ Broker - Messages in Queue-size?
Posted by Fraser Adams <fr...@blueyonder.co.uk>.
Hi all,
Although Pavel mentioned
https://issues.apache.org/jira/browse/QPID-3302
And the need for a patch for Qpid < 0.12 to use QMF2 with Java there's
also an issue with respect to returning Lists. Basically JMS doesn't
support amqp/list
Here's some code to help.....
HTH
Frase
/**
* JMS QMF returns amqp/list types as a BytesMessage this method
decodes that into a java.util.List
* <p>
* Taken from Gordon Sim's initial JMS QMF Example using the BBDecoder
* <p>
* Trivia: This block of code from Gordon Sim is the seed that
spawned the whole of this Java QMF2 API
* implementation - cheers Gordon.
*
* @param message amqp/list encoded JMS Message
* @return a java.util.List decoded from Message
*/
@SuppressWarnings("unchecked")
public static <T> List<T> getList(final Message message) throws
JMSException
{
if (message == null)
{
throw new MessageFormatException("Attempting to do
AMQPMessage.getList() on null Message");
}
else if (message instanceof BytesMessage)
{
BytesMessage msg = (BytesMessage)message;
//only handles responses up to 2^31-1 bytes long
byte[] data = new byte[(int) msg.getBodyLength()];
msg.readBytes(data);
BBDecoder decoder = new BBDecoder();
decoder.init(ByteBuffer.wrap(data));
return (List<T>)decoder.readList();
}
else
{
return null;
}
}
Pavel Moravec wrote:
> Hi,
> the best way I am aware of is to use QMF to query either the queue itself (not sure if or how possible) or to get list of all queues (though for many queues, it is quite inefficient way).
>
> Here is a code snippet from C++ program (rewriting to Java shall be easy, I have it only in C++):
>
> int main(int argc, char** argv) {
> Connection c(argc>1?argv[1]:"localhost:5672");
> c.open();
> Session session = c.createSession();
> Receiver r = session.createReceiver("#qlister; {create:always, delete:always}");
> Sender s = session.createSender("qmf.default.direct/broker");
>
> Message m;
> m.setReplyTo(Address(r.getName()));
> m.setProperty("x-amqp-0-10.app-id", "qmf2");
> m.setProperty("qmf.opcode", "_query_request");
>
> Variant::Map request;
> request["_what"] = "OBJECT";
> Variant::Map schemaId;
> schemaId["_class_name"] = "queue";
> request["_schema_id"] = schemaId;
>
> encode(request, m);
> s.send(m);
> m = r.fetch(3 * Duration::SECOND);
> session.acknowledge(m);
> Variant::List response;
> decode(m, response);
> for(Variant::List::iterator iter = response.begin(); iter != response.end(); iter++) {
> Variant::Map map = iter->asMap();
> Variant::Map values = map["_values"].asMap();
> cout << values["name"] << endl;;
> cout << map << endl << endl;
> }
> r.close();
> s.close();
> session.close();
> c.close();
> return 0;
> }
>
> Please note you have to have qpid at least 0.11 to use QMF, due to https://issues.apache.org/jira/browse/QPID-3302.
>
> Kind regards,
> Pavel Moravec
>
>
> ----- Original Message -----
>
>> From: "dmounessa" <dm...@yahoo.com>
>> To: users@qpid.apache.org
>> Sent: Friday, December 2, 2011 5:42:39 PM
>> Subject: Jave Client with C++ Broker - Messages in Queue-size?
>>
>> Is there a way to get Queue size from the JAVA Client?
>>
>> I want to get notified when I can start sending messages on the
>> queue?
>>
>> Thanks
>>
>> --
>> View this message in context:
>> http://apache-qpid-users.2158936.n2.nabble.com/Jave-Client-with-C-Broker-Messages-in-Queue-size-tp7055301p7055301.html
>> Sent from the Apache Qpid users mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> Apache Qpid - AMQP Messaging Implementation
>> Project: http://qpid.apache.org
>> Use/Interact: mailto:users-subscribe@qpid.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>
>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org
Re: Jave Client with C++ Broker - Messages in Queue-size?
Posted by Fraser Adams <fr...@blueyonder.co.uk>.
Pavel Moravec wrote:
> Hi,
> the best way I am aware of is to use QMF to query either the queue itself (not sure if or how possible)
To query for a specific queue one could use the ObjectId, so Pavel's
snippet below recovers all queue objects so one would then iterate to
find the one you want (presumably via its name property). Having found
the queue you want you the extract it's ObjectId you can then
periodically query using the objectId in place of the schemaId below
request["_object_id"] = objectId;
If you just need updates on a single queue that's more efficient than
pulling back the list.
Depending on how frequently you need updates the broker also pushes out
property and statistic updates. If you subscribe to
qmf.default.topic/agent.ind.# you will get heartbeats and also data
indications. However the broker only pushes updates every 10 seconds
(though that period is configurable).
The queueThresholdExceeded Event might also be useful to you.
Frase.
> or to get list of all queues (though for many queues, it is quite inefficient way).
>
> Here is a code snippet from C++ program (rewriting to Java shall be easy, I have it only in C++):
>
> int main(int argc, char** argv) {
> Connection c(argc>1?argv[1]:"localhost:5672");
> c.open();
> Session session = c.createSession();
> Receiver r = session.createReceiver("#qlister; {create:always, delete:always}");
> Sender s = session.createSender("qmf.default.direct/broker");
>
> Message m;
> m.setReplyTo(Address(r.getName()));
> m.setProperty("x-amqp-0-10.app-id", "qmf2");
> m.setProperty("qmf.opcode", "_query_request");
>
> Variant::Map request;
> request["_what"] = "OBJECT";
> Variant::Map schemaId;
> schemaId["_class_name"] = "queue";
> request["_schema_id"] = schemaId;
>
> encode(request, m);
> s.send(m);
> m = r.fetch(3 * Duration::SECOND);
> session.acknowledge(m);
> Variant::List response;
> decode(m, response);
> for(Variant::List::iterator iter = response.begin(); iter != response.end(); iter++) {
> Variant::Map map = iter->asMap();
> Variant::Map values = map["_values"].asMap();
> cout << values["name"] << endl;;
> cout << map << endl << endl;
> }
> r.close();
> s.close();
> session.close();
> c.close();
> return 0;
> }
>
> Please note you have to have qpid at least 0.11 to use QMF, due to https://issues.apache.org/jira/browse/QPID-3302.
>
> Kind regards,
> Pavel Moravec
>
>
> ----- Original Message -----
>
>> From: "dmounessa" <dm...@yahoo.com>
>> To: users@qpid.apache.org
>> Sent: Friday, December 2, 2011 5:42:39 PM
>> Subject: Jave Client with C++ Broker - Messages in Queue-size?
>>
>> Is there a way to get Queue size from the JAVA Client?
>>
>> I want to get notified when I can start sending messages on the
>> queue?
>>
>> Thanks
>>
>> --
>> View this message in context:
>> http://apache-qpid-users.2158936.n2.nabble.com/Jave-Client-with-C-Broker-Messages-in-Queue-size-tp7055301p7055301.html
>> Sent from the Apache Qpid users mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> Apache Qpid - AMQP Messaging Implementation
>> Project: http://qpid.apache.org
>> Use/Interact: mailto:users-subscribe@qpid.apache.org
>>
>>
>>
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>
>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org
Re: Jave Client with C++ Broker - Messages in Queue-size?
Posted by Pavel Moravec <pm...@redhat.com>.
Hi,
the best way I am aware of is to use QMF to query either the queue itself (not sure if or how possible) or to get list of all queues (though for many queues, it is quite inefficient way).
Here is a code snippet from C++ program (rewriting to Java shall be easy, I have it only in C++):
int main(int argc, char** argv) {
Connection c(argc>1?argv[1]:"localhost:5672");
c.open();
Session session = c.createSession();
Receiver r = session.createReceiver("#qlister; {create:always, delete:always}");
Sender s = session.createSender("qmf.default.direct/broker");
Message m;
m.setReplyTo(Address(r.getName()));
m.setProperty("x-amqp-0-10.app-id", "qmf2");
m.setProperty("qmf.opcode", "_query_request");
Variant::Map request;
request["_what"] = "OBJECT";
Variant::Map schemaId;
schemaId["_class_name"] = "queue";
request["_schema_id"] = schemaId;
encode(request, m);
s.send(m);
m = r.fetch(3 * Duration::SECOND);
session.acknowledge(m);
Variant::List response;
decode(m, response);
for(Variant::List::iterator iter = response.begin(); iter != response.end(); iter++) {
Variant::Map map = iter->asMap();
Variant::Map values = map["_values"].asMap();
cout << values["name"] << endl;;
cout << map << endl << endl;
}
r.close();
s.close();
session.close();
c.close();
return 0;
}
Please note you have to have qpid at least 0.11 to use QMF, due to https://issues.apache.org/jira/browse/QPID-3302.
Kind regards,
Pavel Moravec
----- Original Message -----
> From: "dmounessa" <dm...@yahoo.com>
> To: users@qpid.apache.org
> Sent: Friday, December 2, 2011 5:42:39 PM
> Subject: Jave Client with C++ Broker - Messages in Queue-size?
>
> Is there a way to get Queue size from the JAVA Client?
>
> I want to get notified when I can start sending messages on the
> queue?
>
> Thanks
>
> --
> View this message in context:
> http://apache-qpid-users.2158936.n2.nabble.com/Jave-Client-with-C-Broker-Messages-in-Queue-size-tp7055301p7055301.html
> Sent from the Apache Qpid users mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> Apache Qpid - AMQP Messaging Implementation
> Project: http://qpid.apache.org
> Use/Interact: mailto:users-subscribe@qpid.apache.org
>
>
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:users-subscribe@qpid.apache.org