Default ScaleOut
By defauls XSockets scale P2P
where each server acts as a client to other servers. So you can actually choose to scale one way if you have specific needs.
This ScaleOut
option is mostly used behind firewalls since the connection between the servers is unsecure NOT TLS/SSL by default. This can of course be taken care of in a custom ScaleOut
.
Configure the ScaleOut
In this example we have a solution with 2 Console Applications. Server1
project and Server2
project. Each server has XSockets installed and they both have the default startup code in the Console Application.
Configuration Template
The difference between the projects will be the configuration. They will need to start on separate endpoints so that they can connect to each other.
The configuration is added from the item templates
Configuration for Server1 looks like
public class Server1Config : ConfigurationSetting
{
public Server1Config() : base("ws://127.0.0.1:8080") { }
}
And configuration for Server2 looks like
public class Server2Config : ConfigurationSetting
{
public Server2Config() : base("ws://127.0.0.1:8181") { }
}
Configure Server Siblings
Each server can say that it want to scale incoming data to one or more destinations. This is done by using the IXSocketsScaleOut
module
Server1
that starts on localhost:8080
will scale to Server2
that starts on localhost:8181
So, scaling for Server1
var enterprise = Composable.GetExport<IXSocketsScaleOut>();
enterprise.AddScaleOut("ws://localhost:8181");
and, scaling for Server2
var enterprise = Composable.GetExport<IXSocketsScaleOut>();
enterprise.AddScaleOut("ws://localhost:8080");
Test the Default ScaleOut
As seen many times before in this documentation we can use Putty to test this quickly.
We open two instances of Putty and connect one to localhost:8080
and the other to localhost:8181
I configured the solution to run both Console Applications on start, so this is what we got after starting the debugger.
Then we start 2 instances of Putty and connects them to each server
After sending in the handshake PuttyProtocol
, we open a controller instance by sending generic|1|
If you have no idea what this means read the The Basics
section as well as the Controllers
section
Now the client to the right sends in a message on the generic controller generic|foo|bar
. The message then arrives at both clients since the server ScaledOut
the message coming in to the other servers in the configured ScaleOut
The Code
It is very easy to use the default ScaleOut
and the full source of the server project can be seen below. Of course there will be challenges if you are doing CRUD operations
for example. You do not want to ScaleOut
a Save/Delete/Create to all servers in the ScaleOut
. However, we can solve that as well with Custom ScaleOuts
(covered later).
using System;
using XSockets.Core.Common.Enterprise;
using XSockets.Core.Common.Socket;
using XSockets.Plugin.Framework;
namespace Server2
{
class Program
{
static void Main(string[] args)
{
var enterprise = Composable.GetExport<IXSocketsScaleOut>();
enterprise.AddScaleOut("ws://localhost:8080");
using (var container = Composable.GetExport<IXSocketServerContainer>())
{
container.Start();
Console.ReadLine();
}
}
}
}