/// <summary>
        /// Indicates whether the microservice is running. Will wait for the supplied duration for
        /// the service to come up if a duration has been supplied
        /// </summary>
        /// <param name="microservice"></param>
        /// <param name="waitToStartDuration"></param>
        /// <returns></returns>
        private async Task <bool> IsMicroserviceRunning(IMicroservice microservice, TimeSpan waitToStartDuration)
        {
            if (microservice == null)
            {
                return(false);
            }

            lock (mSyncLock)
            {
                if (microservice.Status == ServiceStatus.Running)
                {
                    return(true);
                }

                if (!mIsSubscribedToStatusEvent)
                {
                    microservice.StatusChanged += new EventHandler <StatusChangedEventArgs>(Microservice_StatusChanged);
                    mIsSubscribedToStatusEvent  = true;
                }
            }

            if (microservice.Status == ServiceStatus.Running)
            {
                return(true);
            }

            await mStatusChangeResetEvent.WaitOneAsync(waitToStartDuration);

            return(microservice.Status == ServiceStatus.Running);
        }
예제 #2
0
        public static void Run(
            IUnityContainer container, Func <IMicroservice> microserviceFactory,
            bool useSignalRLog = true, bool verbose = true, IEnumerable <IPollableEventSource> ocassionallyConnectedSources = null)
        {
            lock (_lockObject)
            {
                // Double checking
                if (_microservice != null || isRunning)
                {
                    return;
                }

                DbConfiguration.SetConfiguration(new TransientFaultHandlingDbConfiguration());
                container     = ContainerFactory.ResolveCommonDependenciesForMainContainer(container, useSignalRLog, verbose);
                _microservice = microserviceFactory.Invoke();

                if (ocassionallyConnectedSources != null)
                {
                    var inMemoryEventPublisher = container.Resolve <IInMemoryEventPublisher>();
                    ocassionallyConnectedSources.ForEach(x => inMemoryEventPublisher.Register(x));
                }

                _microservice.Start();
                isRunning = true;
            }
        }
예제 #3
0
        /// <summary>
        /// This method is called as part of the ASP.Net Core pipeline
        /// </summary>
        /// <param name="context">The context</param>
        /// <returns>This is an async process.</returns>
        public async Task Invoke(HttpContext context)
        {
            Exception     logEx = null;
            IMicroservice ms    = Options.Microservice ?? context.RequestServices.GetService <IMicroservice>();

            try
            {
                await Next(context);
            }
            catch (Exception ex)
            {
                logEx = ex;
                throw;
            }
            finally
            {
                if (ms != null &&
                    Options.Level != ApiBoundaryLoggingFilterLevel.None &&
                    (Options.Filter?.Invoke(context) ?? true)
                    )
                {
                    var boundaryLog = new AspNetCoreBoundaryEvent(context, Options.Level, logEx);
                    ms.DataCollection.Write(boundaryLog, DataCollectionSupport.ApiBoundary, false);
                }
            }
        }
 public HealthStatusReportService(
     ILogger logger,
     IMicroservice microservice,
     CancellationToken cancellationToken)
 {
     Logger            = logger;
     Microservice      = microservice;
     CancellationToken = cancellationToken;
 }
예제 #5
0
        public HeartbeatEmitter(IMicroservice node, ILogger log, IMonitoredSubscriber subscriber)
        {
            Ensure.NotNull(node, nameof(node));
            Ensure.NotNull(log, nameof(log));
            Ensure.NotNull(subscriber, nameof(subscriber));

            this.node       = node;
            this.log        = log;
            this.subscriber = subscriber;
        }
예제 #6
0
        public ConsoleApplication(IMicroservice microservice)
        {
            if (microservice == null)
            {
                throw new ArgumentNullException(nameof(microservice));
            }

            _cancellationTokenSource = new CancellationTokenSource();
            _logger       = LoggerHelper.GetLogger <ConsoleApplication>();
            _microservice = microservice;
        }
예제 #7
0
        /// <summary>
        /// This is the default pipeline.
        /// </summary>
        /// <param name="service">The microservice.</param>
        /// <param name="config">The microservice configuration.</param>
        public MicroservicePipeline(IMicroservice service, IEnvironmentConfiguration config)
        {
            if (service == null)
            {
                throw new ArgumentNullException("service cannot be null");
            }
            if (config == null)
            {
                throw new ArgumentNullException("config cannot be null");
            }

            Service       = service;
            Configuration = config;
        }
        /// <summary>
        /// This is the default pipeline.
        /// </summary>
        /// <param name="service">The microservice.</param>
        /// <param name="config">The microservice configuration.</param>
        /// <param name="httpConfig">The http configuration.</param>
        /// <param name="registerConfig">The boolean property registers the Microservice configuration with Unity.</param>
        public UnityWebApiMicroservicePipeline(IMicroservice service
                                               , IEnvironmentConfiguration config
                                               , HttpConfiguration httpConfig = null
                                               , bool registerConfig          = true
                                               ) : base(service, config, httpConfig)
        {
            //ApiConfig.
            Unity = new UnityContainer();

            HttpConfig.DependencyResolver = new UnityDependencyResolver(Unity);

            if (registerConfig)
            {
                Unity.RegisterInstance <IEnvironmentConfiguration>(this.Configuration);
            }
        }
        /// <summary>
        /// Event handler that indicates the microservice has changed status
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Microservice_StatusChanged(object sender, StatusChangedEventArgs e)
        {
            if (e == null || e.StatusNew != ServiceStatus.Running)
            {
                return;
            }

            IMicroservice microservice = sender as IMicroservice;

            if (microservice != null && mIsSubscribedToStatusEvent)
            {
                lock (mSyncLock)
                {
                    if (mIsSubscribedToStatusEvent)
                    {
                        microservice.StatusChanged -= new EventHandler <StatusChangedEventArgs>(Microservice_StatusChanged);
                        mIsSubscribedToStatusEvent  = false;
                    }
                }
            }

            mStatusChangeResetEvent.Set();
        }
예제 #10
0
 internal EventsWrapper(IMicroservice service, IDataCollection dataCollection, Func <ServiceStatus> getStatus) : base(getStatus)
 {
     mService = service;
     mService.StatusChanged += OnStatusChanged;
     mDataCollection         = dataCollection;
 }
예제 #11
0
 public MicroserviceContainerIoC(IMicroservice microservice)
 {
     this.microservice = microservice;
 }
예제 #12
0
 /// <summary>
 /// This is the default pipeline.
 /// </summary>
 /// <param name="service">The microservice.</param>
 /// <param name="config">The microservice configuration.</param>
 /// <param name="httpConfig">The http configuration.</param>
 public WebApiMicroservicePipeline(IMicroservice service
                                   , IEnvironmentConfiguration config
                                   , HttpConfiguration httpConfig = null) : base(service, config)
 {
     HttpConfig = httpConfig ?? new HttpConfiguration();
 }
예제 #13
0
 /// <summary>
 /// This is the base setting.
 /// </summary>
 /// <param name="service">This is the service.</param>
 /// <param name="config">This is the configuration settings.</param>
 /// <returns>Returns the pipeline object.</returns>
 public static IPipeline ToPipeline(this IMicroservice service, IEnvironmentConfiguration config)
 {
     return(new MicroservicePipeline(service, config));
 }
예제 #14
0
 /// <summary>
 /// This is the default pipeline.
 /// </summary>
 /// <param name="service">The microservice.</param>
 /// <param name="config">The microservice configuration.</param>
 /// <param name="app">The AspNetCore application.</param>
 public AspNetCoreMicroservicePipeline(IMicroservice service
                                       , IEnvironmentConfiguration config
                                       , IApplicationBuilder app = null) : base(service, config)
 {
     App = app;
 }
예제 #15
0
 /// <summary>This is the default constructor.</summary>
 /// <param name="retryInSeconds">The default retry time in seconds.</param>
 /// <param name="waitToStartSeconds">The number of seconds to wait prior to returning 503 starting</param>
 public MicroserviceUnavailableFilter(IMicroservice ms, int retryInSeconds = 10, int waitToStartSeconds = 0)
 {
     Microservice       = ms;
     RetryInSeconds     = retryInSeconds;
     WaitToStartSeconds = waitToStartSeconds;
 }