Example #1
0
        static void Main(string[] args)
        {
            var port = ServiceManagerConfig.GetNextAvailablePort();

            var serviceName = "Service.Data";
            var serviceId   = $"{serviceName}_127.0.0.1:{port}";

            var apiHost = new WebHostBuilder()
                          .ConfigureLogging((_, factory) =>
            {
                factory.AddConsole();
            })
                          .UseKestrel(options =>
            {
                options.Listen(IPAddress.Any, port, listenOptions =>
                {
                    listenOptions.UseConnectionLogging();
                });
            })
                          .ConfigureServices(services =>
            {
                services.Configure <ServiceManagerConfig>(options =>
                {
                    options.ServicePort    = port;
                    options.ServiceName    = serviceName;
                    options.ServiceId      = serviceId;
                    options.ServiceAddress = "127.0.0.1";
                });
                services.AddSingleton <IConfigurationRegistry>(CondenserConfigBuilder.FromConsul().WithAgentAddress("127.0.0.1").WithAgentPort(8500).Build());
            })
                          .UseStartup <Startup>()
                          .Build();

            apiHost.Run();
        }
Example #2
0
        public async Task TestKeyHandlesFrontSlash()
        {
            using (var registry = CondenserConfigBuilder.FromConsul().Build())
            {
                var keyname = Guid.NewGuid().ToString();
                await registry.SetKeyAsync($"org/{keyname}/test1", _value1);

                var result = await registry.AddStaticKeyPathAsync($"/org/{keyname}");

                Assert.Equal(true, result);

                var firstValue = registry["test1"];

                Assert.Equal(_value1, firstValue);
            }
        }
Example #3
0
        public static void Main(string[] args)
        {
            var port = ServiceManagerConfig.GetNextAvailablePort();

            //This setup would be done outside of this sample.
            //The environment variable is passed to the startup to bootstrap
            var environment = "Org1";

            Environment
            .SetEnvironmentVariable("ASPNETCORE_ENVIRONMENT", environment);

            var registry = CondenserConfigBuilder
                           .FromConsul()
                           .WithKeysStoredAsJson()
                           .Build();

            //***Add some config
            var config = new ConsulConfig
            {
                Setting = "Test"
            };

            registry.SetKeyJsonAsync($"{environment}/ConsulConfig", config).Wait();
            //***


            registry.AddUpdatingPathAsync(environment).Wait();

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseUrls($"http://*:{port}")
                       .ConfigureServices(services =>
            {
                services.AddSingleton <IConfigurationRegistry>(registry);
                services.Configure <ServiceManagerConfig>(opts => opts.ServicePort = port);
            })
                       .UseStartup <Startup>()
                       .Build();

            host.Run();
        }