/// <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); }
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; } }
/// <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; }
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; }
public ConsoleApplication(IMicroservice microservice) { if (microservice == null) { throw new ArgumentNullException(nameof(microservice)); } _cancellationTokenSource = new CancellationTokenSource(); _logger = LoggerHelper.GetLogger <ConsoleApplication>(); _microservice = microservice; }
/// <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(); }
internal EventsWrapper(IMicroservice service, IDataCollection dataCollection, Func <ServiceStatus> getStatus) : base(getStatus) { mService = service; mService.StatusChanged += OnStatusChanged; mDataCollection = dataCollection; }
public MicroserviceContainerIoC(IMicroservice microservice) { this.microservice = microservice; }
/// <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(); }
/// <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)); }
/// <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; }
/// <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; }