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" <[email protected]>
To: [email protected]
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:[email protected]
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:[email protected]