Following ideas from Fabriq project, I wrote last week an example of a server application that can receive and process OneWay Windows Communication Foundation (WCF) messages. The server can host applications, and each application is composed by nodes, that have actions. The example code can be download from AjMessagesWCF-0.1.1.zip
The message
The message to exchange is a WCF message (the original Fabriq was written before the WCF era). The main information that AjMessages uses is the Headers.Action property. This string has the name of the application, node, and action to invoke.
The action
It’s a string with format:
<application>/<node>/<action>
An application is a set of nodes. A server can host some or all nodes of an application. But the same node can run in different servers. In this way, the internal process of the server can forward a message to other server: the action is not a physical address, but a logical one. Each server knows the address and nodes in other servers, and then, it can decide to forward a message to another server.
The application
A configuration XML file define the applications to run. An application has:
- Nodes: a collection of actions to process.
- Handlers: objects to process a message. A handler can be a composite of other handlers.
- Actions: named entry points to a handler
An example application definition:
<Application Name="App1"> <Node Name="Node1"> <Handler Name="PrintMessageHandler" Type="AjMessages.PrintMessageHandler, AjMessages"/> <Handler Name="PostHandler" Type="AjMessages.PostHandler, AjMessages"/> <Handler Name="DecrementHandler" Type="AjMessages.Console01.DecrementHandler, AjMessages.Console01"/> <Handler Name="Pipeline1"> <Handler Name="DecrementHandler"/> <Handler Name="PostHandler"> <Property Name="Action" Value="App2/Node1/Process"/> </Handler> </Handler> <Action Name="Process" Handler="Pipeline1"/> </Node> <Node Name="Node2"/> </Application>
The handler
A handler must implements an interface:
public interface IHandler { void Process(Context ctx); }
The context has a property Message, that points to the WCF message in process, and some other methods to use: a Server property that reference to the current server object, and a Post method, to send a new message. The idea is to put in the context all the needed external functionality to the handler, so this is decoupled of the server and message in process.
This is a departure of the original implementation in Fabriq, where the handler receives a message, not a context.
The host
A host is a logical unit that runs inside a server. A server is informed, via configuration, the hosts that are available in other servers, and which ones are local. An example:
<Host Name="Host1" Address=http://localhost:50000/AjMessages Activate="true"> <Application Name="AjMessages"> <Node Name="Administration"/> </Application> <Application Name="App1"> <Node Name="Node1"/> <Node Name="Node2"/> </Application> </Host>
Dynamic configuration
One of the key features implemented is a handler that reconfigure in runtime the running server. It receives a new XML configuration, and merges it with the current information. Then, using these handler, an application can send a message to a AjMessages server, and load, stop, update hosts, applications and nodes.
The solution
The class library AjMessages project contains the implementation of the example. The other projects are manual test to run that shows how to use the example.
Inside Configuration folder there are classes defined to load configuration data from an XML structure.
Handlers folder contains some predefined handlers to use, an important one is the ConfigurationHandler that permits to reconfigure dynamically the server while it’s running.
Ports folder has implementations of endpoints to receive and send message from an to other AjMessages servers.
PipelineHandler.cs is the composite handler, that contain other handlers.
LocalHost.cs is the implementation of a host running in the current server. It mantains a list of active nodes.
RemoteHost.cs mantains the info associated to a host running in other servers. Using this information, the local server knows how to forward a message, inspecting the remote hosts that have an active node.
Running the example
There is a console project AjMessages.Console01 that can be used as a manual test.
You can run the example, and enter the commands:
load ConfigurationServer1.xml
load ConfigurationHost1.xml
load ConfigurationHost2.xml
send App1/Node1/Process 20
The first command creates the server, using the configuration file. The second and third command reconfigure the server to install and run two hosts, with its applications and nodes. The last command send an integer message using App1/Node1/Process as action.
After that, you enter:
unload
fork
These launch another server console program. In the first one, enter:
load ConfigurationServer1.xml
load ConfigurationHost1.xml
load ConfigurationRemoteHost2.xml
and in the other server, enter:
load ConfigurationServer2.xml
load ConfigurationHost2.xml
load ConfigurationRemoteHost1.xml
In anyone, enter:
send App1/Node1/Process 20
and you’ll both servers exchanging messages.
In any moment, you can enter:
help
to obtain a list of commands to use.
Next steps
In a future installment of the example, I’ll rewrite the application to use a custom Message, capable of be transported via WCF, or DSS (Decentralized System Services), so the example could be hosted in different technologies. I must refactor some classes, for example, Server, that has many responsabilities.
Comments, suggestions, welcome!
Angel “Java” Lopez
http://www.ajlopez.com/en
Pingback: » AjMessages: a message processor
Pingback: Grid Computing Programming « Angel “Java” Lopez on Blog
Pingback: Segunda Semana Sabática del año | Buanzolandia
Pingback: Microsoft Robotics in enterprise application « Angel “Java” Lopez on Blog
Pingback: Microsoft Robotics in enterprise applications « Angel “Java” Lopez on Blog
Pingback: Distributed applications with AjMessages using DSS/CCR « Angel “Java” Lopez on Blog
Pingback: Aplicaciones distribuidas con AjMessages usando DSS/CCR - Angel "Java" Lopez
Pingback: Aplicaciones distribuidas con AjMessages usando DSS/CCR | Buanzolandia
Pingback: Distributed Web Crawler using AjMessages « Angel “Java” Lopez on Blog
Pingback: Web Crawler distribuido usando AjMessages - Angel "Java" Lopez
Pingback: Web Crawler distribuido usando AjMessages | Buanzolandia
Pingback: Web Crawler distribuido usando AjMessages | Buanzolandia
Pingback: Sydney: CCR Thoughts « Tales from a Trading Desk
Keep working on your web page. I like how we can all express our emotions. This is an extremely nice blog here.