qpid-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shahbaz Chaudhary" <schaudh...@marcopolonetwork.com>
Subject C# API boilerplate
Date Tue, 02 Dec 2008 15:33:28 GMT
I am going through examples of the new 0-10 client API and have noticed
that the API seems unnecessarily complex.

Some examples:
The IMessageListener interface has a callback method which receives an
IMessage object.  I expected IMessage to work in the following manner:

string x = message.getString("fieldname");
double y = message.getDouble("fieldname");
Dictionary<string,string> fieldsAndTheirTypes =
message.getFieldsNTypes();

Instead the example contains binary readers, bytes, encodings, etc.:

BinaryReader reader = new BinaryReader(m.Body, Encoding.UTF8);
byte[] body = new byte[m.Body.Length - m.Body.Position];
reader.Read(body, 0, body.Length);
ASCIIEncoding enc = new ASCIIEncoding();

-----
The code to create connection and session also looks unnecessarily
noisy.  I have to provide the queue name to the ClientSession object
three times (twice in one method call):

ssn.queueDeclare("queue1", null, null);
ssn.exchangeBind("queue1", "amq.direct", "queue1", null);
sn.messageSubscribe("queue1", "myDest", MessageAcceptMode.EXPLICIT,
MessageAcquireMode.PRE_ACQUIRED, null,0, null);

----
The call-back method in IMessageListener is called messageTransfer(),
isn't it better to simply call it onMessage()?

In fact, it looks like using JMS as the API template will greatly
improve the publicly exposed part of the API (and I used to think the
JMS API was messy :) ).

I think it will be a good idea to expose incoming message as
Events...since that's what incoming messages are and the semantics of
qpid subscribed messages and the Events feature match perfectly.

-----
I realize some of the complexity exists because AMQP provides many
features...perhaps qpid can provide a stupidly simple, default, way of
getting at the data within a few lines?

Client client = new Client("url");

client.subscribe("topicName1").OnMessage += {x =>
Console.WriteLine(x.getLong("bankaccount"))};;
client.subscribe("topicName2").OnMessage += {x =>
Console.WriteLine(x.getLong("bankaccount"))};;

//what ever the right C# syntax is for event handling and lambda
experssions
Sender sender client.getSender("topicName3");
client.connect();

IMessage msg = client.createMessageOfWhateverType();
msg.setLong("bankaccount",234134154123412342);
msg.setString("type","savings");

sender.send(msg);


Mime
View raw message