qpid-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Arnaud Simon <asi...@redhat.com>
Subject Re: Java Client - Question
Date Mon, 16 Jun 2008 07:06:08 GMT
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, <mehtar@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
> > 
> > 


Mime
View raw message