public void Initialize() { if (Interlocked.Exchange(ref _running, 1) != 0) { throw new InvalidOperationException("Thread is already running"); } var subEvents = _subscribeEventStore.Get(); long utcTimestamp = 0; if (subEvents.Count() > 0) { utcTimestamp = subEvents.Min(a => a.UTCTimestamp); } bool isUpdate = true; _logger.LogInformation("系统正在重建事件中"); do { var evts = _eventStore.Take(number, utcTimestamp); _logger.LogInformation($"重建事件 [{evts.Count}] 条"); isUpdate = evts.Count > 0; if (!isUpdate) { break; } _eventBus.Publish(evts.ToArray()); utcTimestamp = evts.Max(a => a.UTCTimestamp); } while (isUpdate); _logger.LogInformation($"完成事件重建"); }
public RingEventSnapshootHandler( IAssemblyProvider assemblyProvider , ISnapshootStoreFactory snapshootStoreFactory , IEventRebuildHandler eventRebuildHandler , ISubscribeEventStore subscribeEventStore , ISnapshootCache snapshootCache , ILoggerFactory loggerFactory , IEventHandleSubject eventHandleSubject , int maxHandleCount) : base(maxHandleCount) { this._assemblyProvider = assemblyProvider; _snapshootStoreFactory = snapshootStoreFactory; _eventRebuildHandler = eventRebuildHandler; _subscribeEventStore = subscribeEventStore; _snapshootCache = snapshootCache; _logger = loggerFactory.CreateLogger <RingEventSnapshootHandler>(); _eventHandleSubject = eventHandleSubject; this.Initialize(assemblyProvider.Assemblys); var subscribeEvent = _subscribeEventStore.Get(_defaultSubscribeId); if (subscribeEvent != null) { _subscribeEvent = subscribeEvent; } }
public RingEventBusinessHandler( IEventRegister eventRegister , IEventHandlerFactory eventHandlerFactory , ISubscribeEventStore subscribeEventStore , ILoggerFactory loggerFactory , IEventHandleSubject eventHandleSubject , int maxHandleCount) : base(maxHandleCount) { _eventRegister = eventRegister; _eventHandlerFactory = eventHandlerFactory; _subscribeEventStore = subscribeEventStore; _logger = loggerFactory.CreateLogger <RingEventBusinessHandler>(); _eventHandleSubject = eventHandleSubject; var subscribeEvent = _subscribeEventStore.Get(_defaultSubscribeId); if (subscribeEvent != null) { _subscribeEvent = subscribeEvent; } }