コード例 #1
0
 private Task<IConnection> CreateConnection(CancellationToken cancellationToken)
 {
     var ctx = new Context();
     ctx.SetRetryCount(0);
     return _connectionRetryPolicy.ExecuteAsync((context, ct) =>
     {
         var endpoint = GetCurrentEndpoint(context);
         var connectionBuilder = new ConnectionBuilder(_loggerFactory, _messageIdPolicyFactory);
         return connectionBuilder.CreateAsync(endpoint, ct);
     }, ctx, cancellationToken);
 }
コード例 #2
0
        public async Task <IConnection> CreateAsync(IEnumerable <Endpoint> endpoints, CancellationToken cancellationToken)
        {
            var endpointsList = endpoints.ToList();

            if (!endpointsList.Any())
            {
                throw new CreateConnectionException("No endpoints provided.");
            }

            if (AutomaticRecoveryEnabled)
            {
                var autoRecoveringConnection = new AutoRecoveringConnection(LoggerFactory, endpointsList, RecoveryPolicy, MessageIdPolicyFactory);
                await autoRecoveringConnection.InitAsync(cancellationToken).ConfigureAwait(false);

                return(autoRecoveringConnection);
            }
            else
            {
                var connectionBuilder = new ConnectionBuilder(LoggerFactory, MessageIdPolicyFactory);
                return(await connectionBuilder.CreateAsync(endpointsList.First(), cancellationToken).ConfigureAwait(false));
            }
        }