Example #1
0
        public async Task HeaderIsAdded()
        {
            var port = ServiceManagerConfig.GetNextAvailablePort();

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseUrls($"http://*:{port}")
                       .UseStartup <Startup>()
                       .Build();

            host.Start();

            try
            {
                var client = new HttpClient();
                var result = await client.GetAsync($"http://localhost:{port}");

                var content = await result.Content.ReadAsStringAsync();

                Assert.Equal("Hello", content);
                Assert.Equal("FunnyHeader", result.Headers.Trailer.First());
            }
            finally
            {
                host.Dispose();
            }
        }
Example #2
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();
        }
        public void SmcTestInit()
        {
            // force new manager for testing.
            ServiceManager.Provider = () => new ServiceManager();
            ServiceManagerConfig.Initialize();

            // END FUNCTION
        }
        public RoutingFixture AddService(string name, string route)
        {
            var hostPort = ServiceManagerConfig.GetNextAvailablePort();

            var host = new WebHostBuilder()
                       .UseKestrel()
                       .UseUrls($"http://*:{hostPort}")
                       .Configure(app =>
            {
                RegisterService(name, hostPort, route);

                app.Run(async message =>
                {
                    HttpStatusCode status;
                    string content = null;
                    var path       = message.Request.Path;

                    var instance = _hosts[name];

                    if (path == HealthRoute)
                    {
                        if (instance.IsHealthy)
                        {
                            status  = HttpStatusCode.OK;
                            content = "Healthy";
                        }
                        else
                        {
                            status  = HttpStatusCode.InternalServerError;
                            content = "Not healthy";
                        }
                    }
                    else if (path == route)
                    {
                        status  = HttpStatusCode.OK;
                        content = "Called me " + name;
                    }
                    else
                    {
                        status  = HttpStatusCode.NotFound;
                        content = "";
                    }

                    message.Response.StatusCode = (int)status;
                    await message.Response.WriteAsync(content);
                });
            })
                       .Build();

            _hosts.Add(name, new ServiceInstance(host));

            return(this);
        }
Example #5
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();
        }
        public void AddRouter()
        {
            routerPort = ServiceManagerConfig.GetNextAvailablePort();

            _routerHost = new WebHostBuilder()
                          .UseKestrel()
                          .UseLoggerFactory(new LoggerFactory().AddConsole())
                          .UseUrls($"http://*:{routerPort}")
                          .ConfigureServices(x =>
            {
                x.AddCondenserWithBuilder()
                .WithRoutesBuiltCallback(SignalWhenAllRegistered)
                .Build();
            })
                          .Configure(app =>
            {
                _host = app.ApplicationServices.GetService <RoutingHost>();


                app.UseCondenser();
            })
                          .Build();
        }
Example #7
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 host = new WebHostBuilder()
                       .UseKestrel()
                       .UseUrls($"http://*:{port}")
                       .ConfigureServices(services =>
            {
                services.Configure <ServiceManagerConfig>(opts => opts.ServicePort = port);
            })
                       .UseStartup <Startup>()
                       .Build();

            host.Run();
        }
Example #8
0
        /// <summary>
        /// Ensures service manager is ready for use.
        /// </summary>
        protected override void BeginProcessing()
        {
            ServiceManagerConfig.Initialize();

            // END FUNCTION
        }