This project is read-only.

XcoAppSpace Discovery Service

In a scenario where a number of distributed partners are communicating with each other, there is often the problem that one doesn't know the address of the other. This problem could be solved by making the addresses of all partners static - but this is often not possible, or at least leads to a not very well configurable system. It is much easier if you only have a single point in the network that is known by all communicating partners, and where they can get access to services offered by others. This is what a lookup or discovery service does.
The AppSpace offers an addon for this feature, called XcoAppSpaces.Discovery. It lets you define an AppSpace instance as a discovery server, and provides extension methods for the XcoAppSpace class that allow easy discovery of other workers in a network of connected AppSpace instances.

Configuring the discovery server

Configuring an AppSpace instance as a discovery server is simple. Take a look at the example below - this is all the code you need for a simple console-based discovery server:
using (var space = new XcoAppSpace("tcp.port=9000;disco.isserver=true"))  //the space running on port 9000 defines itself as discovery server
{
   Console.WriteLine("discovery server running...");
   Console.ReadLine();
}
As you can see, the discovery service can simply be configured with a config string - using the configuration element disco.isserver=true, the AppSpace instance is defined to be a discovery server. The only other thing you need to do is add a reference to XcoAppSpaces.Discovery.dll to your project.
Of course the discovery server could also host workers itself, which are then discoverable by other space Instance.

Hosting a discoverable worker

With the discovery server up and running, other AppSpace instances can now easily connect to it, so that their published workers are automatically discoverably. The following example shows an AppSpace instance that connects to the discovery service and hosts a single worker:
using (var space = new XcoAppSpace("tcp.port=9005;disco.address=discomachine:9000"))  //here the address of the discovery server needs to be defined
{
   space.RunWorker<PMathWorker, MyMathWorker>("math");
   
   Console.WriteLine("running...");
   Console.ReadLine();
}
Discovery is again configured using the configuration string. The element disco.address=discomachine:9000 tells the AppSpace that there is a discovery server running at the given address. With this information, the AppSpace automatically announces its presence to the discovery server at startup. If the discovery server cannot be reached, the AppSpace will automatically retry establishing a connection.

Discovering a worker

Finally, let's take a look at how a worker can be discovered. The first important step for that is to import the namespace XcoAppSpaces.Discovery. By doing that, you will be able to use the extension method DiscoverWorker(). The following example shows the details:
using (var space = new XcoAppSpace("tcp.port=0;disco.address=discomachine:9000"))  //here the address of the discovery server needs to be defined
{
   var w = space.DiscoverWorker<PMathWorker>("math");
   ...
}
As you can see, the AppSpace connects to the discovery server in exactly the same way as shown in the example for hosting a discoverable worker. Now the only thing that needs to be done to connect to a worker is to use the DiscoverWorker() method. As you can see there is no more need now to know the worker's address - only its name and contract type are needed. That's everything you need to flexibly host your workers with many distributed space instances and only a single well known address in the network.

You can also find the example described here in the advanced section of the usage demos.

Last edited Jul 9, 2010 at 1:39 PM by thomass, version 5

Comments

No comments yet.