public RebuildProjectionEngine( EventUnwinder eventUnwinder, IConcurrentCheckpointTracker checkpointTracker, IProjection[] projections, IRebuildContext rebuildContext, ProjectionEngineConfig config, ProjectionEventInspector projectionInspector, ILoggerThreadContextManager loggerThreadContextManager) { _eventUnwinder = eventUnwinder; _checkpointTracker = checkpointTracker; _rebuildContext = rebuildContext; _config = config; _projectionInspector = projectionInspector; if (_config.Slots[0] != "*") { projections = projections .Where(x => _config.Slots.Any(y => y == x.Info.SlotName)) .ToArray(); } _allProjections = projections; _projectionsBySlot = projections .GroupBy(x => x.Info.SlotName) .ToDictionary(x => x.Key, x => x.OrderByDescending(p => p.Priority).ToArray()); _metrics = new ProjectionMetrics(_allProjections); _loggerThreadContextManager = loggerThreadContextManager; HealthChecks.RegisterHealthCheck("RebuildProjectionEngine", (Func <HealthCheckResult>)HealthCheck); }
public static void ClearMarkCommandExecution(this ILoggerThreadContextManager loggerThreadContextManager) { loggerThreadContextManager.ClearContextProperty(LoggingConstants.CommandId); loggerThreadContextManager.ClearContextProperty(LoggingConstants.UserId); loggerThreadContextManager.ClearContextProperty(LoggingConstants.CommandDescription); //correlation id during command execution is given by a special context data and default to message id if correlation is not present loggerThreadContextManager.ClearContextProperty(LoggingConstants.CorrleationId); }
public CommandsExecutorHelper( IInProcessCommandBus commandBus, IEventStoreQueryManager eventStoreQueryManager, IMessagesTrackerQueryManager messagesTrackerQueryManager) { _commandBus = commandBus; _eventStoreQueryManager = eventStoreQueryManager; _messagesTrackerQueryManager = messagesTrackerQueryManager; Logger = NullLogger.Instance; LoggerThreadContextManager = NullLoggerThreadContextManager.Instance; }
/// <summary> /// During command execution store some specific property on all the loggers so you can /// correlate logs to command execution. /// </summary> /// <param name="loggerThreadContextManager"></param> /// <param name="command"></param> /// <returns></returns> public static void MarkCommandExecution(this ILoggerThreadContextManager loggerThreadContextManager, ICommand command) { loggerThreadContextManager.SetContextProperty(LoggingConstants.CommandId, command?.MessageId); loggerThreadContextManager.SetContextProperty(LoggingConstants.UserId, command?.GetContextData(MessagesConstants.UserId)); loggerThreadContextManager.SetContextProperty(LoggingConstants.CommandDescription, String.Format("{0} [{1}]", command?.Describe(), command?.GetType())); //correlation id during command execution is given by a special context data and default to message id if correlation is not present var correlationId = command?.GetContextData(LoggingConstants.CorrleationId) ?? command?.MessageId.ToString(); loggerThreadContextManager.SetContextProperty(LoggingConstants.CorrleationId, correlationId); }
protected InProcessCommandBus( IKernel kernel, IMessagesTracker messagesTracker, ICommandExecutionExceptionHelper commandExecutionExceptionHelper) { _kernel = kernel; _messagesTracker = messagesTracker; Logger = NullLogger.Instance; LoggerThreadContextManager = NullLoggerThreadContextManager.Instance; _commandExecutionExceptionHelper = commandExecutionExceptionHelper; }
public MessageHandlerToCommandHandlerAdapter( ICommandHandler <T> commandHandler, ICommandExecutionExceptionHelper commandExecutionExceptionHelper, IMessagesTracker messagesTracker, IBus bus) { Logger = NullLogger.Instance; LoggerThreadContextManager = NullLoggerThreadContextManager.Instance; _commandHandler = commandHandler; _messagesTracker = messagesTracker; _bus = bus; _commandExecutionExceptionHelper = commandExecutionExceptionHelper; }
/// <summary> /// TODO: We should pass a dictionary where we have the last dispatched /// checkpoint for EACH projection. /// </summary> /// <param name="logger"></param> /// <param name="slotName"></param> /// <param name="config"></param> /// <param name="projections"></param> /// <param name="lastCheckpointDispatched"></param> /// <param name="loggerThreadContextManager"></param> public RebuildProjectionSlotDispatcher( ILogger logger, String slotName, ProjectionEngineConfig config, IEnumerable <IProjection> projections, Int64 lastCheckpointDispatched, ILoggerThreadContextManager loggerThreadContextManager) { SlotName = slotName; _logger = logger; _config = config; _projections = projections; _metrics = new ProjectionMetrics(projections); _maxCheckpointDispatched = lastCheckpointDispatched; _lastCheckpointRebuilded = 0; _loggerThreadContextManager = loggerThreadContextManager; }
/// <summary> /// This is the basic constructor for the projection engine. /// </summary> /// <param name="pollingClientFactory"></param> /// <param name="persistence"></param> /// <param name="checkpointTracker"></param> /// <param name="projections"></param> /// <param name="housekeeper"></param> /// <param name="notifyCommitHandled"></param> /// <param name="config"></param> /// <param name="logger"></param> /// <param name="loggerThreadContextManager"></param> public ProjectionEngine( ICommitPollingClientFactory pollingClientFactory, IPersistence persistence, IConcurrentCheckpointTracker checkpointTracker, IProjection[] projections, IHousekeeper housekeeper, INotifyCommitHandled notifyCommitHandled, ProjectionEngineConfig config, ILogger logger, ILoggerThreadContextManager loggerThreadContextManager) { if (projections == null) { throw new ArgumentNullException(nameof(projections)); } if (config == null) { throw new ArgumentNullException(nameof(config)); } _persistence = persistence ?? throw new ArgumentNullException(nameof(persistence)); _logger = logger; _loggerThreadContextManager = loggerThreadContextManager; var configErrors = config.Validate(); if (!String.IsNullOrEmpty(configErrors)) { throw new ArgumentException(configErrors, nameof(config)); } _engineFatalErrors = new ConcurrentBag <string>(); _pollingClientFactory = pollingClientFactory ?? throw new ArgumentNullException(nameof(pollingClientFactory)); _checkpointTracker = checkpointTracker ?? throw new ArgumentNullException(nameof(checkpointTracker)); _housekeeper = housekeeper ?? throw new ArgumentNullException(nameof(housekeeper)); _notifyCommitHandled = notifyCommitHandled ?? throw new ArgumentNullException(nameof(notifyCommitHandled)); _config = config; if (_config.Slots[0] != "*") { projections = projections .Where(x => _config.Slots.Any(y => y == x.Info.SlotName)) .ToArray(); } if (OfflineMode.Enabled) { //In offline mode we already have filtered out the projection. _allProjections = projections; } else { //we are not in offline mode, just use all projection that are not marked to //run only in offline mode logger.Info($"Projection engine is NOT in OFFLINE mode, projection engine will run only projection that are not marked for OfflineModel."); _allProjections = projections.Where(_ => !_.Info.OfflineProjection).ToArray(); } _projectionsBySlot = projections .GroupBy(x => x.Info.SlotName) .ToDictionary(x => x.Key, x => x.OrderByDescending(p => p.Priority).ToArray()); _bucketToClient = new Dictionary <BucketInfo, ICommitPollingClient>(); RegisterHealthCheck(); }