예제 #1
0
        public void Configuration(IAppBuilder app)
        {
            var logger = LogManager.GetLogger(this.GetType());

            logger.Info("Starting...");

            // Setup WebAPI configuration
            var configuration = new HttpConfiguration();

            configuration.Routes.Add("API Default", new HttpRoute("api/{Controller}/{action}"));

            // Configure OWIN pipeline

            // Configure NInject for WebAPI
            app.UseNinjectMiddleware(CreateKernel).UseNinjectWebApi(configuration);

            // Register the WebAPI to the pipeline. It is required for Configuration WebAPI
            app.UseWebApi(configuration);

            var options = new FileServerOptions {
                RequestPath = new PathString("/admin"),
                FileSystem  = new PhysicalFileSystem(@".\public"),
            };

            app.UseFileServer(options);

            var config = Owin.ApiGateway.Configuration.Configuration.Current ?? Owin.ApiGateway.Configuration.Configuration.Load();

            app.UseConfigurationManager(this.GetCurrentConfiguration, logger);

            var requestResponseLogStoreWriter = new SqlServerRequestResponseLogWriter(logger);
            var requestResponseLogger         = new BackgroundThreadLogger(requestResponseLogStoreWriter, logger);

            app.UseRequestResponseLogger(logger, requestResponseLogger);

            app.UseCache(new MemoryCacheProvider(), logger);
            app.UseRoutingManagerMiddleware(logger, this.GetCurrentConfiguration);
            app.UseProxy(logger, new ProxyOptions {
                VerboseMode = false
            });

            // configure and start endpoints health checking
            IServiceProbe serviceProbe = new ServiceProbe();

            serviceProbe.Initialize(this.GetCurrentConfiguration, logger);
            serviceProbe.Start();

            configuration.Formatters.Clear();
            configuration.Formatters.Add(new JsonMediaTypeFormatter());
            configuration.Formatters.JsonFormatter.SerializerSettings =
                new JsonSerializerSettings
            {
                ContractResolver = new CamelCasePropertyNamesContractResolver()
            };
        }
예제 #2
0
        public void ServiceInstanceIsMarkedAsDown_MonitoringEndpointReturnsSuccessMessage_ServiceInstanceIsMarkedAsUp()
        {
            var configuration = new Configuration.Configuration();

            configuration.Endpoints.Add(new Configuration.RoutingEndpoint
            {
                Id        = "service1",
                Instances = new Configuration.Instances
                {
                    Instance = new System.Collections.Generic.List <Configuration.Instance>
                    {
                        new Configuration.Instance
                        {
                            Status = ApiGateway.Configuration.InstanceStatuses.Down,
                            Url    = "http://service1.com/requestPath"
                        }
                    }
                },
                HealthCheck = new Configuration.HealthCheckConfiguration
                {
                    MonitoringPath = "/status",
                    ResponseShouldContainString = "OK"
                }
            });

            // Arrange
            Func <Configuration.Configuration> configurationGen = () => {
                return(configuration);
            };

            var  logMock = new Mock <ILog>();
            ILog logger  = logMock.Object;

            var responseHandler = new FakeResponseHandler();

            responseHandler.AddFakeResponseGenerator(new System.Uri("http://service1.com/status"), () =>
            {
                var r     = new HttpResponseMessage(HttpStatusCode.OK);
                r.Content = new StringContent("Service is OK.");

                return(r);
            });

            // Act
            var serviceProbe = new ServiceProbe(httpClientMessageHandler: responseHandler);

            serviceProbe.Initialize(configurationGen, logger);
            serviceProbe.TestEndpoint(configuration.Endpoints.First());

            // Assert
            Assert.AreEqual(Configuration.InstanceStatuses.Up, configuration.Endpoints.First().Instances.Instance.First().Status);
        }