Esempio n. 1
0
 public ReplyHandlerStep(ConcurrentDictionary <string, TimedMessage> messages, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, TimeSpan replyMaxAge)
 {
     _messages    = messages ?? throw new ArgumentNullException(nameof(messages));
     _log         = rebusLoggerFactory?.GetLogger <ReplyHandlerStep>() ?? throw new ArgumentNullException(nameof(rebusLoggerFactory));
     _cleanupTask = asyncTaskFactory?.Create("CleanupAbandonedRepliesTask", CleanupAbandonedReplies) ?? throw new ArgumentNullException(nameof(asyncTaskFactory));
     _replyMaxAge = replyMaxAge;
 }
Esempio n. 2
0
 /// <summary>
 /// Constructs the periodic background task with the given <paramref name="description"/>, periodically executing the given <paramref name="action"/>,
 /// waiting <see cref="Interval"/> between invocations.
 /// </summary>
 public TimerAsyncTask(string description, Func<Task> action, IRebusLoggerFactory rebusLoggerFactory, bool prettyInsignificant)
 {
     _log = rebusLoggerFactory.GetLogger<TimerAsyncTask>();
     _description = description;
     _action = action;
     _prettyInsignificant = prettyInsignificant;
     Interval = DefaultInterval;
 }
Esempio n. 3
0
 /// <summary>
 /// Constructs the step, using the given transport and settings
 /// </summary>
 public SimpleRetryStrategyStep(SimpleRetryStrategySettings simpleRetryStrategySettings, IRebusLoggerFactory rebusLoggerFactory, IErrorTracker errorTracker, IErrorHandler errorHandler, CancellationToken cancellationToken)
 {
     _simpleRetryStrategySettings = simpleRetryStrategySettings ?? throw new ArgumentNullException(nameof(simpleRetryStrategySettings));
     _errorTracker      = errorTracker ?? throw new ArgumentNullException(nameof(errorTracker));
     _errorHandler      = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler));
     _logger            = rebusLoggerFactory?.GetLogger <SimpleRetryStrategyStep>() ?? throw new ArgumentNullException(nameof(rebusLoggerFactory));
     _cancellationToken = cancellationToken;
 }
Esempio n. 4
0
 /// <summary>
 /// Constructs the step, using the given transport and settings
 /// </summary>
 public ArkRetryStrategyStep(SimpleRetryStrategySettings arkRetryStrategySettings, IRebusLoggerFactory rebusLoggerFactory, IErrorTracker errorTracker, IErrorHandler errorHandler, IFailFastChecker failFastChecker, CancellationToken cancellationToken)
 {
     _arkRetryStrategySettings = arkRetryStrategySettings ?? throw new ArgumentNullException(nameof(arkRetryStrategySettings));
     _errorTracker             = errorTracker ?? throw new ArgumentNullException(nameof(errorTracker));
     _errorHandler             = errorHandler ?? throw new ArgumentNullException(nameof(errorHandler));
     _failFastChecker          = failFastChecker;
     _logger            = rebusLoggerFactory?.GetLogger <ArkRetryStrategyStep>() ?? throw new ArgumentNullException(nameof(rebusLoggerFactory));
     _cancellationToken = cancellationToken;
 }
Esempio n. 5
0
        /// <summary>
        /// Resilient Rebus decorator
        /// </summary>
        /// <param name="bus">The bus to decorate</param>
        /// <param name="policy">Retry policy, if not set default will be ued (10 times 1 second delay)</param>
        /// <param name="logger">Rebus logger</param>
        public TransientFaultBusDecorator(IBus bus, IAsyncPolicy policy = null, IRebusLoggerFactory logger = null)
        {
            this.innerBus = bus;
            Logger        = logger?.GetLogger <TransientFaultBusDecorator>();
            retryPolicy   = policy ?? Policy.Handle <BrokerUnreachableException>().Or <OperationInterruptedException>()
                            .WaitAndRetryAsync(Enumerable.Repeat(TimeSpan.FromSeconds(1), 10),
                                               (exception, delay, retryCount, context) => Logger?.Warn("Bus operation failed", exception));

            MessageContextWrapper = () => MessageContext.Current;
        }
Esempio n. 6
0
        public MainCircuitBreaker(IList <ICircuitBreaker> circuitBreakers, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, Lazy <IBus> bus, CircuitBreakerEvents circuitBreakerEvents, Options options)
        {
            _log                  = rebusLoggerFactory?.GetLogger <MainCircuitBreaker>() ?? throw new ArgumentNullException(nameof(rebusLoggerFactory));
            _circuitBreakers      = circuitBreakers ?? new List <ICircuitBreaker>();
            _bus                  = bus ?? throw new ArgumentNullException(nameof(bus));
            _circuitBreakerEvents = circuitBreakerEvents;
            _options              = options;

            _resetCircuitBreakerTask = asyncTaskFactory.Create(BackgroundTaskName, Reset, prettyInsignificant: true, intervalSeconds: 2);
        }
 /// <summary>
 /// Creates the bucket in Google if it does not exist
 /// </summary>
 /// <param name="client">Google storage client</param>
 /// <param name="loggerFactory">Reference to the logger factory to create the logger</param>
 /// <param name="options">Options to configure the storage bus</param>
 internal static void CreateBucketIfNotExists(StorageClient client, IRebusLoggerFactory loggerFactory, GoogleCloudStorageOptions options)
 {
     if (options.AutoCreateBucket)
     {
         var log = loggerFactory?.GetLogger <GoogleCloudStorageDataBusStorage>() ?? throw new ArgumentNullException(nameof(loggerFactory));
         if (!BucketExists(client, options.BucketName))
         {
             log.Info("Bucket {0} does not exist - will create it now", options.BucketName);
             CreateBucket(client, options.ProjectId, options.BucketName);
         }
     }
 }
 /// <summary>
 /// Creates the data storage
 /// </summary>
 public SqlServerDataBusStorage(IDbConnectionProvider connectionProvider, string tableName, bool ensureTableIsCreated, IRebusLoggerFactory rebusLoggerFactory, int commandTimeout)
 {
     if (tableName == null)
     {
         throw new ArgumentNullException(nameof(tableName));
     }
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _connectionProvider   = connectionProvider ?? throw new ArgumentNullException(nameof(connectionProvider));
     _tableName            = TableName.Parse(tableName);
     _ensureTableIsCreated = ensureTableIsCreated;
     _commandTimeout       = commandTimeout;
     _log = rebusLoggerFactory.GetLogger <SqlServerDataBusStorage>();
 }
Esempio n. 9
0
        /// <summary>
        /// Get the registered implementation of <seealso cref="ISagaTypeNamingStrategy"/> or the default <seealso cref="LegacySagaTypeNamingStrategy"/> if one is not configured
        /// </summary>
        private static ISagaTypeNamingStrategy GetSagaTypeNamingStrategy(IResolutionContext resolutionContext, IRebusLoggerFactory rebusLoggerFactory)
        {
            ISagaTypeNamingStrategy sagaTypeNamingStrategy;

            if (resolutionContext.Has <ISagaTypeNamingStrategy>() == false)
            {
                rebusLoggerFactory.GetLogger <SqlServerSagaStorage>().Debug($"An implementation of {nameof(ISagaTypeNamingStrategy)} was not registered. A default, backward compatible, implementation will be used ({nameof(LegacySagaTypeNamingStrategy)}).");
                sagaTypeNamingStrategy = new LegacySagaTypeNamingStrategy();
            }
            else
            {
                sagaTypeNamingStrategy = resolutionContext.Get <ISagaTypeNamingStrategy>();
            }

            return(sagaTypeNamingStrategy);
        }
Esempio n. 10
0
        /// <summary>
        /// Constructs the bus.
        /// </summary>
        public RebusBus(IWorkerFactory workerFactory, IRouter router, ITransport transport, IPipelineInvoker pipelineInvoker, ISubscriptionStorage subscriptionStorage, Options options, IRebusLoggerFactory rebusLoggerFactory, BusLifetimeEvents busLifetimeEvents, IDataBus dataBus)
        {
            _workerFactory       = workerFactory;
            _router              = router;
            _transport           = transport;
            _pipelineInvoker     = pipelineInvoker;
            _subscriptionStorage = subscriptionStorage;
            _options             = options;
            _busLifetimeEvents   = busLifetimeEvents;
            _dataBus             = dataBus;
            _log = rebusLoggerFactory.GetLogger <RebusBus>();

            var defaultBusName = $"Rebus {Interlocked.Increment(ref _busIdCounter)}";

            _busName = options.OptionalBusName ?? defaultBusName;
        }
        private void BuildInternal(string inputQueueAddress, IRebusLoggerFactory rebusLoggerFactory, int maxMessagesToPrefetch)
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }
            if (maxMessagesToPrefetch <= 0)
            {
                throw new ArgumentException($"Cannot set 'maxMessagesToPrefetch' to {maxMessagesToPrefetch} - it must be at least 1!");
            }

            _maxMessagesToPrefetch = (ushort)maxMessagesToPrefetch;
            _log = rebusLoggerFactory.GetLogger <RabbitMqTransport>();

            Address = inputQueueAddress;
        }
Esempio n. 12
0
 /// <summary>
 /// Constructs a MySql transport.
 /// </summary>
 public MySqlTransport(MySqlConnectionHelper connectionHelper, string tableName, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, IRebusTime rebusTime)
 {
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _connectionHelper = connectionHelper;
     _tableName        = tableName;
     _inputQueueName   = inputQueueName;
     _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory));
     _rebusTime        = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     ExpiredMessagesCleanupInterval = DefaultExpiredMessagesCleanupInterval;
     _expiredMessagesCleanupTask    = asyncTaskFactory.Create("ExpiredMessagesCleanup",
                                                              PerformExpiredMessagesCleanupCycle, intervalSeconds: 60);
     _log = rebusLoggerFactory.GetLogger <MySqlTransport>();
 }
Esempio n. 13
0
 internal ThreadPoolWorker(string name, ITransport transport, IRebusLoggerFactory rebusLoggerFactory, IPipelineInvoker pipelineInvoker, ParallelOperationsManager parallelOperationsManager, RebusBus owningBus, Options options, IBackoffStrategy backoffStrategy)
 {
     Name                       = name;
     _log                       = rebusLoggerFactory.GetLogger <ThreadPoolWorker>();
     _transport                 = transport;
     _pipelineInvoker           = pipelineInvoker;
     _parallelOperationsManager = parallelOperationsManager;
     _owningBus                 = owningBus;
     _options                   = options;
     _backoffStrategy           = backoffStrategy;
     _workerThread              = new Thread(Run)
     {
         Name         = name,
         IsBackground = true
     };
     _workerThread.Start();
 }
    /// <summary>
    /// Constructs the storage using the specified connection provider and table to store its subscriptions. If the subscription
    /// storage is shared by all subscribers and publishers, the <paramref name="isCentralized"/> parameter can be set to true
    /// in order to subscribe/unsubscribe directly instead of sending subscription/unsubscription requests
    /// </summary>
    public SqlServerSubscriptionStorage(IDbConnectionProvider connectionProvider, string tableName, bool isCentralized, IRebusLoggerFactory rebusLoggerFactory)
    {
        _connectionProvider = connectionProvider ?? throw new ArgumentNullException(nameof(connectionProvider));
        if (tableName == null)
        {
            throw new ArgumentNullException(nameof(tableName));
        }
        if (rebusLoggerFactory == null)
        {
            throw new ArgumentNullException(nameof(rebusLoggerFactory));
        }

        IsCentralized = isCentralized;

        _log       = rebusLoggerFactory.GetLogger <SqlServerSubscriptionStorage>();
        _tableName = TableName.Parse(tableName);
    }
Esempio n. 15
0
        /// <summary>
        /// Constructs the bus.
        /// </summary>
        public RebusBus(IWorkersCoordinatorFactory workerFactory, IRouter router, ITransport transport, IPipelineInvoker pipelineInvoker, ISubscriptionStorage subscriptionStorage, Options options, IRebusLoggerFactory rebusLoggerFactory, BusLifetimeEvents busLifetimeEvents, ITopicNameConvention topicNameConvention)
        {
            _workerFactory       = workerFactory;
            _router              = router;
            _transport           = transport;
            _pipelineInvoker     = pipelineInvoker;
            _subscriptionStorage = subscriptionStorage;
            _options             = options;
            _busLifetimeEvents   = busLifetimeEvents;
            _log = rebusLoggerFactory.GetLogger <RebusBus>();
            _topicNameConvention = topicNameConvention;

            var defaultBusName = $"Rebus {Interlocked.Increment(ref _busIdCounter)}";

            _busName = options.OptionalBusName ?? defaultBusName;
            _workers = new Lazy <IWorkersCoordinator>(() => _workerFactory.CreateWorkersCoordinator("RebusBus WorkersCoordinator", 0), true);
        }
Esempio n. 16
0
        public ConnectionManager(string connectionString, string inputQueueAddress, IRebusLoggerFactory rebusLoggerFactory)
        {
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }

            _log = rebusLoggerFactory.GetLogger <ConnectionManager>();

            if (inputQueueAddress != null)
            {
                _log.Info("Initializing RabbitMQ connection manager for transport with input queue '{0}'", inputQueueAddress);
            }
            else
            {
                _log.Info("Initializing RabbitMQ connection manager for one-way transport");
            }

            var uriStrings = connectionString.Split(";,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            if (uriStrings.Length == 0)
            {
                throw new ArgumentException("Please remember to specify at least one connection string for a RabbitMQ server somewhere. You can also add multiple connection strings separated by ; or , which Rebus will use in failover scenarios");
            }

            if (uriStrings.Length > 1)
            {
                _log.Info("RabbitMQ transport has {0} connection strings available", uriStrings.Length);
            }

            _connectionFactory = new ConnectionFactory
            {
                Uri = uriStrings.First(), //Use the first URI in the list for ConnectionFactory to pick the AMQP credentials (if any)
                AutomaticRecoveryEnabled = true,
                NetworkRecoveryInterval  = TimeSpan.FromSeconds(30),
                ClientProperties         = CreateClientProperties(inputQueueAddress)
            };

            _amqpTcpEndpoints = uriStrings
                                .Select(GetAmqpTcpEndpoint)
                                .ToList();
        }
Esempio n. 17
0
        /// <summary>
        /// Constructs the timeout manager, using the specified connection provider and table to store the messages until they're due.
        /// </summary>
        public SqlServerTimeoutManager(IDbConnectionProvider connectionProvider, string tableName, IRebusLoggerFactory rebusLoggerFactory, IRebusTime rebusTime)
        {
            if (tableName == null)
            {
                throw new ArgumentNullException(nameof(tableName));
            }
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }

            _connectionProvider = connectionProvider ?? throw new ArgumentNullException(nameof(connectionProvider));
            _rebusTime          = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));

            _tableName = TableName.Parse(tableName);
            _log       = rebusLoggerFactory.GetLogger <SqlServerTimeoutManager>();
        }
Esempio n. 18
0
        public AutoScaler(ITransport transport, IRebusLoggerFactory rebusLoggerFactory, int maximumNumberOfWorkers, IAsyncTaskFactory asyncTaskFactory, Func <IBus> busFactory, int adjustmentIntervalSeconds)
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }
            if (asyncTaskFactory == null)
            {
                throw new ArgumentNullException(nameof(asyncTaskFactory));
            }

            _logger    = rebusLoggerFactory.GetLogger <AutoScaler>();
            _transport = transport ?? throw new ArgumentNullException(nameof(transport));
            _maximumNumberOfWorkers = maximumNumberOfWorkers;
            _busFactory             = busFactory ?? throw new ArgumentNullException(nameof(busFactory));
            _task = asyncTaskFactory.Create("AutoScale", Tick, intervalSeconds: adjustmentIntervalSeconds);
        }
Esempio n. 19
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="connectionProvider">A <see cref="IDbConnection"/> to obtain a database connection</param>
        /// <param name="inputQueueName">Name of the queue this transport is servicing</param>
        /// <param name="rebusLoggerFactory">A <seealso cref="IRebusLoggerFactory"/> for building loggers</param>
        /// <param name="asyncTaskFactory">A <seealso cref="IAsyncTaskFactory"/> for creating periodic tasks</param>
        /// <param name="rebusTime">A <seealso cref="IRebusTime"/> to provide the current time</param>
        /// <param name="options">Additional options</param>
        public MySqlTransport(
            IDbConnectionProvider connectionProvider,
            string inputQueueName,
            IRebusLoggerFactory rebusLoggerFactory,
            IAsyncTaskFactory asyncTaskFactory,
            IRebusTime rebusTime,
            MySqlTransportOptions options)
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }
            if (asyncTaskFactory == null)
            {
                throw new ArgumentNullException(nameof(asyncTaskFactory));
            }

            _rebusTime          = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
            _connectionProvider = connectionProvider ?? throw new ArgumentNullException(nameof(connectionProvider));
            _receiveTableName   = inputQueueName != null?TableName.Parse(inputQueueName) : null;

            _log = rebusLoggerFactory.GetLogger <MySqlTransport>();

            var cleanupInterval = options.ExpiredMessagesCleanupInterval ?? DefaultExpiredMessagesCleanupInterval;
            var intervalSeconds = (int)cleanupInterval.TotalSeconds;

            _expiredMessagesCleanupTask = asyncTaskFactory.Create("ExpiredMessagesCleanup", PerformExpiredMessagesCleanupCycle, intervalSeconds: intervalSeconds);
            _autoDeleteQueue            = options.AutoDeleteQueue;
            _leasedByFactory            = options.LeasedByFactory ?? (() => Environment.MachineName);
            _leaseInterval          = options.LeaseInterval ?? DefaultLeaseTime;
            _leaseTolerance         = options.LeaseInterval ?? DefaultLeaseTolerance;
            _ensureTablesAreCreated = options.EnsureTablesAreCreated;

            var automaticLeaseRenewalInterval = options.LeaseAutoRenewInterval;

            if (!automaticLeaseRenewalInterval.HasValue)
            {
                _automaticLeaseRenewal = false;
            }
            else
            {
                _automaticLeaseRenewal         = true;
                _automaticLeaseRenewalInterval = automaticLeaseRenewalInterval.Value;
            }
        }
        /// <summary>
        /// Constructs the transport, connecting to the service bus pointed to by the connection string.
        /// </summary>
        public AzureServiceBusTransport(string connectionString, string queueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, INameFormatter nameFormatter, CancellationToken cancellationToken = default(CancellationToken), ITokenProvider tokenProvider = null)
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }
            if (asyncTaskFactory == null)
            {
                throw new ArgumentNullException(nameof(asyncTaskFactory));
            }

            _nameFormatter = nameFormatter;

            if (queueName != null)
            {
                // this never happens
                if (queueName.StartsWith(MagicSubscriptionPrefix))
                {
                    throw new ArgumentException($"Sorry, but the queue name '{queueName}' cannot be used because it conflicts with Rebus' internally used 'magic subscription prefix': '{MagicSubscriptionPrefix}'. ");
                }

                Address           = _nameFormatter.FormatQueueName(queueName);
                _subscriptionName = _nameFormatter.FormatSubscriptionName(queueName);
            }

            _connectionString  = connectionString ?? throw new ArgumentNullException(nameof(connectionString));
            _cancellationToken = cancellationToken;
            _log = rebusLoggerFactory.GetLogger <AzureServiceBusTransport>();

            if (tokenProvider != null)
            {
                var connectionStringBuilder = new ServiceBusConnectionStringBuilder(connectionString);
                _managementClient = new ManagementClient(connectionStringBuilder, tokenProvider);
                _endpoint         = connectionStringBuilder.Endpoint;
                _transportType    = connectionStringBuilder.TransportType;
            }
            else
            {
                _managementClient = new ManagementClient(connectionString);
            }

            _tokenProvider = tokenProvider;

            _messageLockRenewalTask = asyncTaskFactory.Create("Peek Lock Renewal", RenewPeekLocks, prettyInsignificant: true, intervalSeconds: 10);
        }
 /// <summary>
 /// Constructs the step
 /// </summary>
 public IdempotentMessageIncomingStep(ITransport transport, IMessageStorage messageStorage, IRebusLoggerFactory rebusLoggerFactory)
 {
     if (transport == null)
     {
         throw new ArgumentNullException(nameof(transport));
     }
     if (messageStorage == null)
     {
         throw new ArgumentNullException(nameof(messageStorage));
     }
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _transport  = transport;
     _msgStorage = messageStorage;
     _log        = rebusLoggerFactory.GetLogger <IdempotentMessageIncomingStep>();
 }
Esempio n. 22
0
 /// <summary>
 /// Constructs the timeout manager
 /// </summary>
 public MySqlTimeoutManager(MySqlConnectionHelper connectionHelper, string tableName, IRebusLoggerFactory rebusLoggerFactory)
 {
     if (connectionHelper == null)
     {
         throw new ArgumentNullException(nameof(connectionHelper));
     }
     if (tableName == null)
     {
         throw new ArgumentNullException(nameof(tableName));
     }
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _connectionHelper = connectionHelper;
     _tableName        = tableName;
     _log = rebusLoggerFactory.GetLogger <MySqlTimeoutManager>();
 }
 /// <summary>
 /// Constructs the step
 /// </summary>
 public ForwardTransportMessageStep(Func <TransportMessage, Task <ForwardAction> > routingFunction, ITransport transport, IRebusLoggerFactory rebusLoggerFactory)
 {
     if (routingFunction == null)
     {
         throw new ArgumentNullException(nameof(routingFunction));
     }
     if (transport == null)
     {
         throw new ArgumentNullException(nameof(transport));
     }
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _routingFunction = routingFunction;
     _transport       = transport;
     _log             = rebusLoggerFactory.GetLogger <ForwardTransportMessageStep>();
 }
Esempio n. 24
0
 /// <summary>
 /// Creates the error handler
 /// </summary>
 public PoisonQueueErrorHandler(SimpleRetryStrategySettings simpleRetryStrategySettings, ITransport transport, IRebusLoggerFactory rebusLoggerFactory)
 {
     if (simpleRetryStrategySettings == null)
     {
         throw new ArgumentNullException(nameof(simpleRetryStrategySettings));
     }
     if (transport == null)
     {
         throw new ArgumentNullException(nameof(transport));
     }
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _simpleRetryStrategySettings = simpleRetryStrategySettings;
     _transport = transport;
     _log       = rebusLoggerFactory.GetLogger <PoisonQueueErrorHandler>();
 }
Esempio n. 25
0
 public KafkaTransport(
     IRebusLoggerFactory rebusLoggerFactory,
     IAsyncTaskFactory asyncTaskFactory,
     ISerializer customSerializer,
     string brokerList,
     string groupId,
     string topicPrefix)
 {
     _log              = rebusLoggerFactory.GetLogger <KafkaTransport>();
     _brokerList       = brokerList;
     _customSerializer = customSerializer;
     _groupId          = groupId;
     _knownRoutes      = new ConcurrentBag <string>();
     _knownRoutes.Add($"^{topicPrefix}.*");
     _knownRoutes.Add($"{topicPrefix}");
     _topicPrefix      = topicPrefix;
     _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory));
 }
 /// <summary>
 /// Constructs the timeout manager
 /// </summary>
 public MongoDbTimeoutManager(IRebusTime rebusTime, IMongoDatabase database, string collectionName, IRebusLoggerFactory rebusLoggerFactory)
 {
     if (database == null)
     {
         throw new ArgumentNullException(nameof(database));
     }
     if (collectionName == null)
     {
         throw new ArgumentNullException(nameof(collectionName));
     }
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _rebusTime = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     _log       = rebusLoggerFactory.GetLogger <MongoDbTimeoutManager>();
     _timeouts  = database.GetCollection <Timeout>(collectionName);
 }
 /// <summary>
 /// Creates the data bus storage
 /// </summary>
 public AzureBlobsDataBusStorage(CloudStorageAccount storageAccount, string containerName, IRebusLoggerFactory loggerFactory)
 {
     if (storageAccount == null)
     {
         throw new ArgumentNullException(nameof(storageAccount));
     }
     if (containerName == null)
     {
         throw new ArgumentNullException(nameof(containerName));
     }
     if (loggerFactory == null)
     {
         throw new ArgumentNullException(nameof(loggerFactory));
     }
     _containerName = containerName.ToLowerInvariant();
     _client        = storageAccount.CreateCloudBlobClient();
     _log           = loggerFactory.GetLogger <AzureBlobsDataBusStorage>();
 }
        internal KafkaSubscriptionStorage(IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory
                                          , string brokerList, string inputQueueName, string groupId = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrWhiteSpace(brokerList))
            {
                throw new NullReferenceException(nameof(brokerList));
            }
            var maxNameLength = 249;

            if (inputQueueName.Length > maxNameLength && _topicRegex.IsMatch(inputQueueName))
            {
                throw new ArgumentException("Invalid characters or length of a topic (file)", nameof(inputQueueName));
            }
            if (inputQueueName.StartsWith(_magicSubscriptionPrefix))
            {
                throw new ArgumentException($"Sorry, but the queue name '{inputQueueName}' cannot be used because it conflicts with Rebus' internally used 'magic subscription prefix': '{_magicSubscriptionPrefix}'. ");
            }

            _config = new ConsumerConfig
            {
                BootstrapServers    = brokerList,
                ApiVersionRequest   = true,
                GroupId             = !string.IsNullOrEmpty(groupId) ? groupId : Guid.NewGuid().ToString("N"),
                EnableAutoCommit    = false,
                FetchWaitMaxMs      = 5,
                FetchErrorBackoffMs = 5,
                QueuedMinMessages   = 1000,
                SessionTimeoutMs    = 6000,
                //StatisticsIntervalMs = 5000,
#if DEBUG
                TopicMetadataRefreshIntervalMs = 20000,                 // Otherwise it runs maybe five minutes
                Debug = "msg",
#endif
                AutoOffsetReset    = AutoOffsetReset.Latest,
                EnablePartitionEof = true
            };
            _config.Set("fetch.message.max.bytes", "10240");

            _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory));
            _log = rebusLoggerFactory.GetLogger <KafkaSubscriptionStorage>();
            _cancellationToken = cancellationToken;

            _subscriptions.TryAdd(inputQueueName, new[] { inputQueueName });
        }
Esempio n. 29
0
        public TplWorker(string workerName, RebusBus owningBus, ITransport transport,
                         IRebusLoggerFactory rebusLoggerFactory, IPipelineInvoker pipelineInvoker,
                         ParallelOperationsManager parallelOperationsManager, Options options, IBackoffStrategy backoffStrategy,
                         CancellationToken busDisposalCancellationToken)
        {
            _owningBus                 = owningBus;
            _transport                 = transport;
            _pipelineInvoker           = pipelineInvoker;
            _parallelOperationsManager = parallelOperationsManager;
            _options         = options;
            _backoffStrategy = backoffStrategy;
            _busDisposalCancellationToken = busDisposalCancellationToken;
            Name = workerName;

            _cancellationToken = _cancellationTokenSource.Token;
            _log = rebusLoggerFactory.GetLogger <TplWorker>();

            Task.Run(Run);
        }
Esempio n. 30
0
        /// <summary>
        /// Enables message validation for incoming messages using FluentValidation.
        /// <para>
        /// When an incoming message fails to validate, by default it is wrapped in a <see cref="IValidationFailed{TMessage}"/> message and dispatched to handlers implementing this wrapped message type. Use the <paramref name="onFailed"/> builder to configure if messages should be handled differently (f.ex. move to error queue, drop, etc.).
        /// </para>
        /// </summary>
        /// <param name="configurer">The options configurer.</param>
        /// <param name="validatorFactory">The FluentValidation validator factory to resolve message validators from.</param>
        /// <param name="onFailed">A builder to configure how messages should be handled when validation fails.</param>
        public static void ValidateIncomingMessages(this OptionsConfigurer configurer, IValidatorFactory validatorFactory, Action <ValidationConfigurer>?onFailed = null)
        {
            if (configurer is null)
            {
                throw new ArgumentNullException(nameof(configurer));
            }

            if (validatorFactory is null)
            {
                throw new ArgumentNullException(nameof(validatorFactory));
            }

            var opts = new ValidationConfigurer(configurer);

            onFailed?.Invoke(opts);

            configurer.Register(ctx =>
            {
                IRebusLoggerFactory loggerFactory = ctx.Get <IRebusLoggerFactory>();
                return(new ValidateIncomingStep(
                           loggerFactory.GetLogger <ValidateIncomingStep>(),
                           validatorFactory,
                           ctx.Get <IReadOnlyDictionary <Type, IValidationFailedStrategy> >(),
                           // By default, handle as IValidationFailed<>
                           ctx.Get <WrapAsValidationFailed>()
                           ));
            });

            configurer.Decorate <IPipeline>(ctx =>
            {
                IPipeline pipeline   = ctx.Get <IPipeline>();
                var pipelineInjector = new PipelineStepInjector(pipeline);

                ValidateIncomingStep incomingStep = ctx.Get <ValidateIncomingStep>();
                pipelineInjector.OnReceive(
                    incomingStep,
                    PipelineRelativePosition.After,
                    typeof(DeserializeIncomingMessageStep)
                    );

                return(pipelineInjector);
            });
        }
        /// <summary>
        /// Constructs the transport
        /// </summary>
        public AzureStorageQueuesTransport(CloudStorageAccount storageAccount, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory)
        {
            if (storageAccount == null)
            {
                throw new ArgumentNullException(nameof(storageAccount));
            }
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }

            _queueClient = storageAccount.CreateCloudQueueClient();
            _log         = rebusLoggerFactory.GetLogger <AzureStorageQueuesTransport>();

            if (inputQueueName != null)
            {
                _inputQueueName = inputQueueName.ToLowerInvariant();
            }
        }