Esempio n. 1
0
 private void OnException(Exception exception)
 {
     if (_faultStrategy.DetermineFaultAction(exception) == FaultAction.Relookup)
     {
         _proxy.Disconnected();
     }
 }
Esempio n. 2
0
        private async Task <CommandSendReceipt> SendPackage(bool autoAssignSequenceId)
        {
            try
            {
                _cachedSendPackage.Metadata.PublishTime = (ulong)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

                if (autoAssignSequenceId)
                {
                    _cachedSendPackage.Command.SequenceId  = _sequenceId.Current;
                    _cachedSendPackage.Metadata.SequenceId = _sequenceId.Current;
                }
                else
                {
                    _cachedSendPackage.Command.SequenceId = _cachedSendPackage.Metadata.SequenceId;
                }

                var response = await _connection.Send(_cachedSendPackage);

                response.Expect(BaseCommand.Type.SendReceipt);

                if (autoAssignSequenceId)
                {
                    _sequenceId.Increment();
                }

                return(response.SendReceipt);
            }
            catch (Exception exception)
            {
                if (_faultStrategy.DetermineFaultAction(exception) == FaultAction.Relookup)
                {
                    _proxy.Disconnected();
                }

                throw;
            }
            finally
            {
                if (autoAssignSequenceId)
                {
                    _cachedSendPackage.Metadata.SequenceId = 0; // Reset in case the user reuse the MessageMetadata, but is not explicitly setting the sequenceId
                }
            }
        }
Esempio n. 3
0
        public async Task <IProducerStream> CreateStream(IProducerProxy proxy, CancellationToken cancellationToken)
        {
            var commandProducer = new CommandProducer
            {
                ProducerName = _options.ProducerName,
                Topic        = _options.Topic
            };

            while (true)
            {
                try
                {
                    var connection = await _connectionPool.FindConnectionForTopic(_options.Topic, cancellationToken);

                    var response = await connection.Send(commandProducer, proxy);

                    return(new ProducerStream(response.ProducerId, response.ProducerName, _sequenceId, connection, _faultStrategy, proxy));
                }
                catch (OperationCanceledException)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        throw;
                    }
                    else
                    {
                        await Task.Delay(_faultStrategy.RetryInterval, cancellationToken);
                    }
                }
                catch (Exception exception)
                {
                    switch (_faultStrategy.DetermineFaultAction(exception))
                    {
                    case FaultAction.Relookup:
                    case FaultAction.Retry:
                        await Task.Delay(_faultStrategy.RetryInterval, cancellationToken);

                        continue;
                    }

                    throw;
                }
            }
        }
Esempio n. 4
0
        public async Task <IConsumerStream> CreateStream(IConsumerProxy proxy, CancellationToken cancellationToken)
        {
            while (true)
            {
                try
                {
                    var connection = await _connectionPool.FindConnectionForTopic(_subscribe.Topic, cancellationToken);

                    var response = await connection.Send(_subscribe, proxy);

                    return(new ConsumerStream(response.ConsumerId, _messagePrefetchCount, proxy, connection, _faultStrategy, proxy, _batchHandler));
                }
                catch (OperationCanceledException)
                {
                    if (cancellationToken.IsCancellationRequested)
                    {
                        throw;
                    }
                    else
                    {
                        await Task.Delay(_faultStrategy.RetryInterval, cancellationToken);
                    }
                }
                catch (Exception exception)
                {
                    switch (_faultStrategy.DetermineFaultAction(exception))
                    {
                    case FaultAction.Relookup:
                    case FaultAction.Retry:
                        await Task.Delay(_faultStrategy.RetryInterval, cancellationToken);

                        continue;
                    }

                    throw;
                }
            }
        }
Esempio n. 5
0
        private async Task ExecutorOnException(Exception exception, CancellationToken cancellationToken)
        {
            _throwIfClosedOrFaulted();

            switch (_faultStrategy.DetermineFaultAction(exception))
            {
            case FaultAction.Retry:
                await Task.Delay(_faultStrategy.RetryInterval, cancellationToken);

                break;

            case FaultAction.Relookup:
                await _stateManager.StateChangedTo(ProducerState.Connected, cancellationToken);

                break;

            case FaultAction.Fault:
                HasFaulted(exception);
                break;
            }

            _throwIfClosedOrFaulted();
        }