Skip to content

Instantly share code, notes, and snippets.

@thefringeninja
Created October 27, 2014 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thefringeninja/fd4a772e5e58a8c3e192 to your computer and use it in GitHub Desktop.
Save thefringeninja/fd4a772e5e58a8c3e192 to your computer and use it in GitHub Desktop.
Creating a Cluster
public static class Program {
const int ClusterSize = 3;
public static void Main(string[] args) {
int clusterMemberId = Int32.Parse(args[0]);
var options = new StartupOptions {
ClusterMemberId = clusterMemberId
}
ClusterVNode node = options.BuildVNode(ClusterSize);
node.Start();
Console.ReadLine();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Net;
using EventStore.ClientAPI.Embedded;
public class StartupOptions
{
public int ClusterMemberId { get; set; }
private int BaseClusterPort
{
get { return ClusterMemberId * 1000; }
}
private int InternalTcpPort
{
get { return BaseClusterPort + 111; }
}
private int ExternalTcpPort
{
get { return BaseClusterPort + 112; }
}
private int InternalHttpPort
{
get { return BaseClusterPort + 113; }
}
private int ExternalHttpPort
{
get { return BaseClusterPort + 114; }
}
private IPEndPoint ExternalHttpEndpoint
{
get { return new IPEndPoint(IPAddress.Loopback, ExternalHttpPort); }
}
private IPEndPoint InternalHttpEndpoint
{
get { return new IPEndPoint(IPAddress.Loopback, InternalHttpPort); }
}
private IPEndPoint ExternalTcpEndpoint
{
get { return new IPEndPoint(IPAddress.Loopback, ExternalTcpPort); }
}
private IPEndPoint InternalTcpEndpoint
{
get { return new IPEndPoint(IPAddress.Loopback, InternalTcpPort); }
}
public EmbeddedVNodeBuilder BuildVNode(int clusterSize)
{
return EmbeddedVNodeBuilder.AsClusterMember(clusterSize)
.WithInternalTcpOn(InternalTcpEndpoint)
.WithExternalTcpOn(ExternalTcpEndpoint)
.WithInternalHttpOn(InternalHttpEndpoint)
.WithExternalHttpOn(ExternalHttpEndpoint)
.WithGossipSeeds(GossipSeeds(clusterSize).ToArray());
}
private IEnumerable<IPEndPoint> GossipSeeds(int clusterSize)
{
return from otherClusterMemberId in Enumerable.Range(1, clusterSize)
where otherClusterMemberId != ClusterMemberId
select new StartupOptions // I'm lazy
{
ClusterMemberId = otherClusterId
}.InternalHttpEndpoint;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment