Using AMQP from Delphi with ZeroMQ
Delphi for Win32, Design Patterns, Programming, Uncategorized Add commentsThe 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 ![]()

August 13th, 2009 at 4:22 am
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 !
September 1st, 2009 at 1:27 pm
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
September 11th, 2009 at 1:58 pm
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.
September 14th, 2009 at 11:57 pm
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.
September 29th, 2009 at 4:29 pm
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.
September 29th, 2009 at 4:30 pm
After fixing the open method it still does not work and raises a access violation when the open method is called.
March 5th, 2010 at 8:12 pm
[...] Mail (will not be published) (required) Website. XHTML: You can use these tags: Search for: …while true do; Blog Archive Using AMQP from Delphi with …Delphi for Win32, Design Patterns, Programming, Uncategorized Add comments. The Advanced Message [...]
March 26th, 2010 at 9:45 am
i run succesfully in one computer but not in two computer and more…can you expalin it mr.daniels, please…sorry i’m beginner…