Using AMQP from Delphi with ZeroMQ

The Advanced Message Queuing Protocol (AMQP) is an open standard [application layer] protocol for [[Message Oriented Middleware]](http://en.wikipedia.org/wiki/Message_oriented_middleware “What does it mean “Mom” ?”) (MoM).

The defining features of AMQP are message orientation, queuing, routing (including point-to-point and publish-and-subscribe), reliability and security^.^

The good news about AMQP is that AMQP mandates the behaviour of the messaging provider and client to the extent that implementations from different vendors are truly interoperable, in the same way as SMTP, HTTP, FTP, etc. have created interoperable systems.

In a so “Open” market, live an interesting project called ZeroMQ.

In a my recent Delphi project, I must choice a thin and fast messaging system, ZeroMQ has been the choice.

However, ZeroMQ has not the Delphi client for talking with the broker, so I decided to write my own.

ZeroMQ is very fast but doesn’t support some enteprise features like users management and message persistence, but is very simple to use and to intergate in a legacy system.

For example, with my wrapper, a simple “sender” is like following:

zmq := TZeroMQ.Create;
try
zmq.Open('localhost');
ex := zmq.CreateLocalExchange('MyExchange', zmqStyleDataDistribution);
zmq.Bind('MyExchange', 'GlobalQueue');
zmq.Send(ex, 'Hello World From Delphi');
finally
zmq.Free;
end;

And a simple receiver is simple as follow:

zmq := TZeroMQ.Create;
try
zmq.Open('localhost');
ex := zmq.CreateLocalQueue('LocalQueue');
zmq.Bind('GlobalExchange', 'LocalQueue');
zmq.Receive(msg, msgtype, msgsize, zmqBlocking);
WriteLn(msg);  //we are in a console application
finally
zmq.Free;
end;

In the distribution there are a complete set of examples including a simple “Chat” application.

ZeroMQ is primarily intended to power stock trading business, this is the reason becouse is very fast.

To use ZeroMQ you need the ZeroMQ server downloadable from http://www.zeromq.org/ where you can find additional info about Exchange and Queue configuration and binding.

Wrapper (beta) can be downloaded from the ZeroMQ section.

Comments and fix for the wrapper are very apreciated.

Have fun and happy messaging :-)

Comments

comments powered by Disqus