Angel \”Java\” Lopez on Blog

October 18, 2007

AjMessages: a message processor

Filed under: .NET, AjMessages, Windows Communication Foundation — ajlopez @ 10:33 am

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

14 Comments »

  1. [...] Original post by ajlopez [...]

    Pingback by » AjMessages: a message processor — October 18, 2007 @ 10:49 am

  2. [...] AjMessages: a message processor [...]

    Pingback by Grid Computing Programming « Angel “Java” Lopez on Blog — December 3, 2007 @ 10:53 am

  3. [...] una versión nueva de AjMessage, que soporte el transporte de mensajes via DSS/CCR así como por Windows Communication [...]

    Pingback by Segunda Semana Sabática del año | Buanzolandia — September 21, 2008 @ 12:07 am

  4. [...] AjMessages- a message processor [...]

    Pingback by Microsoft Robotics in enterprise application « Angel “Java” Lopez on Blog — September 24, 2008 @ 8:22 am

  5. [...] AjMessages- a message processor [...]

    Pingback by Microsoft Robotics in enterprise applications « Angel “Java” Lopez on Blog — September 24, 2008 @ 8:27 am

  6. [...] AjMessages- a message processor [...]

    Pingback by Distributed applications with AjMessages using DSS/CCR « Angel “Java” Lopez on Blog — October 8, 2008 @ 12:07 pm

  7. [...] AjMessages- a message processorAjMessages- hacia un procesador de mensajes [...]

    Pingback by Aplicaciones distribuidas con AjMessages usando DSS/CCR - Angel "Java" Lopez — October 10, 2008 @ 11:42 am

  8. [...] AjMessages- a message processorAjMessages- hacia un procesador de mensajes [...]

    Pingback by Aplicaciones distribuidas con AjMessages usando DSS/CCR | Buanzolandia — October 11, 2008 @ 12:01 am

  9. [...] AjMessages- a message processorDistributed Applications with AjMessages using DSS/CCR [...]

    Pingback by Distributed Web Crawler using AjMessages « Angel “Java” Lopez on Blog — March 9, 2009 @ 8:11 am

  10. [...] AjMessages- a message processorDistributed Applications with AjMessages using DSS/CCRAplicaciones Distribuidas con AjMessages usando DSS/CCRAjMessages- hacia un procesador de mensajes [...]

    Pingback by Web Crawler distribuido usando AjMessages - Angel "Java" Lopez — March 10, 2009 @ 1:07 am

  11. [...] AjMessages- a message processorDistributed Applications with AjMessages using DSS/CCRAplicaciones Distribuidas con AjMessages usando DSS/CCRAjMessages- hacia un procesador de mensajes [...]

    Pingback by Web Crawler distribuido usando AjMessages | Buanzolandia — March 10, 2009 @ 3:40 am

  12. [...] pueden albergarse en una o más máquinas física. Más información sobre AjMessages en: AjMessages- a message processorDistributed Applications with AjMessages using DSS/CCRAplicaciones Distribuidas con AjMessages [...]

    Pingback by Web Crawler distribuido usando AjMessages | Buanzolandia — March 15, 2009 @ 6:43 am

  13. [...] let me start by first highlighting Angel “Java” Lopez blog which has a few postings on the CCR: AjMessages, Distributed Agents using DSS/VPL and [...]

    Pingback by Sydney: CCR Thoughts « Tales from a Trading Desk — September 28, 2010 @ 7:43 am

  14. Keep working on your web page. I like how we can all express our emotions. This is an extremely nice blog here.

    Comment by buy junk silver coins — March 3, 2011 @ 7:50 pm


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

The Shocking Blue Green Theme. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

Join 66 other followers

%d bloggers like this: