You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by me...@cs.man.ac.uk on 2008/06/12 12:18:27 UTC

Java Client - Question

Hi All,

Thanks Carl for giving me a good starting point. So I am focusing on the 
first step from the following step (regarding JMX/WSDM Bridge project):

1. Creating a Java Client which can talk to Qpid C++ Broker. Thus I can 
fetch the schema out from the broker

2. Once I will get the schema, I will translate it into JMS object

3. Then, we can expose those to WSDM

One question on the first step, I am creating an individual Java Client for 
this. I dont really understand how I will bind Queue of my Java client to 
exchange so that I can receive messages and updates periodically from the 
exchange. Carl, did you want me to create an individual java client, if so 
how can I bind it with the exchange?

Secondly, will I use the Client APIs of Qpid broker to make the connection 
and create/declare queues and bind them to exchange?

For instance, I did find the APIs for the same under this directory 
structure:

https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/

Can I use this code to fetch the schema from the Qpid C++ broker?

Thank you.

Best Regards,
Rahul


Re: Java Client - Question

Posted by me...@cs.man.ac.uk.
Hi Aidan,

Thanks.

I used Maven to build and it was successful. I will give a try with ant now.

Best Regards,
Rahul



On Jun 16 2008, Aidan Skinner wrote:

> On Mon, Jun 16, 2008 at 9:56 AM,  <me...@cs.man.ac.uk> wrote:
> 
> > Thanks for your help. I am still with my previous problem (i.e. 
> > missing some APIs)
> 
> > Client.java (under org.apache.qpidity.nclient) is missing some apis. eg.
> >
> > org.apache.qpidity.transport.ConnectionClose;
> 
> > due to these I can not compile/run the code.
> 
> It looks like you haven't run the generator, try doing an ant build
> and it should create those classes for you.
> 
> - Aidan
> 

Re: Java Client - Question

Posted by me...@cs.man.ac.uk.
Hi Arnaud,

Thanks for your email.

So it should be like this:

-----------
...
...
// schema hash
decoder.readBin128());				

// get the decoded properties contents
int propCnt = decoder.readUint16();
int statCnt = decoder.readUint16();
int methodCnt = decoder.readUint16();				
int eventCnt = decoder.readUint16();				
//System.out.println("Property content:   " + propCnt);

for( int i = 0; i < propCnt; i++ )
{	// decode the MAP
	Map<String,Object> map = decoder.readMap();
}
				
for( int i = 0; i < statCnt; i++ )
{	// decode the MAP
Map<String,Object> map = decoder.readMap();
	}

for( int i = 0; i < methodCnt; i++ )
{	// decode the MAP
	Map<String,Object> map = decoder.readMap();
}
				
for( int i = 0; i < eventCnt; i++ )
{	// decode the MAP
Map<String,Object> map = decoder.readMap();
}

....
....

-------

However, I have not compiled it yet. Just wanted to know your view.

BR,
Rahul



On Jun 27 2008, Arnaud Simon wrote:

> Hi,
> 
> > Rafael mentioned last night that AbastractDecoder does not know it so 
> > we added another method i.e. readBin128() in AbstractDecoder.java 
> > (under org.apache.qpidity.transport.codec) for decoding 16 bytes of 
> > opaque binary data. It produced some unknown characters (e.g. output: 
> > Schema hash is: 
> > &#65533;\&#65533;W&#65533;p&#65533;`&#1566;??V&#65533;?) as schema hash 
> > is an md5 digest and md5 hashes are binary data so in this case I was 
> > converting to a string like this System.out.println("Schema hash is " + 
> > new String(decoder.readBin128()));
> > 
> > So I converted this non printable characters to hex (with Rafael's 
> > advice just to get rid off these some unknown character) by using 
> > org.apache.qpidity.transport.util.Functions.str(decoder.readBin128()) 
> > method. so the schema hash printed as (Schema is: 
> > "\x85\x5c\xea\x96W\xe3p\xcc`\xd8\x9e\x1a\x08V\xa4\x0e")...
> > 
> > 1) I want to see the Schema hash in the correct way ? How would I 
> > print it?
> 
> I don't think you want to print the hash, you only need it for sending
> further requests. So, the hash is only 16 bytes of opaque binary, that's
> all. 
> 
> > -----
> > 
> > As i was ignoring what i was getting for "schema hash" field (hax 
> > value) and moving on to next field... i.e. propCnt (properties 
> > content), i am doing this
> >   int propCnt = decoder.readUint16();
> > System.out.println("Property content: " + propCnt);
> > 
> > for( int i = 0; i < propCnt; i++ )
> > {
> > Map<String,Object> map = decoder.readMap();
> > printMap(map);
> > }
> >   public void printMap(Map mapnew)
> > {
> > Set s=mapnew.entrySet();
> > Iterator it=s.iterator();
> > for (Iterator iterator = s.iterator(); iterator.hasNext();) {
> > Object object = (Object) iterator.next();
> > System.out.println(object.toString());
> > 
> > }
> >   
> > BUT, getting an exception here
> > A
> > M
> > 1
> > s
> > 15
> > Package Name: qpid
> > Class Name: vhost
> > Schema is: "\x85\x5c\xea\x96W\xe3p\xcc`\xd8\x9e\x1a\x08V\xa4\x0e"
> > Property content:   2
> > code is : 6
> > 
> > Error reading messagejava.lang.IllegalArgumentException: unknown code: 6
> >          at 
> > org.apache.qpidity.transport.codec.AbstractDecoder.getType(AbstractDecoder.java:302)
> >          at 
> > org.apache.qpidity.transport.codec.AbstractDecoder.readMap(AbstractDecoder.java:253)
> > 	at apache.qpid.client.ListenerReply.onMessage(ListenerReply.java:109)
> >          at 
> > org.apache.qpidity.nclient.util.MessagePartListenerAdapter.messageReceived(MessagePartListenerAdapter.java:56)
> >          at 
> > org.apache.qpidity.nclient.impl.ClientSessionDelegate.data(ClientSessionDelegate.java:41)
> >          at 
> > org.apache.qpidity.transport.SessionDelegate.data(SessionDelegate.java:1)
> > 	at org.apache.qpidity.transport.Data.delegate(Data.java:78)
> > 	at org.apache.qpidity.transport.Channel.data(Channel.java:114)
> > 	at org.apache.qpidity.transport.Channel.data(Channel.java:1)
> > 	at org.apache.qpidity.transport.Data.delegate(Data.java:78)
> > 	at org.apache.qpidity.transport.Channel.received(Channel.java:75)
> > 	at org.apache.qpidity.transport.Connection.received(Connection.java:84)
> > 	at org.apache.qpidity.transport.Connection.received(Connection.java:1)
> >     at 
> > org.apache.qpidity.transport.network.Assembler.emit(Assembler.java:92)
> >     at 
> > org.apache.qpidity.transport.network.Assembler.emit(Assembler.java:97)
> >     at 
> > org.apache.qpidity.transport.network.Assembler.frame(Assembler.java:125)
> > 	at org.apache.qpidity.transport.network.Frame.delegate(Frame.java:145)
> >          at 
> > org.apache.qpidity.transport.network.Assembler.received(Assembler.java:102)
> >          at 
> > org.apache.qpidity.transport.network.Assembler.received(Assembler.java:1)
> >          at 
> > org.apache.qpidity.transport.network.InputHandler.frame(InputHandler.java:103)
> >          at 
> > org.apache.qpidity.transport.network.InputHandler.next(InputHandler.java:204)
> >          at 
> > org.apache.qpidity.transport.network.InputHandler.received(InputHandler.java:116)
> >          at 
> > org.apache.qpidity.transport.network.InputHandler.received(InputHandler.java:1)
> >          at 
> > org.apache.qpidity.transport.network.mina.MinaHandler.messageReceived(MinaHandler.java:87)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(AbstractIoFilterChain.java:703)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:54)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain$HeadFilter.messageReceived(AbstractIoFilterChain.java:617)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain.fireMessageReceived(AbstractIoFilterChain.java:353)
> >          at 
> > org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:281)
> >          at 
> > org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:241)
> >          at 
> > org.apache.mina.transport.socket.nio.SocketIoProcessor.access$500(SocketIoProcessor.java:44)
> >          at 
> > org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:559)
> >          at 
> > org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
> > 	at java.lang.Thread.run(Thread.java:619)
> > 
> > 
> > I have just an idea why it is raising but how to mitigate it I dont 
> > know.
> > 
> > 2) How to fix it? Can anyone help me?
> 
> Looking at http://cwiki.apache.org/qpid/management-design-notes.html,
> the message format is as follows: 
> 	+-----+-----+-----+-----+-----------------------+
>         | 'A' | 'M' | '1' | 's' |          seq          |
>         +-----+-----+-----+-----+-----------------------+----------+
>         |                packageName (short string)                |
>         +----------------------------------------------------------+
>         |                className (short string)                  |
>         +----------------------------------------------------------+
>         |                schema-hash (bin128)                      |
>         +-----------+-----------+-----------+-----------+----------+
>         | propCnt   | statCnt   | methodCnt | eventCnt  |
>          
>  
> +-----------+-----------+-----------+-----------+----------------------------+
>         | propCnt property records |
>          
>  
> +----------------------------------------------------------------------------+
>         | statCnt statistic records |
>          
>  
> +----------------------------------------------------------------------------+
>         | methodCnt method records |
>          
>  
> +----------------------------------------------------------------------------+
>         | eventCnt event records |
>          
>  
> +----------------------------------------------------------------------------+
> 
> This means that you need to read propCnt, statCnt, methodCnt and then
> eventCnt before you can read propCnt maps. statCnt maps, methodCnt maps
> and then eventCnt maps. You are currently not reading statCnt, methodCnt
> and eventCnt. 
> 
> 
> Arnaud
> 
> 
> 

Re: Java Client - Question

Posted by me...@cs.man.ac.uk.
Hi Arnaud,

Original Code is here which I attached in my previous email (I will update 
it with your previous comments e.g. remove printMap method)

SendMessage.java:


package apache.qpid.client;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import org.apache.qpidity.nclient.Client;
import org.apache.qpidity.nclient.Connection;
import org.apache.qpidity.nclient.Session;
import org.apache.qpidity.transport.DeliveryProperties;
import org.apache.qpidity.transport.MessageAcceptMode;
import org.apache.qpidity.transport.MessageAcquireMode;
import org.apache.qpidity.transport.MessageProperties;
import org.apache.qpidity.transport.ReplyTo;

/*
 * this sends the "Class Query" and "Schema Request" to the broker
 */
public class SendMessage
{	// AMQP type
	String opcode;
/*	int sequenceNo;
	String packageName; 
	String schemaHash;
	String classname;*/

	public static void main(String[] args)
	{
		SendMessage p=new SendMessage();
		// Create connection
		Connection con = Client.createConnection();
		ByteBuffer message= ByteBuffer.allocate(100);
		try
		{	// connect to local host on default port 5672
		con.connect("localhost", 5672, "test", "guest", "guest");
		}
		catch(Exception e)
		{
		System.out.print("Error connecting to broker");
		e.printStackTrace();
		}

		// Create session
		Session session = con.createSession(0);
		DeliveryProperties deliveryProps = new DeliveryProperties();
		// set the routing key as "agent"
		deliveryProps.setRoutingKey("agent");
		MessageProperties messageProps=new MessageProperties();
	// set replyTo field so that messages return to the "reply" queue  
		ReplyTo rpt=new ReplyTo();
		rpt.setExchange("amq.direct");
		rpt.setRoutingKey("reply");
		messageProps.setReplyTo(rpt);

		// transfer message to "qpid.management" exchange
                 session.messageTransfer("qpid.management", 
MessageAcceptMode.EXPLICIT,MessageAcquireMode.PRE_ACQUIRED);
		session.header(deliveryProps,messageProps);
		/*
		 * JUST FOR TEST
		 * Read input from keyboard
		 * if user enters 1 so it sends the "Class Query" or if
                 * enters 2 then it means client sends
		 * the "Schema Request" 
		 */
		System.out.println("Enter an opertion ");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int i=0;
		try {
			i = Integer.parseInt(br.readLine().trim());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 

		switch (i)
		{
		/*
                  * if user enters 1 then a "Class Query" message will be 
sent to the broker
		 * 
		 *  +-----+-----+-----+-----+-----------------------+
        	| 'A' | 'M' | '1' | 'Q' |          seq          |
        	+-----+-----+-----+-----+-----------------------+----------+
        	|  package name (short string)                             |
        	+----------------------------------------------------------+

		 */
		case 1:

			p.opcode="AM1Q";
         //p.sequenceNo=100; p.packageName="qpid"; p.classname="exchange"; 
/* * I am wondering I am sending only the type/opcode (e.g. AM1Q) and it 
works * unlike what the format mentioned above (according to 
management-design notes) * 
http://cwiki.apache.org/qpid/management-design-notes.html
 */

			message.clear();
			try {
				message.put(p.opcode.getBytes("UTF-8"));
			} catch (UnsupportedEncodingException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			break;

			/*
 * if user enters 2 then a "Schema request" message will be sent to the 
broker
		 *   +-----+-----+-----+-----+-----------------------+
       		| 'A' | 'M' | '1' | 'S' |          seq          |
       		+-----+-----+-----+-----+-----------------------+----------+
       		|                packageName (short string)                |
       		+----------------------------------------------------------+
       		|                className (short string)                  |
       		+----------------------------------------------------------+
       		|                schema-hash (bin128)                      |
       		+----------------------------------------------------------+
				
			 */
		case 2:
			p.opcode="AM1S";
         //p.sequenceNo=100; p.packageName="qpid"; p.classname="exchange"; 
/* * I am wondering I am only sending the type/opcode (e.g. AM1S) and it 
works... * unlike what the format mentioned above (according to 
management-design notes) * 
http://cwiki.apache.org/qpid/management-design-notes.html */
			message.clear();
			try {
				message.put(p.opcode.getBytes("UTF-8"));
			
			} catch (UnsupportedEncodingException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
			break;

		default:
			break;
		}
		message.flip();
		// send message
		session.data(message);
		session.endData();
		// confirm completion
		session.sync();
		//cleanup
		session.sessionDetach(session.getName());
		try
		{	// clise connection
			con.close();
		}
		catch(Exception e)
		{
			System.out.print("Error closing broker connection");
			e.printStackTrace();
		}
	}
}


ListenerReply.java:


package apache.qpid.client;

import java.nio.ByteBuffer;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import org.apache.qpidity.api.Message;
import org.apache.qpidity.nclient.Client;
import org.apache.qpidity.nclient.Connection;
import org.apache.qpidity.nclient.Session;
import org.apache.qpidity.nclient.util.MessageListener;
import org.apache.qpidity.nclient.util.MessagePartListenerAdapter;

import org.apache.qpidity.transport.MessageCreditUnit;

/**
 * This listen messages on reply queue and terminates
 * when it sees the final message
 *
 */
public class ListenerReply implements MessageListener
{
	ByteBuffer buf;
	public void onMessage(Message m)
	{
		try
		{
			buf = m.readData();
			// get the Magic number "AM1"
			char magicNumber = (char)buf.get();
			System.out.println(magicNumber);
			magicNumber = (char)buf.get();
			System.out.println(magicNumber);
			magicNumber = (char)buf.get();
			System.out.println(magicNumber);
			// get the opcode
			char opcode = (char)buf.get();
			System.out.println(opcode);
			// java decoder
			ManagementDecoder decoder = new ManagementDecoder(buf);
			// get the decoded sequence number
			System.out.println(decoder.readSequenceNo());

			switch (opcode) {
		
	/*
	* if the response is "query indication"
	*  +-----+-----+-----+-----+-----------------------+
        | 'A' | 'M' | '1' | 'q' |          seq          |
        +-----+-----+-----+-----+-----------------------+----------+
        |  package name (short string)                             |
        +----------------------------------------------------------+
        |  class name (short string)                               |
        +----------------------------------------------------------+
        |  schema hash (bin128)                                    |
        +----------------------------------------------------------+

		*/
			case 'q':
				// decode the package name
				String packagename = decoder.readStr8();
				// decode the class name
				String classname = decoder.readStr8();
			System.out.println("Package Name: " + packagename);
			System.out.println("Class Name: " + classname);
                                 // decode the schema hash // TODO: this 
prints the hexa value of schema... need to be printed in readable 
System.out.println("Schema hash is: " + 
org.apache.qpidity.transport.util.Functions.str(decoder.readBin128())); 
//System.out.println("Schema hash is: " + decoder.readUint64() + 
decoder.readUint64()); break;
		/*
		* if the response is "schema response"
* +-----+-----+-----+-----+-----------------------+
  | 'A' | 'M' | '1' | 's' |          seq          |
  +-----+-----+-----+-----+-----------------------+----------+
  |                packageName (short string)                |
  +----------------------------------------------------------+
  |                className (short string)                  |
  +----------------------------------------------------------+
  |                schema-hash (bin128)                      |
  +-----------+-----------+-----------+-----------+----------+
  | propCnt   | statCnt   | methodCnt | eventCnt  |
   
+-----------+-----------+-----------+-----------+----------------------------+
  | propCnt property records |
   
+----------------------------------------------------------------------------+
  | statCnt statistic records |
   
+----------------------------------------------------------------------------+
  | methodCnt method records |
   
+----------------------------------------------------------------------------+
  | eventCnt event records |
   
+----------------------------------------------------------------------------+
 */
			case 's':
			String packname = decoder.readStr8();
			String clasnam = decoder.readStr8();

			System.out.println("Package Name: " + packname);
                         System.out.println("Class Name: " + clasnam); // 
Added new method i.e. readBin128() in AbstractDecoder.java (under 
org.apache.qpidity.transport.codec) for decoding 16 bytes of opaque binary 
data // TODO: this prints the hexa value of schema... need to be printed in 
readable System.out.println("Schema is: " + 
org.apache.qpidity.transport.util.Functions.str(decoder.readBin128()));
	// get the decoded properties contents
	int propCnt = decoder.readUint16();
	System.out.println("Property content:   " + propCnt);
	for( int i = 0; i < propCnt; i++ )
	{	// decode the MAP
// FIXME: getting exception here "java.lang.IllegalArgumentException:
// unknown code: 6"
	Map<String,Object> map = decoder.readMap();
	printMap(map);
	}
// TODO: Also do the same for statistic records, method records, 
// event records     
	break;
			
			default:
			break;
			}
		}
		catch(Exception e)
		{
			System.out.print("Error reading message");
			e.printStackTrace();
		}
	}
	/*
	 * print the decoded map
	 * TODO: fix the warning and comment it when it works
	 */
	public void printMap(Map mapnew)
	{
		Set s=mapnew.entrySet();
		Iterator it=s.iterator();
		for (Iterator iterator = s.iterator(); iterator.hasNext();) 
		{
			Object object = (Object) iterator.next();
			System.out.println(object.toString());
		}
	}

	
	public static void main(String[] args)
	{
		// Create connection
		Connection con = Client.createConnection();
		try
		{	// connect to local host on default port 5672
	con.connect("localhost", 5672, "test", "guest", "guest");
		}
		catch(Exception e)
		{
			System.out.print("Error connecting to broker");
			e.printStackTrace();
		}
		// Create session
		Session session = con.createSession(0);
		// Create an instance of the listener
		ListenerReply listener = new ListenerReply();
		// create a subscription with the "reply" queue
		session.messageSubscribe("reply",
				"listener_reply",
				Session.TRANSFER_CONFIRM_MODE_NOT_REQUIRED,
				Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE,
				new MessagePartListenerAdapter(listener), null);
		// controls the flow of message data to a given destination
                 session.messageFlow("listener_reply", 
MessageCreditUnit.BYTE, Session.MESSAGE_FLOW_MAX_BYTES);
		// will get maximum of 11 messages
		session.messageFlow("listener_reply", MessageCreditUnit.MESSAGE, 11);
		// confirm completion
		session.sync();
                 // This method cancels a consumer. The server will not 
send any more messages to the "listener_reply" destination.
		session.messageCancel("listener_reply");
		//cleanup
		session.sessionDetach(session.getName());
		try
		{	// close connection
			con.close();
		}
		catch(Exception e)
		{
			System.out.print("Error closing broker connection");
			e.printStackTrace();
		}
	}

}



-------

Best Regards,
Rahul

On Jun 27 2008, Arnaud Simon wrote:

> Hi,
> 
> > Rafael mentioned last night that AbastractDecoder does not know it so 
> > we added another method i.e. readBin128() in AbstractDecoder.java 
> > (under org.apache.qpidity.transport.codec) for decoding 16 bytes of 
> > opaque binary data. It produced some unknown characters (e.g. output: 
> > Schema hash is: 
> > &#65533;\&#65533;W&#65533;p&#65533;`&#1566;??V&#65533;?) as schema hash 
> > is an md5 digest and md5 hashes are binary data so in this case I was 
> > converting to a string like this System.out.println("Schema hash is " + 
> > new String(decoder.readBin128()));
> > 
> > So I converted this non printable characters to hex (with Rafael's 
> > advice just to get rid off these some unknown character) by using 
> > org.apache.qpidity.transport.util.Functions.str(decoder.readBin128()) 
> > method. so the schema hash printed as (Schema is: 
> > "\x85\x5c\xea\x96W\xe3p\xcc`\xd8\x9e\x1a\x08V\xa4\x0e")...
> > 
> > 1) I want to see the Schema hash in the correct way ? How would I 
> > print it?
> 
> I don't think you want to print the hash, you only need it for sending
> further requests. So, the hash is only 16 bytes of opaque binary, that's
> all. 
> 
> > -----
> > 
> > As i was ignoring what i was getting for "schema hash" field (hax 
> > value) and moving on to next field... i.e. propCnt (properties 
> > content), i am doing this
> >   int propCnt = decoder.readUint16();
> > System.out.println("Property content: " + propCnt);
> > 
> > for( int i = 0; i < propCnt; i++ )
> > {
> > Map<String,Object> map = decoder.readMap();
> > printMap(map);
> > }
> >   public void printMap(Map mapnew)
> > {
> > Set s=mapnew.entrySet();
> > Iterator it=s.iterator();
> > for (Iterator iterator = s.iterator(); iterator.hasNext();) {
> > Object object = (Object) iterator.next();
> > System.out.println(object.toString());
> > 
> > }
> >   
> > BUT, getting an exception here
> > A
> > M
> > 1
> > s
> > 15
> > Package Name: qpid
> > Class Name: vhost
> > Schema is: "\x85\x5c\xea\x96W\xe3p\xcc`\xd8\x9e\x1a\x08V\xa4\x0e"
> > Property content:   2
> > code is : 6
> > 
> > Error reading messagejava.lang.IllegalArgumentException: unknown code: 6
> >          at 
> > org.apache.qpidity.transport.codec.AbstractDecoder.getType(AbstractDecoder.java:302)
> >          at 
> > org.apache.qpidity.transport.codec.AbstractDecoder.readMap(AbstractDecoder.java:253)
> > 	at apache.qpid.client.ListenerReply.onMessage(ListenerReply.java:109)
> >          at 
> > org.apache.qpidity.nclient.util.MessagePartListenerAdapter.messageReceived(MessagePartListenerAdapter.java:56)
> >          at 
> > org.apache.qpidity.nclient.impl.ClientSessionDelegate.data(ClientSessionDelegate.java:41)
> >          at 
> > org.apache.qpidity.transport.SessionDelegate.data(SessionDelegate.java:1)
> > 	at org.apache.qpidity.transport.Data.delegate(Data.java:78)
> > 	at org.apache.qpidity.transport.Channel.data(Channel.java:114)
> > 	at org.apache.qpidity.transport.Channel.data(Channel.java:1)
> > 	at org.apache.qpidity.transport.Data.delegate(Data.java:78)
> > 	at org.apache.qpidity.transport.Channel.received(Channel.java:75)
> > 	at org.apache.qpidity.transport.Connection.received(Connection.java:84)
> > 	at org.apache.qpidity.transport.Connection.received(Connection.java:1)
> >     at 
> > org.apache.qpidity.transport.network.Assembler.emit(Assembler.java:92)
> >     at 
> > org.apache.qpidity.transport.network.Assembler.emit(Assembler.java:97)
> >     at 
> > org.apache.qpidity.transport.network.Assembler.frame(Assembler.java:125)
> > 	at org.apache.qpidity.transport.network.Frame.delegate(Frame.java:145)
> >          at 
> > org.apache.qpidity.transport.network.Assembler.received(Assembler.java:102)
> >          at 
> > org.apache.qpidity.transport.network.Assembler.received(Assembler.java:1)
> >          at 
> > org.apache.qpidity.transport.network.InputHandler.frame(InputHandler.java:103)
> >          at 
> > org.apache.qpidity.transport.network.InputHandler.next(InputHandler.java:204)
> >          at 
> > org.apache.qpidity.transport.network.InputHandler.received(InputHandler.java:116)
> >          at 
> > org.apache.qpidity.transport.network.InputHandler.received(InputHandler.java:1)
> >          at 
> > org.apache.qpidity.transport.network.mina.MinaHandler.messageReceived(MinaHandler.java:87)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(AbstractIoFilterChain.java:703)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:54)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain$HeadFilter.messageReceived(AbstractIoFilterChain.java:617)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
> >          at 
> > org.apache.mina.common.support.AbstractIoFilterChain.fireMessageReceived(AbstractIoFilterChain.java:353)
> >          at 
> > org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:281)
> >          at 
> > org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:241)
> >          at 
> > org.apache.mina.transport.socket.nio.SocketIoProcessor.access$500(SocketIoProcessor.java:44)
> >          at 
> > org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:559)
> >          at 
> > org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
> > 	at java.lang.Thread.run(Thread.java:619)
> > 
> > 
> > I have just an idea why it is raising but how to mitigate it I dont 
> > know.
> > 
> > 2) How to fix it? Can anyone help me?
> 
> Looking at http://cwiki.apache.org/qpid/management-design-notes.html,
> the message format is as follows: 
> 	+-----+-----+-----+-----+-----------------------+
>         | 'A' | 'M' | '1' | 's' |          seq          |
>         +-----+-----+-----+-----+-----------------------+----------+
>         |                packageName (short string)                |
>         +----------------------------------------------------------+
>         |                className (short string)                  |
>         +----------------------------------------------------------+
>         |                schema-hash (bin128)                      |
>         +-----------+-----------+-----------+-----------+----------+
>         | propCnt   | statCnt   | methodCnt | eventCnt  |
>          
>  
> +-----------+-----------+-----------+-----------+----------------------------+
>         | propCnt property records |
>          
>  
> +----------------------------------------------------------------------------+
>         | statCnt statistic records |
>          
>  
> +----------------------------------------------------------------------------+
>         | methodCnt method records |
>          
>  
> +----------------------------------------------------------------------------+
>         | eventCnt event records |
>          
>  
> +----------------------------------------------------------------------------+
> 
> This means that you need to read propCnt, statCnt, methodCnt and then
> eventCnt before you can read propCnt maps. statCnt maps, methodCnt maps
> and then eventCnt maps. You are currently not reading statCnt, methodCnt
> and eventCnt. 
> 
> 
> Arnaud
> 
> 
> 

Re: Java Client - Question

Posted by Arnaud Simon <as...@redhat.com>.
Hi,

> Rafael mentioned last night that AbastractDecoder does not know it so we 
> added another method i.e. readBin128() in AbstractDecoder.java (under 
> org.apache.qpidity.transport.codec) for decoding 16 bytes of opaque binary 
> data. It produced some unknown characters (e.g. output: Schema hash is: 
> &#65533;\&#65533;W&#65533;p&#65533;`&#1566;??V&#65533;?) as schema hash is 
> an md5 digest and md5 hashes are binary data so in this case I was 
> converting to a string like this System.out.println("Schema hash is " + new 
> String(decoder.readBin128()));
> 
> So I converted this non printable characters to hex (with Rafael's advice 
> just to get rid off these some unknown character) by using 
> org.apache.qpidity.transport.util.Functions.str(decoder.readBin128()) 
> method. so the schema hash printed as (Schema is: 
> "\x85\x5c\xea\x96W\xe3p\xcc`\xd8\x9e\x1a\x08V\xa4\x0e")...
> 
> 1) I want to see the Schema hash in the correct way ? How would I print it?

I don't think you want to print the hash, you only need it for sending
further requests. So, the hash is only 16 bytes of opaque binary, that's
all. 

> -----
> 
> As i was ignoring what i was getting for "schema hash" field (hax value) 
> and moving on to next field... i.e. propCnt (properties content), i am 
> doing this
>   int propCnt = decoder.readUint16();
> System.out.println("Property content: " + propCnt);
> 
> for( int i = 0; i < propCnt; i++ )
> {
> Map<String,Object> map = decoder.readMap();
> printMap(map);
> }
>   public void printMap(Map mapnew)
> {
> Set s=mapnew.entrySet();
> Iterator it=s.iterator();
> for (Iterator iterator = s.iterator(); iterator.hasNext();) {
> Object object = (Object) iterator.next();
> System.out.println(object.toString());
> 
> }
>   
> BUT, getting an exception here
> A
> M
> 1
> s
> 15
> Package Name: qpid
> Class Name: vhost
> Schema is: "\x85\x5c\xea\x96W\xe3p\xcc`\xd8\x9e\x1a\x08V\xa4\x0e"
> Property content:   2
> code is : 6
> 
> Error reading messagejava.lang.IllegalArgumentException: unknown code: 6
>          at 
> org.apache.qpidity.transport.codec.AbstractDecoder.getType(AbstractDecoder.java:302)
>          at 
> org.apache.qpidity.transport.codec.AbstractDecoder.readMap(AbstractDecoder.java:253)
> 	at apache.qpid.client.ListenerReply.onMessage(ListenerReply.java:109)
>          at 
> org.apache.qpidity.nclient.util.MessagePartListenerAdapter.messageReceived(MessagePartListenerAdapter.java:56)
>          at 
> org.apache.qpidity.nclient.impl.ClientSessionDelegate.data(ClientSessionDelegate.java:41)
>          at 
> org.apache.qpidity.transport.SessionDelegate.data(SessionDelegate.java:1)
> 	at org.apache.qpidity.transport.Data.delegate(Data.java:78)
> 	at org.apache.qpidity.transport.Channel.data(Channel.java:114)
> 	at org.apache.qpidity.transport.Channel.data(Channel.java:1)
> 	at org.apache.qpidity.transport.Data.delegate(Data.java:78)
> 	at org.apache.qpidity.transport.Channel.received(Channel.java:75)
> 	at org.apache.qpidity.transport.Connection.received(Connection.java:84)
> 	at org.apache.qpidity.transport.Connection.received(Connection.java:1)
> 	at org.apache.qpidity.transport.network.Assembler.emit(Assembler.java:92)
> 	at org.apache.qpidity.transport.network.Assembler.emit(Assembler.java:97)
> 	at org.apache.qpidity.transport.network.Assembler.frame(Assembler.java:125)
> 	at org.apache.qpidity.transport.network.Frame.delegate(Frame.java:145)
>          at 
> org.apache.qpidity.transport.network.Assembler.received(Assembler.java:102)
>          at 
> org.apache.qpidity.transport.network.Assembler.received(Assembler.java:1)
>          at 
> org.apache.qpidity.transport.network.InputHandler.frame(InputHandler.java:103)
>          at 
> org.apache.qpidity.transport.network.InputHandler.next(InputHandler.java:204)
>          at 
> org.apache.qpidity.transport.network.InputHandler.received(InputHandler.java:116)
>          at 
> org.apache.qpidity.transport.network.InputHandler.received(InputHandler.java:1)
>          at 
> org.apache.qpidity.transport.network.mina.MinaHandler.messageReceived(MinaHandler.java:87)
>          at 
> org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(AbstractIoFilterChain.java:703)
>          at 
> org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
>          at 
> org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:54)
>          at 
> org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
>          at 
> org.apache.mina.common.support.AbstractIoFilterChain$HeadFilter.messageReceived(AbstractIoFilterChain.java:617)
>          at 
> org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
>          at 
> org.apache.mina.common.support.AbstractIoFilterChain.fireMessageReceived(AbstractIoFilterChain.java:353)
>          at 
> org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:281)
>          at 
> org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:241)
>          at 
> org.apache.mina.transport.socket.nio.SocketIoProcessor.access$500(SocketIoProcessor.java:44)
>          at 
> org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:559)
>          at 
> org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
> 	at java.lang.Thread.run(Thread.java:619)
> 
> 
> I have just an idea why it is raising but how to mitigate it I dont know.
> 
> 2) How to fix it? Can anyone help me?

Looking at http://cwiki.apache.org/qpid/management-design-notes.html,
the message format is as follows: 
	+-----+-----+-----+-----+-----------------------+
        | 'A' | 'M' | '1' | 's' |          seq          |
        +-----+-----+-----+-----+-----------------------+----------+
        |                packageName (short string)                |
        +----------------------------------------------------------+
        |                className (short string)                  |
        +----------------------------------------------------------+
        |                schema-hash (bin128)                      |
        +-----------+-----------+-----------+-----------+----------+
        | propCnt   | statCnt   | methodCnt | eventCnt  |
        +-----------+-----------+-----------+-----------+----------------------------+
        | propCnt property records                                                   |
        +----------------------------------------------------------------------------+
        | statCnt statistic records                                                  |
        +----------------------------------------------------------------------------+
        | methodCnt method records                                                   |
        +----------------------------------------------------------------------------+
        | eventCnt event records                                                     |
        +----------------------------------------------------------------------------+

This means that you need to read propCnt, statCnt, methodCnt and then
eventCnt before you can read propCnt maps. statCnt maps, methodCnt maps
and then eventCnt maps. You are currently not reading statCnt, methodCnt
and eventCnt. 


Arnaud



Re: Java Client - Question

Posted by me...@cs.man.ac.uk.
Hi Arnaud/Ted/Carl/Rafael/Rajith,

I have some questions on "Schema Response" message. (I am trying to fetch 
the management schema for classes broker knows).

First, how do we decode the "Schema-hash" field from the AM1s 
("Schema-Response" method).

Rafael mentioned last night that AbastractDecoder does not know it so we 
added another method i.e. readBin128() in AbstractDecoder.java (under 
org.apache.qpidity.transport.codec) for decoding 16 bytes of opaque binary 
data. It produced some unknown characters (e.g. output: Schema hash is: 
&#65533;\&#65533;W&#65533;p&#65533;`&#1566;??V&#65533;?) as schema hash is 
an md5 digest and md5 hashes are binary data so in this case I was 
converting to a string like this System.out.println("Schema hash is " + new 
String(decoder.readBin128()));

So I converted this non printable characters to hex (with Rafael's advice 
just to get rid off these some unknown character) by using 
org.apache.qpidity.transport.util.Functions.str(decoder.readBin128()) 
method. so the schema hash printed as (Schema is: 
"\x85\x5c\xea\x96W\xe3p\xcc`\xd8\x9e\x1a\x08V\xa4\x0e")...

1) I want to see the Schema hash in the correct way ? How would I print it?

-----

As i was ignoring what i was getting for "schema hash" field (hax value) 
and moving on to next field... i.e. propCnt (properties content), i am 
doing this
  int propCnt = decoder.readUint16();
System.out.println("Property content: " + propCnt);

for( int i = 0; i < propCnt; i++ )
{
Map<String,Object> map = decoder.readMap();
printMap(map);
}
  public void printMap(Map mapnew)
{
Set s=mapnew.entrySet();
Iterator it=s.iterator();
for (Iterator iterator = s.iterator(); iterator.hasNext();) {
Object object = (Object) iterator.next();
System.out.println(object.toString());

}
  
BUT, getting an exception here
A
M
1
s
15
Package Name: qpid
Class Name: vhost
Schema is: "\x85\x5c\xea\x96W\xe3p\xcc`\xd8\x9e\x1a\x08V\xa4\x0e"
Property content:   2
code is : 6

Error reading messagejava.lang.IllegalArgumentException: unknown code: 6
         at 
org.apache.qpidity.transport.codec.AbstractDecoder.getType(AbstractDecoder.java:302)
         at 
org.apache.qpidity.transport.codec.AbstractDecoder.readMap(AbstractDecoder.java:253)
	at apache.qpid.client.ListenerReply.onMessage(ListenerReply.java:109)
         at 
org.apache.qpidity.nclient.util.MessagePartListenerAdapter.messageReceived(MessagePartListenerAdapter.java:56)
         at 
org.apache.qpidity.nclient.impl.ClientSessionDelegate.data(ClientSessionDelegate.java:41)
         at 
org.apache.qpidity.transport.SessionDelegate.data(SessionDelegate.java:1)
	at org.apache.qpidity.transport.Data.delegate(Data.java:78)
	at org.apache.qpidity.transport.Channel.data(Channel.java:114)
	at org.apache.qpidity.transport.Channel.data(Channel.java:1)
	at org.apache.qpidity.transport.Data.delegate(Data.java:78)
	at org.apache.qpidity.transport.Channel.received(Channel.java:75)
	at org.apache.qpidity.transport.Connection.received(Connection.java:84)
	at org.apache.qpidity.transport.Connection.received(Connection.java:1)
	at org.apache.qpidity.transport.network.Assembler.emit(Assembler.java:92)
	at org.apache.qpidity.transport.network.Assembler.emit(Assembler.java:97)
	at org.apache.qpidity.transport.network.Assembler.frame(Assembler.java:125)
	at org.apache.qpidity.transport.network.Frame.delegate(Frame.java:145)
         at 
org.apache.qpidity.transport.network.Assembler.received(Assembler.java:102)
         at 
org.apache.qpidity.transport.network.Assembler.received(Assembler.java:1)
         at 
org.apache.qpidity.transport.network.InputHandler.frame(InputHandler.java:103)
         at 
org.apache.qpidity.transport.network.InputHandler.next(InputHandler.java:204)
         at 
org.apache.qpidity.transport.network.InputHandler.received(InputHandler.java:116)
         at 
org.apache.qpidity.transport.network.InputHandler.received(InputHandler.java:1)
         at 
org.apache.qpidity.transport.network.mina.MinaHandler.messageReceived(MinaHandler.java:87)
         at 
org.apache.mina.common.support.AbstractIoFilterChain$TailFilter.messageReceived(AbstractIoFilterChain.java:703)
         at 
org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
         at 
org.apache.mina.common.support.AbstractIoFilterChain.access$1200(AbstractIoFilterChain.java:54)
         at 
org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:800)
         at 
org.apache.mina.common.support.AbstractIoFilterChain$HeadFilter.messageReceived(AbstractIoFilterChain.java:617)
         at 
org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:362)
         at 
org.apache.mina.common.support.AbstractIoFilterChain.fireMessageReceived(AbstractIoFilterChain.java:353)
         at 
org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:281)
         at 
org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:241)
         at 
org.apache.mina.transport.socket.nio.SocketIoProcessor.access$500(SocketIoProcessor.java:44)
         at 
org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:559)
         at 
org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
	at java.lang.Thread.run(Thread.java:619)


I have just an idea why it is raising but how to mitigate it I dont know.

2) How to fix it? Can anyone help me?

I am attaching my TEST code (two java programs) here for your consideration:

SendMessage.java sends the "Class Query" and "Schema Request" to the broker 
ListenerReply.java listens messages on "reply" queue * Please note: Before 
these two programs, I created two Queues (management and reply) and bound 
them on qpid.exchange and amq.direct exchanges respectively. I am using the 
Qpid C++ broker.

Look forward to hearing from you.
Thank you,

BR,
Rahul
On Jun 23 2008, Ted Ross wrote:

> mehtar@cs.man.ac.uk wrote:
> > Hi Arnaud,
> >
> > Thanks for your help. Your sample codes are really very useful to get 
> > an idea. At this moment, I can fetch the following information 
> > (decoded) from the broker by "management" queue bound on 
> > "qpid.management" exchange.
> >
> >
> > A
> > M
> > 1
> > c
> > 0
> > Package Name: qpid
> > Class Name: broker
> > -6506066772830834859
> > 3980601858483200060
> > Current Sample: Wed Jul 06 22:54:31 CEST 38476878
> > Object Created: Sat Jul 24 16:10:25 CEST 38476877
> > Object Deleted: Thu Jan 01 01:00:00 CET 1970
> > 16777218
> > --------
> > A
> > M
> > 1
> > c
> > 0
> > Package Name: qpid
> > Class Name: vhost
> > -8836930437367238452
> > 6978501457256817678
> > Current Sample: Wed Jul 06 22:55:54 CEST 38476878
> > Object Created: Sat Jul 24 16:10:31 CEST 38476877
> > Object Deleted: Thu Jan 01 01:00:00 CET 1970
> > 16777219
> > -------------
> >
> > A
> > M
> > 1
> > c
> > 0
> > Package Name: qpid
> > Class Name: exchange
> > -5418781513850411724
> > -4895665811244006470
> > Current Sample: Wed Jul 06 22:57:02 CEST 38476878
> > Object Created: Sat Jul 24 16:11:00 CEST 38476877
> > Object Deleted: Thu Jan 01 01:00:00 CET 1970
> > 33554433
> > ------------
> > A
> > M
> > 1
> > c
> > 0
> > Package Name: qpid
> > Class Name: client
> > 2274936829591414069
> > 7716666671830073968
> > Current Sample: Wed Jul 06 23:10:41 CEST 38476878
> > Object Created: Thu Oct 14 02:14:24 CEST 38476877
> > Object Deleted: Thu Jan 01 01:00:00 CET 1970
> > 19421773476921347
> > ---------------
> > A
> > M
> > 1
> > c
> > 0
> > Package Name: qpid
> > Class Name: session
> > 7627530833415044037
> > 7647849998445955049
> > Current Sample: Wed Jul 06 23:12:52 CEST 38476878
> > Object Created: Fri Oct 15 13:01:40 CEST 38476877
> > Object Deleted: Thu Jan 01 01:00:00 CET 1970
> > 19421773476921348
> > --------------
> > A
> > M
> > 1
> > i
> > 0
> > Package Name: qpid
> > Class Name: queue
> > 1347274480851610151
> > 7548280486574577882
> > Current Sample: Wed Jul 06 23:16:10 CEST 38476878
> > Object Created: Fri Oct 15 13:03:14 CEST 38476877
> > Object Deleted: Thu Jan 01 01:00:00 CET 1970
> > 19421773476921349
> > ------------
> > A
> > M
> > 1
> > h
> > 0
> > Sun Dec 13 05:38:09 CET 38476882
> > -------------------------------------
> >
> > I am wondering if you can give me a sample example to send message to 
> > broker so that I can get the schema from broker. I have another queue 
> > called "reply" bound on "amq.direct" with the routing key "reply" but 
> > dont know how to get the management schema in it (cannt find the 
> > example for sending the message to broker to fetch the management 
> > information). I have read the qpid management notes and now know how 
> > to fetch the schema (in theory) but it will be nice to see the sample.
> >
> > It will also be nice if you can explain a little about management 
> > interface you mentioned.
> >
> > Also, if you can let me know where I can put my work?
> > Just to update you, I started working on a ppt file and on 
> > documentation for this project.
> >
> >
> > Thanks in advance.
> >
> >
> > Best Regards,
> > Rahul
> >
> Rahul,
> 
> To get the schema from the broker, there are three protocol exchanges 
> you need to execute:
> 
> 1) Request the list of schema packages.
> 2) For each package (or the package of interest), request the list of 
> classes.
> 3) For each class (or the class of interest), request the schema details.
> 
> To send protocol messages to the management broker, create the message 
> with AMQP types via the Java encoder/decoder, then send them to the 
> "qpid.management" exchange using "agent" as the routing key.
> 
> Replies will be transmitted according the the key in the replyTo field 
> of the message.  Make sure the replyTo attribute is set on the message 
> (setJMSReplyTo) to amq.direct/reply.
> 
> Here are the protocol references (see 
> http://cwiki.apache.org/confluence/display/qpid/Management+Design+notes 
> for protocol details):
> 
> 1) Request packages by sending a "Package Query" message.  You will 
> receive a "Package Indication" message on your reply queue for each 
> package known to the broker.  The "qpid" package contains classes for 
> the broker itself.
> 
> 2) Request classes-per-package by sending a "Class Query" message.  You 
> will receive a "Class Indication" message for each class in the 
> package.  Note that a class is identified by the following tuple: 
> (package-name, class-name, class-hash).  The hash is included because 
> there may be more than one version of the schema for a particular class.
> 
> 3) To request the schema details for a class, send a "Schema Request" 
> message to the broker.  A "Schema Response" message will be sent in 
> reply which contains the details of the class schema.
> 
> If you have further questions, don't hesitate to ask.
> 
> Regards,
> 
> -Ted
> 
> ?
> 

Re: Java Client - Question

Posted by Ted Ross <tr...@redhat.com>.
mehtar@cs.man.ac.uk wrote:
> Hi Arnaud,
>
> Thanks for your help. Your sample codes are really very useful to get 
> an idea. At this moment, I can fetch the following information 
> (decoded) from the broker by "management" queue bound on 
> "qpid.management" exchange.
>
>
> A
> M
> 1
> c
> 0
> Package Name: qpid
> Class Name: broker
> -6506066772830834859
> 3980601858483200060
> Current Sample: Wed Jul 06 22:54:31 CEST 38476878
> Object Created: Sat Jul 24 16:10:25 CEST 38476877
> Object Deleted: Thu Jan 01 01:00:00 CET 1970
> 16777218
> --------
> A
> M
> 1
> c
> 0
> Package Name: qpid
> Class Name: vhost
> -8836930437367238452
> 6978501457256817678
> Current Sample: Wed Jul 06 22:55:54 CEST 38476878
> Object Created: Sat Jul 24 16:10:31 CEST 38476877
> Object Deleted: Thu Jan 01 01:00:00 CET 1970
> 16777219
> -------------
>
> A
> M
> 1
> c
> 0
> Package Name: qpid
> Class Name: exchange
> -5418781513850411724
> -4895665811244006470
> Current Sample: Wed Jul 06 22:57:02 CEST 38476878
> Object Created: Sat Jul 24 16:11:00 CEST 38476877
> Object Deleted: Thu Jan 01 01:00:00 CET 1970
> 33554433
> ------------
> A
> M
> 1
> c
> 0
> Package Name: qpid
> Class Name: client
> 2274936829591414069
> 7716666671830073968
> Current Sample: Wed Jul 06 23:10:41 CEST 38476878
> Object Created: Thu Oct 14 02:14:24 CEST 38476877
> Object Deleted: Thu Jan 01 01:00:00 CET 1970
> 19421773476921347
> ---------------
> A
> M
> 1
> c
> 0
> Package Name: qpid
> Class Name: session
> 7627530833415044037
> 7647849998445955049
> Current Sample: Wed Jul 06 23:12:52 CEST 38476878
> Object Created: Fri Oct 15 13:01:40 CEST 38476877
> Object Deleted: Thu Jan 01 01:00:00 CET 1970
> 19421773476921348
> --------------
> A
> M
> 1
> i
> 0
> Package Name: qpid
> Class Name: queue
> 1347274480851610151
> 7548280486574577882
> Current Sample: Wed Jul 06 23:16:10 CEST 38476878
> Object Created: Fri Oct 15 13:03:14 CEST 38476877
> Object Deleted: Thu Jan 01 01:00:00 CET 1970
> 19421773476921349
> ------------
> A
> M
> 1
> h
> 0
> Sun Dec 13 05:38:09 CET 38476882
> -------------------------------------
>
> I am wondering if you can give me a sample example to send message to 
> broker so that I can get the schema from broker. I have another queue 
> called "reply" bound on "amq.direct" with the routing key "reply" but 
> dont know how to get the management schema in it (cannt find the 
> example for sending the message to broker to fetch the management 
> information). I have read the qpid management notes and now know how 
> to fetch the schema (in theory) but it will be nice to see the sample.
>
> It will also be nice if you can explain a little about management 
> interface you mentioned.
>
> Also, if you can let me know where I can put my work?
> Just to update you, I started working on a ppt file and on 
> documentation for this project.
>
>
> Thanks in advance.
>
>
> Best Regards,
> Rahul
>
Rahul,

To get the schema from the broker, there are three protocol exchanges 
you need to execute:

1) Request the list of schema packages.
2) For each package (or the package of interest), request the list of 
classes.
3) For each class (or the class of interest), request the schema details.

To send protocol messages to the management broker, create the message 
with AMQP types via the Java encoder/decoder, then send them to the 
"qpid.management" exchange using "agent" as the routing key.

Replies will be transmitted according the the key in the replyTo field 
of the message.  Make sure the replyTo attribute is set on the message 
(setJMSReplyTo) to amq.direct/reply.

Here are the protocol references (see 
http://cwiki.apache.org/confluence/display/qpid/Management+Design+notes 
for protocol details):

1) Request packages by sending a "Package Query" message.  You will 
receive a "Package Indication" message on your reply queue for each 
package known to the broker.  The "qpid" package contains classes for 
the broker itself.

2) Request classes-per-package by sending a "Class Query" message.  You 
will receive a "Class Indication" message for each class in the 
package.  Note that a class is identified by the following tuple: 
(package-name, class-name, class-hash).  The hash is included because 
there may be more than one version of the schema for a particular class.

3) To request the schema details for a class, send a "Schema Request" 
message to the broker.  A "Schema Response" message will be sent in 
reply which contains the details of the class schema.

If you have further questions, don't hesitate to ask.

Regards,

-Ted

?

Re: Java Client - Question

Posted by me...@cs.man.ac.uk.
Hi Arnaud,

Thanks for your help. Your sample codes are really very useful to get an 
idea. At this moment, I can fetch the following information (decoded) from 
the broker by "management" queue bound on "qpid.management" exchange.


A
M
1
c
0
Package Name: qpid
Class Name: broker
-6506066772830834859
3980601858483200060
Current Sample: Wed Jul 06 22:54:31 CEST 38476878
Object Created: Sat Jul 24 16:10:25 CEST 38476877
Object Deleted: Thu Jan 01 01:00:00 CET 1970
16777218
--------
A
M
1
c
0
Package Name: qpid
Class Name: vhost
-8836930437367238452
6978501457256817678
Current Sample: Wed Jul 06 22:55:54 CEST 38476878
Object Created: Sat Jul 24 16:10:31 CEST 38476877
Object Deleted: Thu Jan 01 01:00:00 CET 1970
16777219
-------------

A
M
1
c
0
Package Name: qpid
Class Name: exchange
-5418781513850411724
-4895665811244006470
Current Sample: Wed Jul 06 22:57:02 CEST 38476878
Object Created: Sat Jul 24 16:11:00 CEST 38476877
Object Deleted: Thu Jan 01 01:00:00 CET 1970
33554433
------------
A
M
1
c
0
Package Name: qpid
Class Name: client
2274936829591414069
7716666671830073968
Current Sample: Wed Jul 06 23:10:41 CEST 38476878
Object Created: Thu Oct 14 02:14:24 CEST 38476877
Object Deleted: Thu Jan 01 01:00:00 CET 1970
19421773476921347
---------------
A
M
1
c
0
Package Name: qpid
Class Name: session
7627530833415044037
7647849998445955049
Current Sample: Wed Jul 06 23:12:52 CEST 38476878
Object Created: Fri Oct 15 13:01:40 CEST 38476877
Object Deleted: Thu Jan 01 01:00:00 CET 1970
19421773476921348
--------------
A
M
1
i
0
Package Name: qpid
Class Name: queue
1347274480851610151
7548280486574577882
Current Sample: Wed Jul 06 23:16:10 CEST 38476878
Object Created: Fri Oct 15 13:03:14 CEST 38476877
Object Deleted: Thu Jan 01 01:00:00 CET 1970
19421773476921349
------------
A
M
1
h
0
Sun Dec 13 05:38:09 CET 38476882
-------------------------------------

I am wondering if you can give me a sample example to send message to 
broker so that I can get the schema from broker. I have another queue 
called "reply" bound on "amq.direct" with the routing key "reply" but dont 
know how to get the management schema in it (cannt find the example for 
sending the message to broker to fetch the management information). I have 
read the qpid management notes and now know how to fetch the schema (in 
theory) but it will be nice to see the sample.

It will also be nice if you can explain a little about management interface 
you mentioned.

Also, if you can let me know where I can put my work? 

Just to update you, I started working on a ppt file and on documentation 
for this project.


Thanks in advance.


Best Regards,
Rahul




On Jun 19 2008, Arnaud Simon wrote:

> Hi Rahul,
> 
> The format that is used is the AMQP one as described here:
> http://cwiki.apache.org/qpid/management-design-notes.html
> 
> I would suggest you reuse the existing java Encoder/Decoder. You can do
> something like: 
> 
> ==== code sample ======
> public class ManagementDecoder extends AbstractDecoder
> {
>     private final ByteBuffer _buf;
> 
>     public ManagementDecoder(ByteBuffer buf)
>     {
>         _buf = buf;
>     }
> ....
> ==== end of code sample ======
> 
> Then when receiving a message you need to decode it based on its type.
> For example: 
> 
> ==== code sample ======
>  ManagementDecoder decoder = new ManagementDecoder(buf);
>  .....
>  pn = decoder.readStr8();
>  cn = decoder.readStr8();           
>  ...
>  int propCnt = decoder.readUint16();
>  for( int i = 0; i < propCnt; i++ )
>  {
>     Map<String,Object> map = decoder.readMap();
>     .....
> ==== end of code sample ======
> 
> I would also suggest we define a management interface (you can look at
> the python one --- qpid/python/qpid/management.py) that we can use to
> access to the managed packages/classes/objects...
> 
> 
> Arnaud 
> 
> On Thu, 2008-06-19 at 12:02 +0100, mehtar@cs.man.ac.uk wrote:
> > Hi,
> > 
> > I did again with Maven and this time it builds all the classes... So 
> > after creating and binding both the queues "reply" and "management". I 
> > am trying to fetch the management information (all what broker knows) 
> > from management queue and getting some encoded messages (i believe). 
> > for instance,
> > 
> > --------------
> > Message: AM1h
> > Message: AM1c
> > Message: AM1c
> > 
> > Message: AM1c
> > Message: AM1c
> > �ú�h�XW*��h�_�
> > amq.directdirect
> > Message: AM1i
> > �ú�h�XXCq�h�_�
> > Message: AM1i
> > �ú�h�XYIY�h�_�xR
> > Message: AM1i
> > �ú�h�XZH��h�_�xR
> > Message: AM1i
> > �ú�h�X[Q��h�_Ȭ�
> > amq.fanoutfanout
> > Message: AM1i
> > �ú�h�X\O�h�_Ȭ�
> > Message: AM1i
> > �ú�h�X]P��h�_���
> > Message: AM1i
> > �ú�h�X^N��h�_���
> > Message: AM1c
> > �ú�h�X_OP�h�_ǕV
> > Message: AM1i
> > �ú�h�X`Ke�h�_ǕV
> > Message: AM1c
> > �ú�h�XaK��h�_�v
> > Message: AM1i
> > �ú�h�XbF��h�_�v
> > ....
> > ...
> > 
> > java program which is retrieving this above mentioned encoded 
> > management information from management queue is :
> > 
> > package apache.qpid.client;
> > 
> > import java.nio.ByteBuffer;
> > import org.apache.qpidity.api.Message;
> > import org.apache.qpidity.nclient.Client;
> > import org.apache.qpidity.nclient.Connection;
> > import org.apache.qpidity.nclient.Session;
> > import org.apache.qpidity.nclient.util.MessageListener;
> > import org.apache.qpidity.nclient.util.MessagePartListenerAdapter;
> > import org.apache.qpidity.transport.MessageCreditUnit;
> > 
> > /**
> >  * This listens messages from management queue
> >  */
> > // TODO: decode these messages
> > 
> > public class Listener  implements MessageListener
> > {
> >    // implementation of onMessage
> >     public void onMessage(Message m)
> >     {
> >        String data = null;
> > 
> >         try
> >         {
> >              ByteBuffer buf = m.readData();
> >             byte[] b = new byte[buf.remaining()];
> >             buf.get(b);
> >             data = new String(b);
> >         }
> >         catch(Exception e)
> >         {
> >             System.out.print("Error reading message");
> >             e.printStackTrace();
> >         }
> >         System.out.println("Message: " + data);
> >     }
> >     public static void main(String[] args)
> >     {
> >         // Create connection
> >         Connection con = Client.createConnection();
> >         try
> >         {
> >             con.connect("localhost", 5672, "test", "guest", "guest");
> >         }
> >         catch(Exception e)
> >         {
> >             System.out.print("Error connecting to broker");
> >             e.printStackTrace();
> >         }
> >         // Create session
> >         Session session = con.createSession(0);
> >         // Create an instance of the listener
> >         Listener listener = new Listener();
> >         // create a subscription 
> >         session.messageSubscribe("management",
> >                                  "listener_management",
> >                                   
> > Session.TRANSFER_CONFIRM_MODE_NOT_REQUIRED,
> >                                   
> > Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE,
> >                                  new 
> > MessagePartListenerAdapter(listener), null);
> >    	  // issue credits
> >            session.messageFlow("listener_management", 
> > MessageCreditUnit.BYTE, Session.MESSAGE_FLOW_MAX_BYTES);
> >         session.messageFlow("listener_management", 
> > MessageCreditUnit.MESSAGE, 25);
> >         // confirm completion
> >         session.sync();
> >        session.messageCancel("listener_management");
> >         //cleanup
> >         session.sessionDetach(session.getName());
> >         try
> >         {
> >             con.close();
> >         }
> >         catch(Exception e)
> >         {
> >             System.out.print("Error closing broker connection");
> >             e.printStackTrace();
> >         }
> >     }
> > }
> > 
> > My question is how can I decode these messages?
> > 
> > Thank you.
> > 
> > Regards,
> > Rahul
> > 
> > 
> > On Jun 16 2008, Aidan Skinner wrote:
> > 
> > > On Mon, Jun 16, 2008 at 9:56 AM,  <me...@cs.man.ac.uk> wrote:
> > > 
> > > > Thanks for your help. I am still with my previous problem (i.e. 
> > > > missing some APIs)
> > > 
> > > > Client.java (under org.apache.qpidity.nclient) is missing some 
> > > > apis. eg.
> > > >
> > > > org.apache.qpidity.transport.ConnectionClose;
> > > 
> > > > due to these I can not compile/run the code.
> > > 
> > > It looks like you haven't run the generator, try doing an ant build
> > > and it should create those classes for you.
> > > 
> > > - Aidan
> > > 
> 
> 

Re: Java Client - Question

Posted by Arnaud Simon <as...@redhat.com>.
Hi Rahul,

The format that is used is the AMQP one as described here:
http://cwiki.apache.org/qpid/management-design-notes.html

I would suggest you reuse the existing java Encoder/Decoder. You can do
something like: 

==== code sample ======
public class ManagementDecoder extends AbstractDecoder
{
    private final ByteBuffer _buf;

    public ManagementDecoder(ByteBuffer buf)
    {
        _buf = buf;
    }
....
==== end of code sample ======

Then when receiving a message you need to decode it based on its type.
For example: 

==== code sample ======
 ManagementDecoder decoder = new ManagementDecoder(buf);
 .....
 pn = decoder.readStr8();
 cn = decoder.readStr8();           
 ...
 int propCnt = decoder.readUint16();
 for( int i = 0; i < propCnt; i++ )
 {
    Map<String,Object> map = decoder.readMap();
    .....
==== end of code sample ======

I would also suggest we define a management interface (you can look at
the python one --- qpid/python/qpid/management.py) that we can use to
access to the managed packages/classes/objects...


Arnaud 

On Thu, 2008-06-19 at 12:02 +0100, mehtar@cs.man.ac.uk wrote:
> Hi,
> 
> I did again with Maven and this time it builds all the classes... So after 
> creating and binding both the queues "reply" and "management". I am trying 
> to fetch the management information (all what broker knows) from management 
> queue and getting some encoded messages (i believe). for instance,
> 
> --------------
> Message: AM1h
> Message: AM1c
> Message: AM1c
> 
> Message: AM1c
> Message: AM1c
> �ú�h�XW*��h�_�
> amq.directdirect
> Message: AM1i
> �ú�h�XXCq�h�_�
> Message: AM1i
> �ú�h�XYIY�h�_�xR
> Message: AM1i
> �ú�h�XZH��h�_�xR
> Message: AM1i
> �ú�h�X[Q��h�_Ȭ�
> amq.fanoutfanout
> Message: AM1i
> �ú�h�X\O�h�_Ȭ�
> Message: AM1i
> �ú�h�X]P��h�_���
> Message: AM1i
> �ú�h�X^N��h�_���
> Message: AM1c
> �ú�h�X_OP�h�_ǕV
> Message: AM1i
> �ú�h�X`Ke�h�_ǕV
> Message: AM1c
> �ú�h�XaK��h�_�v
> Message: AM1i
> �ú�h�XbF��h�_�v
> ....
> ...
> 
> java program which is retrieving this above mentioned encoded management 
> information from management queue is :
> 
> package apache.qpid.client;
> 
> import java.nio.ByteBuffer;
> import org.apache.qpidity.api.Message;
> import org.apache.qpidity.nclient.Client;
> import org.apache.qpidity.nclient.Connection;
> import org.apache.qpidity.nclient.Session;
> import org.apache.qpidity.nclient.util.MessageListener;
> import org.apache.qpidity.nclient.util.MessagePartListenerAdapter;
> import org.apache.qpidity.transport.MessageCreditUnit;
> 
> /**
>  * This listens messages from management queue
>  */
> // TODO: decode these messages
> 
> public class Listener  implements MessageListener
> {
>    // implementation of onMessage
>     public void onMessage(Message m)
>     {
>        String data = null;
> 
>         try
>         {
>              ByteBuffer buf = m.readData();
>             byte[] b = new byte[buf.remaining()];
>             buf.get(b);
>             data = new String(b);
>         }
>         catch(Exception e)
>         {
>             System.out.print("Error reading message");
>             e.printStackTrace();
>         }
>         System.out.println("Message: " + data);
>     }
>     public static void main(String[] args)
>     {
>         // Create connection
>         Connection con = Client.createConnection();
>         try
>         {
>             con.connect("localhost", 5672, "test", "guest", "guest");
>         }
>         catch(Exception e)
>         {
>             System.out.print("Error connecting to broker");
>             e.printStackTrace();
>         }
>         // Create session
>         Session session = con.createSession(0);
>         // Create an instance of the listener
>         Listener listener = new Listener();
>         // create a subscription 
>         session.messageSubscribe("management",
>                                  "listener_management",
>                                  Session.TRANSFER_CONFIRM_MODE_NOT_REQUIRED,
>                                  Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE,
>                                  new MessagePartListenerAdapter(listener), 
> null);
>    	  // issue credits
>            session.messageFlow("listener_management", 
> MessageCreditUnit.BYTE, Session.MESSAGE_FLOW_MAX_BYTES);
>         session.messageFlow("listener_management", 
> MessageCreditUnit.MESSAGE, 25);
>         // confirm completion
>         session.sync();
>        session.messageCancel("listener_management");
>         //cleanup
>         session.sessionDetach(session.getName());
>         try
>         {
>             con.close();
>         }
>         catch(Exception e)
>         {
>             System.out.print("Error closing broker connection");
>             e.printStackTrace();
>         }
>     }
> }
> 
> My question is how can I decode these messages?
> 
> Thank you.
> 
> Regards,
> Rahul
> 
> 
> On Jun 16 2008, Aidan Skinner wrote:
> 
> > On Mon, Jun 16, 2008 at 9:56 AM,  <me...@cs.man.ac.uk> wrote:
> > 
> > > Thanks for your help. I am still with my previous problem (i.e. 
> > > missing some APIs)
> > 
> > > Client.java (under org.apache.qpidity.nclient) is missing some apis. eg.
> > >
> > > org.apache.qpidity.transport.ConnectionClose;
> > 
> > > due to these I can not compile/run the code.
> > 
> > It looks like you haven't run the generator, try doing an ant build
> > and it should create those classes for you.
> > 
> > - Aidan
> > 


Re: Java Client - Question

Posted by me...@cs.man.ac.uk.
Hi,

I did again with Maven and this time it builds all the classes... So after 
creating and binding both the queues "reply" and "management". I am trying 
to fetch the management information (all what broker knows) from management 
queue and getting some encoded messages (i believe). for instance,

--------------
Message: AM1h
Message: AM1c
Message: AM1c

Message: AM1c
Message: AM1c
�ú�h�XW*��h�_�
amq.directdirect
Message: AM1i
�ú�h�XXCq�h�_�
Message: AM1i
�ú�h�XYIY�h�_�xR
Message: AM1i
�ú�h�XZH��h�_�xR
Message: AM1i
�ú�h�X[Q��h�_Ȭ�
amq.fanoutfanout
Message: AM1i
�ú�h�X\O�h�_Ȭ�
Message: AM1i
�ú�h�X]P��h�_���
Message: AM1i
�ú�h�X^N��h�_���
Message: AM1c
�ú�h�X_OP�h�_ǕV
Message: AM1i
�ú�h�X`Ke�h�_ǕV
Message: AM1c
�ú�h�XaK��h�_�v
Message: AM1i
�ú�h�XbF��h�_�v
....
...

java program which is retrieving this above mentioned encoded management 
information from management queue is :

package apache.qpid.client;

import java.nio.ByteBuffer;
import org.apache.qpidity.api.Message;
import org.apache.qpidity.nclient.Client;
import org.apache.qpidity.nclient.Connection;
import org.apache.qpidity.nclient.Session;
import org.apache.qpidity.nclient.util.MessageListener;
import org.apache.qpidity.nclient.util.MessagePartListenerAdapter;
import org.apache.qpidity.transport.MessageCreditUnit;

/**
 * This listens messages from management queue
 */
// TODO: decode these messages

public class Listener  implements MessageListener
{
   // implementation of onMessage
    public void onMessage(Message m)
    {
       String data = null;

        try
        {
             ByteBuffer buf = m.readData();
            byte[] b = new byte[buf.remaining()];
            buf.get(b);
            data = new String(b);
        }
        catch(Exception e)
        {
            System.out.print("Error reading message");
            e.printStackTrace();
        }
        System.out.println("Message: " + data);
    }
    public static void main(String[] args)
    {
        // Create connection
        Connection con = Client.createConnection();
        try
        {
            con.connect("localhost", 5672, "test", "guest", "guest");
        }
        catch(Exception e)
        {
            System.out.print("Error connecting to broker");
            e.printStackTrace();
        }
        // Create session
        Session session = con.createSession(0);
        // Create an instance of the listener
        Listener listener = new Listener();
        // create a subscription 
        session.messageSubscribe("management",
                                 "listener_management",
                                 Session.TRANSFER_CONFIRM_MODE_NOT_REQUIRED,
                                 Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE,
                                 new MessagePartListenerAdapter(listener), 
null);
   	  // issue credits
           session.messageFlow("listener_management", 
MessageCreditUnit.BYTE, Session.MESSAGE_FLOW_MAX_BYTES);
        session.messageFlow("listener_management", 
MessageCreditUnit.MESSAGE, 25);
        // confirm completion
        session.sync();
       session.messageCancel("listener_management");
        //cleanup
        session.sessionDetach(session.getName());
        try
        {
            con.close();
        }
        catch(Exception e)
        {
            System.out.print("Error closing broker connection");
            e.printStackTrace();
        }
    }
}

My question is how can I decode these messages?

Thank you.

Regards,
Rahul


On Jun 16 2008, Aidan Skinner wrote:

> On Mon, Jun 16, 2008 at 9:56 AM,  <me...@cs.man.ac.uk> wrote:
> 
> > Thanks for your help. I am still with my previous problem (i.e. 
> > missing some APIs)
> 
> > Client.java (under org.apache.qpidity.nclient) is missing some apis. eg.
> >
> > org.apache.qpidity.transport.ConnectionClose;
> 
> > due to these I can not compile/run the code.
> 
> It looks like you haven't run the generator, try doing an ant build
> and it should create those classes for you.
> 
> - Aidan
> 

Re: Java Client - Question

Posted by Aidan Skinner <ai...@apache.org>.
On Mon, Jun 16, 2008 at 9:56 AM,  <me...@cs.man.ac.uk> wrote:

> Thanks for your help. I am still with my previous problem (i.e. missing some
> APIs)

> Client.java (under org.apache.qpidity.nclient) is missing some apis. eg.
>
> org.apache.qpidity.transport.ConnectionClose;

> due to these I can not compile/run the code.

It looks like you haven't run the generator, try doing an ant build
and it should create those classes for you.

- Aidan
-- 
aim/y!:aidans42 g:aidan.skinner@gmail.com
http://aidan.skinner.me.uk/
"We belong to nobody and nobody belongs to us. We don't even belong to
each other."

Re: Java Client - Question

Posted by me...@cs.man.ac.uk.
Hi Arnuad,

Thanks for your help. I am still with my previous problem (i.e. missing 
some APIs)

Connection con = Client.createConnection();

Client.java (under org.apache.qpidity.nclient) is missing some apis. eg.

org.apache.qpidity.transport.ConnectionClose;
org.apache.qpidity.transport.ConnectionCloseCode;
org.apache.qpidity.transport.ConnectionCloseOk;

In addition, the code snippet you wrote is missing some more APIs. e.g.

  org.apache.qpidity.transport.MessageAcceptMode;
  org.apache.qpidity.transport.MessageAcquireMode;
  org.apache.qpidity.transport.DeliveryProperties;


due to these I can not compile/run the code.

Regards,
Rahul



On Jun 16 2008, Arnaud Simon wrote:

> Hi Rahul,
> 
> Here is a code snippet that should do the job: 
>         // Create connection
>         Connection con = Client.createConnection();
>         try
>         {
>             con.connect("localhost", 5672, "test", "guest", "guest");
>         }
>         catch (Exception e)
>         {
> 	   // exception handling 
>         }
>         // Create a session
>         Session session = con.createSession(0);
>         // declare and bind the management queue
>         session.queueDeclare("management", null, null);
>         session.exchangeBind("management", "qpid.management", "mgmt.#",
> null);
>         // confirm completion
>         session.sync();
>         // declare and bind the reply queue
>         session.queueDeclare("reply", null, null);
>         session.exchangeBind("reply", "amq.direct", "reply", null);
>         // confirm completion
>         session.sync();
>         // Create an instance of the listener
>         ManagementTest listener = new ManagementTest();        
>         // create a subscription
>         session.messageSubscribe("reply",
>                 "listener_reply",
>                 Session.TRANSFER_CONFIRM_MODE_NOT_REQUIRED,
>                 Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE,
>                 new MessagePartListenerAdapter(listener), null);
>         // issue credits
>         session.messageFlow("listener_reply", MessageCreditUnit.BYTE,
> Session.MESSAGE_FLOW_MAX_BYTES);
>         session.messageFlow("listener_reply", MessageCreditUnit.MESSAGE,
> 11);
> 	// send a management message
>         DeliveryProperties deliveryProps = new DeliveryProperties();
>         deliveryProps.setRoutingKey("mgmt.#");
>         session.messageTransfer("qpid.management",
> MessageAcceptMode.EXPLICIT, MessageAcquireMode.PRE_ACQUIRED);
>         session.header(deliveryProps);
>         // some data here 
>         session.data(data);
>         session.endData();
>         // you may sync
> 
> Arnaud
> 
> 
> On Sun, 2008-06-15 at 13:52 +0100, mehtar@cs.man.ac.uk wrote:
> > Hi All,
> > 
> > Thank you Rajith and Ted for your help.
> > 
> > Arnaud as we discussed, I was looking at the 
> > org.apache.qpidity.nclient.impl.ClientSession to create a client 
> > session and I found there are several programs are misssing in 
> > "transport api" (this is the cause of several errors). Could you please 
> > point me where I can find these APIs? For instance following set of 
> > programs are missing:
> > 
> > import org.apache.qpidity.transport.MessageAcceptMode;
> > import org.apache.qpidity.transport.MessageAcquireMode;
> > import org.apache.qpidity.transport.Option;
> > import org.apache.qpidity.transport.DeliveryProperties;
> > import org.apache.qpidity.transport.MessageProperties;
> > import org.apache.qpidity.transport.ConnectionClose;
> > import org.apache.qpidity.transport.ConnectionCloseCode;
> > import org.apache.qpidity.transport.ConnectionCloseOk;
> > 
> > I am checking out from here:
> > http://svn.apache.org/repos/asf/incubator/qpid/trunk
> > 
> > 
> > Can anybody help me in this? 
> > 
> > Thank you.
> > 
> > Regards,
> > Rahul
> > 
> > On Jun 12 2008, Ted Ross wrote:
> > 
> > > Rajith Attapattu wrote:
> > > > On Thu, Jun 12, 2008 at 6:18 AM, <me...@cs.man.ac.uk> wrote:
> > > >
> > > >   
> > > >> Hi All,
> > > >>
> > > >> Thanks Carl for giving me a good starting point. So I am focusing 
> > > >> on the first step from the following step (regarding JMX/WSDM 
> > > >> Bridge project):
> > > >>
> > > >> 1. Creating a Java Client which can talk to Qpid C++ Broker. Thus 
> > > >> I can fetch the schema out from the broker
> > > >>
> > > >> 2. Once I will get the schema, I will translate it into JMS object
> > > >>
> > > >> 3. Then, we can expose those to WSDM
> > > >>
> > > >> One question on the first step, I am creating an individual Java 
> > > >> Client for this. I dont really understand how I will bind Queue of 
> > > >> my Java client to exchange so that I can receive messages and 
> > > >> updates periodically from the exchange. Carl, did you want me to 
> > > >> create an individual java client, if so how can I bind it with the 
> > > >> exchange?
> > > >>
> > > >> Secondly, will I use the Client APIs of Qpid broker to make the 
> > > >> connection and create/declare queues and bind them to exchange?
> > > >>
> > > >> For instance, I did find the APIs for the same under this directory
> > > >> structure:
> > > >>
> > > >>
> > > >>  
> > > >>  
> > > >>  
> > > >>  
> > > >> https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/
> > > >>     
> > > >
> > > >
> > > > I wrote them a while back and haven't looked at them recently. 
> > > > These examples compile so I assume it reflects the latests AMQP 
> > > > java API.
> > > >
> > > > However if you are not doing any management specific commands and 
> > > > only wants to bind to an exchange and receive messages, maybe you 
> > > > can get away with JMS.
> > > >
> > > > Regards,
> > > >
> > > > Rajith
> > > >
> > > >   
> > > Rahul,
> > > 
> > > For your purposes, you need to create two private queues.  The first, 
> > > the "management" queue, must be bound to the topic exchange called 
> > > "qpid.management" with a binding key of "mgmt.#".  The second, the 
> > > "reply" queue, must be bound to amq.direct with a binding key that is 
> > > identical to the name of the queue.
> > > 
> > > You will then be sending messages to the "qpid.management" exchange 
> > > and receiving messages from both private queues.
> > > 
> > > You can use the JMS API for message transfer. You will need the AMQP 
> > > codec from the non-JMS Java API to encode and decode the bodies of 
> > > the management messages.
> > > 
> > > -Ted
> > > 
> > > 
> 
> 

Re: Java Client - Question

Posted by Arnaud Simon <as...@redhat.com>.
Hi Rahul,

Here is a code snippet that should do the job: 
        // Create connection
        Connection con = Client.createConnection();
        try
        {
            con.connect("localhost", 5672, "test", "guest", "guest");
        }
        catch (Exception e)
        {
	   // exception handling 
        }
        // Create a session
        Session session = con.createSession(0);
        // declare and bind the management queue
        session.queueDeclare("management", null, null);
        session.exchangeBind("management", "qpid.management", "mgmt.#",
null);
        // confirm completion
        session.sync();
        // declare and bind the reply queue
        session.queueDeclare("reply", null, null);
        session.exchangeBind("reply", "amq.direct", "reply", null);
        // confirm completion
        session.sync();
        // Create an instance of the listener
        ManagementTest listener = new ManagementTest();        
        // create a subscription
        session.messageSubscribe("reply",
                "listener_reply",
                Session.TRANSFER_CONFIRM_MODE_NOT_REQUIRED,
                Session.TRANSFER_ACQUIRE_MODE_PRE_ACQUIRE,
                new MessagePartListenerAdapter(listener), null);
        // issue credits
        session.messageFlow("listener_reply", MessageCreditUnit.BYTE,
Session.MESSAGE_FLOW_MAX_BYTES);
        session.messageFlow("listener_reply", MessageCreditUnit.MESSAGE,
11);
	// send a management message
        DeliveryProperties deliveryProps = new DeliveryProperties();
        deliveryProps.setRoutingKey("mgmt.#");
        session.messageTransfer("qpid.management",
MessageAcceptMode.EXPLICIT, MessageAcquireMode.PRE_ACQUIRED);
        session.header(deliveryProps);
        // some data here 
        session.data(data);
        session.endData();
        // you may sync

Arnaud


On Sun, 2008-06-15 at 13:52 +0100, mehtar@cs.man.ac.uk wrote:
> Hi All,
> 
> Thank you Rajith and Ted for your help.
> 
> Arnaud as we discussed, I was looking at the 
> org.apache.qpidity.nclient.impl.ClientSession to create a client session 
> and I found there are several programs are misssing in "transport api" 
> (this is the cause of several errors). Could you please point me where I 
> can find these APIs? For instance following set of programs are missing:
> 
> import org.apache.qpidity.transport.MessageAcceptMode;
> import org.apache.qpidity.transport.MessageAcquireMode;
> import org.apache.qpidity.transport.Option;
> import org.apache.qpidity.transport.DeliveryProperties;
> import org.apache.qpidity.transport.MessageProperties;
> import org.apache.qpidity.transport.ConnectionClose;
> import org.apache.qpidity.transport.ConnectionCloseCode;
> import org.apache.qpidity.transport.ConnectionCloseOk;
> 
> I am checking out from here:
> http://svn.apache.org/repos/asf/incubator/qpid/trunk
> 
> 
> Can anybody help me in this? 
> 
> Thank you.
> 
> Regards,
> Rahul
> 
> On Jun 12 2008, Ted Ross wrote:
> 
> > Rajith Attapattu wrote:
> > > On Thu, Jun 12, 2008 at 6:18 AM, <me...@cs.man.ac.uk> wrote:
> > >
> > >   
> > >> Hi All,
> > >>
> > >> Thanks Carl for giving me a good starting point. So I am focusing on 
> > >> the first step from the following step (regarding JMX/WSDM Bridge 
> > >> project):
> > >>
> > >> 1. Creating a Java Client which can talk to Qpid C++ Broker. Thus I can
> > >> fetch the schema out from the broker
> > >>
> > >> 2. Once I will get the schema, I will translate it into JMS object
> > >>
> > >> 3. Then, we can expose those to WSDM
> > >>
> > >> One question on the first step, I am creating an individual Java 
> > >> Client for this. I dont really understand how I will bind Queue of my 
> > >> Java client to exchange so that I can receive messages and updates 
> > >> periodically from the exchange. Carl, did you want me to create an 
> > >> individual java client, if so how can I bind it with the exchange?
> > >>
> > >> Secondly, will I use the Client APIs of Qpid broker to make the 
> > >> connection and create/declare queues and bind them to exchange?
> > >>
> > >> For instance, I did find the APIs for the same under this directory
> > >> structure:
> > >>
> > >>
> > >>  
> > >>  
> > >> https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/
> > >>     
> > >
> > >
> > > I wrote them a while back and haven't looked at them recently. These 
> > > examples compile so I assume it reflects the latests AMQP java API.
> > >
> > > However if you are not doing any management specific commands and only 
> > > wants to bind to an exchange and receive messages, maybe you can get 
> > > away with JMS.
> > >
> > > Regards,
> > >
> > > Rajith
> > >
> > >   
> > Rahul,
> > 
> > For your purposes, you need to create two private queues.  The first, 
> > the "management" queue, must be bound to the topic exchange called 
> > "qpid.management" with a binding key of "mgmt.#".  The second, the 
> > "reply" queue, must be bound to amq.direct with a binding key that is 
> > identical to the name of the queue.
> > 
> > You will then be sending messages to the "qpid.management" exchange and 
> > receiving messages from both private queues.
> > 
> > You can use the JMS API for message transfer.  You will need the AMQP 
> > codec from the non-JMS Java API to encode and decode the bodies of the 
> > management messages.
> > 
> > -Ted
> > 
> > 


Re: Java Client - Question

Posted by me...@cs.man.ac.uk.
Hi All,

Thank you Rajith and Ted for your help.

Arnaud as we discussed, I was looking at the 
org.apache.qpidity.nclient.impl.ClientSession to create a client session 
and I found there are several programs are misssing in "transport api" 
(this is the cause of several errors). Could you please point me where I 
can find these APIs? For instance following set of programs are missing:

import org.apache.qpidity.transport.MessageAcceptMode;
import org.apache.qpidity.transport.MessageAcquireMode;
import org.apache.qpidity.transport.Option;
import org.apache.qpidity.transport.DeliveryProperties;
import org.apache.qpidity.transport.MessageProperties;
import org.apache.qpidity.transport.ConnectionClose;
import org.apache.qpidity.transport.ConnectionCloseCode;
import org.apache.qpidity.transport.ConnectionCloseOk;

I am checking out from here:
http://svn.apache.org/repos/asf/incubator/qpid/trunk


Can anybody help me in this? 

Thank you.

Regards,
Rahul

On Jun 12 2008, Ted Ross wrote:

> Rajith Attapattu wrote:
> > On Thu, Jun 12, 2008 at 6:18 AM, <me...@cs.man.ac.uk> wrote:
> >
> >   
> >> Hi All,
> >>
> >> Thanks Carl for giving me a good starting point. So I am focusing on 
> >> the first step from the following step (regarding JMX/WSDM Bridge 
> >> project):
> >>
> >> 1. Creating a Java Client which can talk to Qpid C++ Broker. Thus I can
> >> fetch the schema out from the broker
> >>
> >> 2. Once I will get the schema, I will translate it into JMS object
> >>
> >> 3. Then, we can expose those to WSDM
> >>
> >> One question on the first step, I am creating an individual Java 
> >> Client for this. I dont really understand how I will bind Queue of my 
> >> Java client to exchange so that I can receive messages and updates 
> >> periodically from the exchange. Carl, did you want me to create an 
> >> individual java client, if so how can I bind it with the exchange?
> >>
> >> Secondly, will I use the Client APIs of Qpid broker to make the 
> >> connection and create/declare queues and bind them to exchange?
> >>
> >> For instance, I did find the APIs for the same under this directory
> >> structure:
> >>
> >>
> >>  
> >>  
> >> https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/
> >>     
> >
> >
> > I wrote them a while back and haven't looked at them recently. These 
> > examples compile so I assume it reflects the latests AMQP java API.
> >
> > However if you are not doing any management specific commands and only 
> > wants to bind to an exchange and receive messages, maybe you can get 
> > away with JMS.
> >
> > Regards,
> >
> > Rajith
> >
> >   
> Rahul,
> 
> For your purposes, you need to create two private queues.  The first, 
> the "management" queue, must be bound to the topic exchange called 
> "qpid.management" with a binding key of "mgmt.#".  The second, the 
> "reply" queue, must be bound to amq.direct with a binding key that is 
> identical to the name of the queue.
> 
> You will then be sending messages to the "qpid.management" exchange and 
> receiving messages from both private queues.
> 
> You can use the JMS API for message transfer.  You will need the AMQP 
> codec from the non-JMS Java API to encode and decode the bodies of the 
> management messages.
> 
> -Ted
> 
> 

Re: Java Client - Question

Posted by Ted Ross <tr...@redhat.com>.
Rajith Attapattu wrote:
> On Thu, Jun 12, 2008 at 6:18 AM, <me...@cs.man.ac.uk> wrote:
>
>   
>> Hi All,
>>
>> Thanks Carl for giving me a good starting point. So I am focusing on the
>> first step from the following step (regarding JMX/WSDM Bridge project):
>>
>> 1. Creating a Java Client which can talk to Qpid C++ Broker. Thus I can
>> fetch the schema out from the broker
>>
>> 2. Once I will get the schema, I will translate it into JMS object
>>
>> 3. Then, we can expose those to WSDM
>>
>> One question on the first step, I am creating an individual Java Client for
>> this. I dont really understand how I will bind Queue of my Java client to
>> exchange so that I can receive messages and updates periodically from the
>> exchange. Carl, did you want me to create an individual java client, if so
>> how can I bind it with the exchange?
>>
>> Secondly, will I use the Client APIs of Qpid broker to make the connection
>> and create/declare queues and bind them to exchange?
>>
>> For instance, I did find the APIs for the same under this directory
>> structure:
>>
>>
>> https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/
>>     
>
>
> I wrote them a while back and haven't looked at them recently.
> These examples compile so I assume it reflects the latests AMQP java API.
>
> However if you are not doing any management specific commands and only wants
> to bind to an exchange and receive messages, maybe you can get away with
> JMS.
>
> Regards,
>
> Rajith
>
>   
Rahul,

For your purposes, you need to create two private queues.  The first, 
the "management" queue, must be bound to the topic exchange called 
"qpid.management" with a binding key of "mgmt.#".  The second, the 
"reply" queue, must be bound to amq.direct with a binding key that is 
identical to the name of the queue.

You will then be sending messages to the "qpid.management" exchange and 
receiving messages from both private queues.

You can use the JMS API for message transfer.  You will need the AMQP 
codec from the non-JMS Java API to encode and decode the bodies of the 
management messages.

-Ted


Re: Java Client - Question

Posted by Rajith Attapattu <ra...@gmail.com>.
On Thu, Jun 12, 2008 at 6:18 AM, <me...@cs.man.ac.uk> wrote:

> Hi All,
>
> Thanks Carl for giving me a good starting point. So I am focusing on the
> first step from the following step (regarding JMX/WSDM Bridge project):
>
> 1. Creating a Java Client which can talk to Qpid C++ Broker. Thus I can
> fetch the schema out from the broker
>
> 2. Once I will get the schema, I will translate it into JMS object
>
> 3. Then, we can expose those to WSDM
>
> One question on the first step, I am creating an individual Java Client for
> this. I dont really understand how I will bind Queue of my Java client to
> exchange so that I can receive messages and updates periodically from the
> exchange. Carl, did you want me to create an individual java client, if so
> how can I bind it with the exchange?
>
> Secondly, will I use the Client APIs of Qpid broker to make the connection
> and create/declare queues and bind them to exchange?
>
> For instance, I did find the APIs for the same under this directory
> structure:
>
>
> https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/


I wrote them a while back and haven't looked at them recently.
These examples compile so I assume it reflects the latests AMQP java API.

However if you are not doing any management specific commands and only wants
to bind to an exchange and receive messages, maybe you can get away with
JMS.

Regards,

Rajith


>
> <https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/java/client/example/src/main/java/org/apache/qpid/example/amqpexample/>
>
> Can I use this code to fetch the schema from the Qpid C++ broker?
>
> Thank you.
>
> Best Regards,
> Rahul
>
>


-- 
Regards,

Rajith Attapattu
Red Hat
http://rajith.2rlabs.com/