示例#1
0
        /// <summary>
        /// Activate Grain
        /// </summary>
        /// <returns></returns>
        public override async Task OnActivateAsync()
        {
            try
            {
                this._eventBufferBlock      = new DataflowBufferBlock <EventTransactionModel <TStateKey> >(this.TriggerEventStorage);
                this._internalConfiguration = this.ServiceProvider.GetRequiredService <IInternalConfiguration>();
                this._mqPublisher           = this.ServiceProvider.GetRequiredService <IMQPublisher>();
                this._eventSourcing         = await this.ServiceProvider.GetEventSourcing <TState, TStateKey>(this).Init(this.StateId);

                this.State = await this._eventSourcing.ReadSnapshotAsync();

                this.PublishOptions = this._internalConfiguration.GetEventPublishOptions(this);
                await base.OnActivateAsync();
            }
            catch (Exception ex)
            {
                this.Logger.LogError(ex, $"{StateId} Activate Grain failure");
                throw ex;
            }
        }
示例#2
0
        public async Task <IEventSourcing <TState, TStateKey> > Init(TStateKey stateKey)
        {
            this.StateId         = stateKey;
            this._storageFactory = new StorageFactory(this._serviceProvider, this.Options.StorageOptions);
            this._eventStorage   = await this._storageFactory.GetEventStorage(this.Options.EventSourceName, this.StateId.ToString());

            string bufferKey = "es" + this.Options.EventSourceName + this.Options.StorageOptions.StorageProvider;

            this._eventBufferBlock = this._serviceProvider.GetRequiredService <IDataflowBufferBlockFactory>().Create <EventStorageModel>(bufferKey, this.LazySaveAsync);

            //Get snapshot storage information
            if (this.Options.SnapshotOptions.SnapshotType != SnapshotType.NoSnapshot)
            {
                IStorageFactory snapshotStorageFactory = new StorageFactory(this._serviceProvider, this.Options.SnapshotOptions);
                this._snapshotStorage = await snapshotStorageFactory.GetStateStorage(this.Options.EventSourceName, StorageType.EventSourceSnapshot, this.StateId.ToString());

                this.SnapshotTable = await snapshotStorageFactory.GetTable(this.Options.EventSourceName, StorageType.EventSourceSnapshot, this.StateId.ToString());
            }
            return(this);
        }
示例#3
0
 public EventProcessCore(IServiceProvider serviceProvider, ILogger <EventProcessCore> logger)
 {
     this._serviceProvider  = serviceProvider;
     this._logger           = logger;
     this._eventBufferBlock = new DataflowBufferBlock <EventProccessBufferWrap>(this.TriggerEventProcessing);
 }