예제 #1
0
 public static ClusterHost UseRedisClusterProvider(this ClusterHost host, Action <RedisOptions> configuration)
 {
     return(host.ConfigureServices(services =>
     {
         var options = new RedisOptions();
         configuration?.Invoke(options);
         services.AddSingleton(options).AddRedis();
     }));
 }
예제 #2
0
        public static void StartgRPCService <T>(this ClusterHost cluster, T t) where T : ServerServiceDefinition
        {
            var addr = new Uri(cluster.GetConfig <HostOptions>().Address);

            server = new Server
            {
                Services = { t },
                Ports    = { new ServerPort(addr.Host, addr.Port, ServerCredentials.Insecure) }
            };
            server.Start();
        }
예제 #3
0
 public static void StopWcfService(this ClusterHost cluster)
 {
     if (hosts == null)
     {
         return;
     }
     foreach (var host in hosts)
     {
         host.Close();
     }
 }
예제 #4
0
        static void Main(string[] args)
        {
            var cluster = new ClusterHost();

            cluster.UseConfig <HostOptions>(new HostOptions()
            {
                ClusterID = "test"
            });
            cluster.UseRedisClusterProvider(x =>
            {
                x.ConnectionString = "localhost:7000,localhost:7001,localhost:7002,syncTimeout=30000,asyncTimeout=30000,allowAdmin=True,connectTimeout=5000,responseTimeout=5000,password=rdc!234";
            });
            cluster.StartWcfService();
            cluster.Start();
            Console.WriteLine("start");
            Console.ReadLine();
            cluster.StopWcfService();
        }
예제 #5
0
        public static void StartWcfService <T>(this ClusterHost cluster)
        {
            hosts = new List <ServiceHost>();
            var config = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location);
            var groups = (ServiceModelSectionGroup)config.GetSectionGroup("system.serviceModel");
            var routes = new Dictionary <string, string>();

            foreach (ServiceElement service in groups.Services.Services)
            {
                ServiceHost host = new ServiceHost(typeof(T).Assembly.GetType(service.Name));
                host.Open();
                hosts.Add(host);
                foreach (ServiceEndpoint endpoint in host.Description.Endpoints)
                {
                    routes.Add(endpoint.Contract.ContractType.FullName, endpoint.ListenUri.ToString());
                }
            }
            cluster.CurrentNode.Details.Add("contract", JsonConvert.SerializeObject(routes));
        }
 public static ClusterHost UseBasicAuthenticate(this ClusterHost cluster, string token)
 {
     cluster.CurrentNode.Details.Add("Authorization", token);
     return(cluster);
 }
예제 #7
0
 public static void StopWcfService(this ClusterHost cluster)
 {
     server.ShutdownAsync().Wait();
 }
예제 #8
0
 public static void EnableCluster(this ClusterHost cluster)
 {
     cluster.CurrentNode.Details.Add("name", cluster.GetConfig <HostOptions>().ServiceName);
 }