Using AMQP from Delphi with ZeroMQ

The Advanced Message Queuing Protocol (AMQP) is an open standard application layer protocol for Message Oriented Middleware (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 🙂

8 thoughts on “Using AMQP from Delphi with ZeroMQ

  1. Hi.

    Which is the license for the code ?

    Would be interesting to have a project at sourceforge/GoogleCode to help improve the code.

    Great work, thanks !

  2. Hi,

    promising approach. Sad to see there’s no MPL license available for it. LGPL will create problems when linking the library statically into commercial Delphi Applications. Only solution so far: put the message queue code into a DLL and do a late binding of it while publishing the DLL code again under LGPL.

    Cheers,
    Arvid

  3. This example actually works?
    You are using GlobalQueue and LocalQueue, shouldn’t it be the same?
    In my test program this code hangs on ‘zmq.Receive’.
    Please let me know if you want port of this library for Freee Pascal Compiler.

  4. FreePascalTester,

    Are You trying to port to Freepascal ? I have converted the code to test with Lazarus on Ubuntu.

    When I try to run the Chatroom Example on my Ubuntu (Hardy 64 bits) the entire X Freezes. :D.

  5. Your wrapper included with the ZeroMQ distro is broken.
    Take a look at the open method, it uses Fhost, but it is never set anywhere. you should override the create method and set fhost there, or just get rid of Fhost and change the open method to use the host var that is passed.

  6. After fixing the open method it still does not work and raises a access violation when the open method is called.

  7. Pingback: msgtype
  8. i run succesfully in one computer but not in two computer and more…can you expalin it mr.daniels, please…sorry i’m beginner…

Comments are closed.