Gordon Sim wrote:
[EMAIL PROTECTED] wrote:
Author: rajith
Date: Fri Jun 1 13:40:34 2007
New Revision: 543602
URL: http://svn.apache.org/viewvc?view=rev&rev=543602
Log:
more enchancements for the Qpid java client. Also I have checked in a
sample client(QpidTestClient) on how to use the qpid java client.
Rajith,
Great to see this coming together! The sample was perfect for getting a
quick overview of how the API is to work. It will also be very useful in
focusing the discussion on more uniformity across the qpid clients.
I've attached some comments on that sample. I have to confess though
that I didn't investigate the APIs directly so some of these comments
may be based on ignorance of what is already there. A lot of them are
also probably based on prejudices acquired in connection with the c++ or
python clients!
--Gordon.
Many apologies; comments are now attached as originally promised!
QpidConnection con = new QpidConnectionImpl();
con.connect("amqp://guest:[EMAIL
PROTECTED]/test?brokerlist='tcp://localhost:5672?'");
Rather than having to remember the format of this URL scheme, I'd
prefer (overloaded) method arguments for the constitutent parts. E.g.
con.connect("localhost", 5672, "test", "guest", "guest"). Or perhaps a
properties object with some defined keys (i.e. similar to how JDBC
connections are often configured).
QpidSession session =
con.createSession(QpidConstants.SESSION_EXPIRY_TIED_TO_CHANNEL);
session.open();
Though a minor point, there should be a createSession() with no
argument that assumes the expiry is tied to the channel. That keeps
the simple case simple.
QpidExchangeHelper exchangeHelper = session.getExchangeHelper();
exchangeHelper.declareExchange(false, false,
QpidConstants.DIRECT_EXCHANGE_NAME, false, false, false,
QpidConstants.DIRECT_EXCHANGE_CLASS);
QpidQueueHelper queueHelper = session.getQueueHelper();
queueHelper.declareQueue(false, false, false, false, false, "myQueue");
queueHelper.bindQueue(QpidConstants.DIRECT_EXCHANGE_NAME, false, "myQueue",
"RH");
Perhaps a bit controversial, but how about e.g.
session.exchange.declare(false, false ...);
session.queue.declare(false, false, ...);
session.queue.bind(QpidConstants.DIRECT_EXCHANGE_NAME, ...);
or (probably even more controversially!):
session.exchangeDeclare(false, false ...);
session.queueDeclare(false, false, ...);
session.queueBind(QpidConstants.DIRECT_EXCHANGE_NAME, ...);
Ideally the method fields would be in the order defined in the spec or
the order of relevance; in queue.declare for example, having the name
first would be more 'appealing' to me. We should also expose the
'arguments' field table.
Very minor point: should it not be DIRECT_EXCHANGE_TYPE, rather than
_CLASS?
MessageHeaders msgHeaders = new MessageHeaders();
msgHeaders.setRoutingKey(new AMQShortString("RH"));
msgHeaders.setExchange(new
AMQShortString(QpidConstants.DIRECT_EXCHANGE_NAME));
AMQPApplicationMessage msg = new
AMQPApplicationMessage(msgHeaders,"test".getBytes());
The application should not have to care about AMQShortString; it
should be able to pass in a normal java string and have the client
wrap it if required.
My view on the exchange is that the application wouldn't directly set
a message header, but would specify the exchange to which a publish
was directed. I think I would do the same for routing key also.
QpidMessageProducer messageProducer = session.createProducer();
messageProducer.open();
messageProducer.send(false, true, msg);
I would directly expose e.g. the message.transfer method, rather than
wrapping it behind a more generic producer interface.
QpidMessageConsumer messageConsumer = session.createConsumer("myQueue",
false, false);
messageConsumer.open();
AMQPApplicationMessage msg2 = messageConsumer.receive();
Again, I think I would lean towards more direct expression of the AMQP
methods. So a message.consume method, and then the ability to set a
listener or poll from a queue for that consumer. e.g.
QpidMessageConsumer consumer = session.message.consume("myQueue", false, false);
//either
consumer.setListener(...);
//or
AMQPApplicationMessage msg = consumer.receive()