Example #1
0
        public PubSubSSSBService(Guid conversationGroup, IServiceProvider services, IPubSubHelper pubSubHelper, HeartBeatTimer heartBeatTimer, ILogger <PubSubSSSBService> logger)
        {
            try
            {
                this._conversationGroup = conversationGroup;
                this._services          = services;
                this._pubSubHelper      = pubSubHelper;
                this._heartBeatTimer    = heartBeatTimer;
                this._logger            = logger ?? throw new ArgumentNullException(nameof(logger));
                this._startDateTime     = DateTime.Now;

                _sssbService = SSSBService.Create(this._services, (options) => { options.ConversationGroup = conversationGroup; options.MaxReadersCount = 1; options.Name = PubSubHelper.SUBSCRIBER_SERVICE_NAME; });
                _sssbService.OnStartedEvent += async() =>
                {
                    this._startDateTime = DateTime.Now;
                    await this.OnStarted(_sssbService.QueueName);
                };
                _sssbService.OnStoppedEvent += async() =>
                {
                    await this.OnStopped(_sssbService.QueueName);
                };
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ErrorHelper.GetFullMessage(ex));
                throw;
            }
        }
Example #2
0
        public HeartBeatTimer(Guid conversationGroup, IServiceProvider services, IPubSubHelper pubSubHelper, ILogger <HeartBeatTimer> logger)
        {
            this._conversationGroup = conversationGroup;
            this._services          = services;
            this._pubSubHelper      = pubSubHelper;
            this._logger            = logger;
            this._isStopped         = true;

            this._timer = new System.Threading.Timer(async(state) => {
                try
                {
                    this.Pause();
                    var connectionManager = _services.GetRequiredService <IConnectionManager>();

                    using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.RequiresNew, TransactionScopeAsyncFlowOption.Enabled))
                        using (var dbconnection = await connectionManager.CreateSSSBConnectionAsync(CancellationToken.None))
                        {
                            await _pubSubHelper.HeartBeat(dbconnection, TimeSpan.FromDays(365 * 10), _conversationGroup);
                            transactionScope.Complete();
                        }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex.Message);
                }
                finally
                {
                    this.Resume();
                }
            });
        }