示例#1
0
        public Consumer(
            Guid correlationId,
            Uri serviceUrl,
            string subscriptionName,
            string topic,
            IRegisterEvent eventRegister,
            IConsumerChannel <TMessage> initialChannel,
            IExecute executor,
            IStateChanged <ConsumerState> state,
            IConsumerChannelFactory <TMessage> factory)
        {
            _correlationId   = correlationId;
            ServiceUrl       = serviceUrl;
            SubscriptionName = subscriptionName;
            Topic            = topic;
            _eventRegister   = eventRegister;
            _channel         = initialChannel;
            _executor        = executor;
            _state           = state;
            _factory         = factory;
            _commandAckPool  = new DefaultObjectPool <CommandAck>(new DefaultPooledObjectPolicy <CommandAck>());
            _isDisposed      = 0;

            _eventRegister.Register(new ConsumerCreated(_correlationId));
        }
示例#2
0
        public async Task EstablishNewChannel(CancellationToken cancellationToken)
        {
            var channel = await _executor.Execute(() => _factory.Create(cancellationToken), cancellationToken).ConfigureAwait(false);

            var oldChannel = _channel;

            _channel = channel;

            if (oldChannel is not null)
            {
                await oldChannel.DisposeAsync().ConfigureAwait(false);
            }
        }
示例#3
0
        public Consumer(
            Guid correlationId,
            IRegisterEvent eventRegister,
            IConsumerChannel initialChannel,
            IExecute executor,
            IStateChanged <ConsumerState> state)
        {
            _correlationId    = correlationId;
            _eventRegister    = eventRegister;
            _channel          = initialChannel;
            _executor         = executor;
            _state            = state;
            _cachedCommandAck = new CommandAck();
            _isDisposed       = 0;

            _eventRegister.Register(new ConsumerCreated(_correlationId, this));
        }
示例#4
0
        internal async ValueTask SetChannel(IConsumerChannel channel)
        {
            if (_isDisposed != 0)
            {
                await channel.DisposeAsync().ConfigureAwait(false);

                return;
            }

            var oldChannel = _channel;

            _channel = channel;

            if (oldChannel is not null)
            {
                await oldChannel.DisposeAsync().ConfigureAwait(false);
            }
        }
示例#5
0
        public Consumer(
            Guid correlationId,
            string topic,
            IRegisterEvent eventRegister,
            IConsumerChannel initialChannel,
            IExecute executor,
            IStateChanged <ConsumerState> state)
        {
            _correlationId  = correlationId;
            Topic           = topic;
            _eventRegister  = eventRegister;
            _channel        = initialChannel;
            _executor       = executor;
            _state          = state;
            _commandAckPool = new DefaultObjectPool <CommandAck>(new DefaultPooledObjectPolicy <CommandAck>());
            _isDisposed     = 0;

            _eventRegister.Register(new ConsumerCreated(_correlationId, this));
        }
示例#6
0
        public Reader(
            Guid correlationId,
            Uri serviceUrl,
            string topic,
            IRegisterEvent eventRegister,
            IConsumerChannel initialChannel,
            IExecute executor,
            IStateChanged <ReaderState> state)
        {
            _correlationId = correlationId;
            ServiceUrl     = serviceUrl;
            Topic          = topic;
            _eventRegister = eventRegister;
            _channel       = initialChannel;
            _executor      = executor;
            _state         = state;
            _isDisposed    = 0;

            _eventRegister.Register(new ReaderCreated(_correlationId, this));
        }
示例#7
0
 internal void SetChannel(IConsumerChannel channel)
 {
     ThrowIfDisposed();
     _channel = channel;
 }