Esempio n. 1
0
        protected async Task <SerfClient> GetClient()
        {
            var splitHost   = Subject.Split(':');
            var hostPortion = splitHost[0];
            var port        = int.Parse(splitHost[1]);

            tcpClient = new TcpClient(hostPortion, port);
            srfClient = new SerfClient(tcpClient.GetStream());

            var handshakeError = await srfClient.Handshake();

            if (handshakeError != null)
            {
                throw new Exception($"failed during handshake: {handshakeError.Error}");
            }

            if (!string.IsNullOrWhiteSpace(Authenticationkey))
            {
                var authenticationError = await srfClient.Authenticate(Authenticationkey);

                if (authenticationError != null)
                {
                    throw new Exception($"failed during authentication: {authenticationError.Error}");
                }
            }

            return(srfClient);
        }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="configuration"></param>
 /// <returns></returns>
 public static ContainerBuilder AddSwimGossipClient(this ContainerBuilder builder, IConfiguration configuration)
 {
     builder.Register(c =>
     {
         var serfConfigurationOptions = new SerfConfigurationOptions();
         var apiConfigurationOptions  = new ApiConfigurationOptions();
         var serfSeedNodes            = new SerfSeedNodes();
         configuration.Bind("SeedNodes", serfSeedNodes);
         configuration.Bind("Serf", serfConfigurationOptions);
         configuration.Bind("Api", apiConfigurationOptions);
         var logger     = c.Resolve <Serilog.ILogger>();
         var serfClient = new SerfClient(c.Resolve <ISigning>(), serfConfigurationOptions,
                                         apiConfigurationOptions, serfSeedNodes, logger);
         return(serfClient);
     }).As <ISerfClient>().SingleInstance();
     return(builder);
 }