Mobile Message Push everyone has experienced, a lot of ads on smartphones and other messages will occasionally pop from the message bar to harass you.
In the PC program we also sometimes use message push, such as notification. Often we use a method that is more likely to be handled with a socket, and sometimes a less efficient method is to poll the database. If the terminal is many, the message is many, the database polling way is certainly not acceptable.
Now the more popular message server has a lot, like Apache ACTIVEMQ, upgrade products is APOLLO,RABBITMQ, there are known as the fastest zeromq, and so many. Most of these messaging servers support a variety of platforms, such as Java,php,python, and most of them support Delphi.
The more famous clients under Delphi are the clients of Habari, the official homepage:
https://www.habarisoft.com/
There are dedicated clients for ACTIVEMQ and so on.
And this open source work:
http://www.danieleteti.it/stomp-client/
The code is hosted in:
http://code.google.com/p/delphistompclient/
ACTIVEMQ, such as the persistent support for the message is relatively simple, configuration can be, this Baidu a little bit, the key is through the connection message server, you can enable the client to simply process the message, so efficient, real-time.
Here is an excerpt from a simple Delphi application using the Stomp protocol client, which is the open source work mentioned above:
Stomp Client
Stomp protocol provides an interoperable wire format so, any of the available Stomp clients can communicate with any S Tomp Message Broker to provide easy and widespread messaging interop among languages, platforms and brokers.
The Delphi Stomp Client is a open source implementation of the Stomp protocol for Delphi (should work with Delphi 20 too) and freepascal 2.4.x.
This Delphi Stomp client is attempt to copy the JMS client architecture to Delphi. So aren ' t included some JMS specific features like message transformations.
This stomp client was actually tested on ActiveMQ 5.2 and ActiveMQ 5.3, but should work with every STOMP compliant server.
In Delphi you can use the built-in INDY component suite or the OpenSource Synapse acording with a compiler directive. In Stompclient.pas there is following definitions:
Unitstompclient;//For freepascal users://automatically selected synapse TCP library{$IFDEF FPC}{$MODE DELPHI}{$DEFINE Usesynapse} //freepascal Always use SYNAPSE{$ENDIF}//For Delphi users://decomment following line to use synapse also in Delphi{. $DEFINE Usesynapse} //DELPHI USERS CAN use INDY OR SYNAPSE
Some Examples of basic functionalities (not real world example, use included examples instead):
Programsimplemessaging;{$APPTYPE CONSOLE} usessysutils, Stompclient, stomptypes;procedureExample_pub_subscriber;varstomppub, stompsubscriber:istompclient; Stompframe:istompframe;beginWriteln ('==> Example_pub_subscriber'); Stompsubscriber:= Stomputils.newstomp ('127.0.0.1');//Default PortStompsubscriber.subscribe ('/topic/dummy'); Stomppub:= Stomputils.newstomp ('127.0.0.1');//Default PortStomppub.send ('/topic/dummy','Some test Message'); RepeatStompframe:=stompsubscriber.receive; untilAssigned (stompframe); Writeln (Stompframe.getbody); //Print "Some test Message"Writeln;End; procedureExample_onepub_twosubscriber;varstomppub, StompSub1, stompsub2:istompclient; Stompframe:istompframe;beginWriteln ('==> Example_onepub_twosubscriber'); STOMPSUB1:= Stomputils.newstomp ('127.0.0.1');//Default PortSTOMPSUB2:= Stomputils.newstomp ('127.0.0.1');//Default PortStompsub1.subscribe ('/topic/dummy'); Stompsub2.subscribe ('/topic/dummy'); Stomppub:= Stomputils.newstomp ('127.0.0.1');//Default PortStomppub.send ('/topic/dummy','First test message on a topic'); Stomppub.send ('/topic/dummy','Second test message on a topic'); Stompframe:= Stompsub1.receive ( -); ifAssigned (Stompframe) ThenWriteln (stompframe.getbody); Stompframe:= Stompsub1.receive ( -); ifAssigned (Stompframe) ThenWriteln (stompframe.getbody); Stompframe:= Stompsub2.receive ( -); ifAssigned (Stompframe) ThenWriteln (stompframe.getbody); Stompframe:= Stompsub2.receive ( -); ifAssigned (Stompframe) ThenWriteln (stompframe.getbody); Writeln;End; procedureExample_pointtopoint;varstomppub, StompSub1, stompsub2:istompclient; Stompframe:istompframe;beginWriteln ('==> Example_pointtopoint'); STOMPSUB1:= Stomputils.newstomp ('127.0.0.1');//Default PortSTOMPSUB2:= Stomputils.newstomp ('127.0.0.1');//Default PortStompsub1.subscribe ('/queue/dummy'); Stompsub2.subscribe ('/queue/dummy'); Stomppub:= Stomputils.newstomp ('127.0.0.1');//Default PortStomppub.send ('/queue/dummy','First test message on a queue'); Stomppub.send ('/queue/dummy','Second test message on a queue'); Stompframe:= Stompsub1.receive ( -); ifAssigned (Stompframe) ThenWriteln (stompframe.output); Stompframe:= Stompsub1.receive ( -); ifAssigned (Stompframe) ThenWriteln (stompframe.output); Stompframe:= Stompsub2.receive ( -); ifAssigned (Stompframe) ThenWriteln (stompframe.output); Stompframe:= Stompsub2.receive ( -); ifAssigned (Stompframe) ThenWriteln (stompframe.output); Writeln;End; begin TryExample_pub_subscriber; Example_onepub_twosubscriber; Example_pointtopoint; exceptOn e:exception DoWriteln (E.classname,': 'E.message); End;End.
Delphistompclient has also a simple listener for asynchronous use. To use the listener should implement follwing interface:
Interface ['{c4c0d932-8994-43fb-9d32-a03fe86aefe4}'] Procedure OnMessage (stompframe:istompframe); End;
Also a normal form can be used:
class (Tform, Istompclientlistener) ... Public procedure OnMessage (stompframe:istompframe); // called by the Stomp receiver End;
And then your can manager your message in a simple form ' s method.
There is many features in this STOMP client. I ' ve tried to respect all the STOMP specs also in the Transactions side (Http://stomp.codehaus.org/Protocol).
You can find all the source code and the examples at following Google code Project:
http://code.google.com/p/delphistompclient/
The freepascal version is actually mantained by Daniel gaspary, thank Daniel.
Delphi Message Push