Created
October 27, 2014 15:50
-
-
Save thefringeninja/fd4a772e5e58a8c3e192 to your computer and use it in GitHub Desktop.
Creating a Cluster
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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