/// <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, AzureServiceBusNameHelper azureServiceBusNameHelper, CancellationToken cancellationToken = default(CancellationToken)) { if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } _azureServiceBusNameHelper = azureServiceBusNameHelper; 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 = _azureServiceBusNameHelper.ReplaceInvalidCharacters(queueName); _azureServiceBusNameHelper.EnsureIsValidQueueName(Address); } _connectionString = connectionString ?? throw new ArgumentNullException(nameof(connectionString)); _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory)); _cancellationToken = cancellationToken; _log = rebusLoggerFactory.GetLogger <AzureServiceBusTransport>(); _managementClient = new ManagementClient(connectionString); _receiveTimeout = _connectionString.Contains("OperationTimeout") ? default(TimeSpan?) : TimeSpan.FromSeconds(5); }
public void Setup() { rebusLoggerFactory = new ConsoleLoggerFactory(false); taskFactory = new SystemThreadingTimerAsyncTaskFactory(rebusLoggerFactory); circuitBreakerEvents = new CircuitBreakerEvents(); fakeBus = new Lazy <IBus>(new FakeBus()); }
public DacPacDeployer(ILog log, IBuildServerResolver buildServerResolver, IOptions <Arguments> arguments, IAsyncTaskFactory <DacPacDeployAsyncTask> dacPacDeployAsyncTaskFactory) { _log = log; _buildServerResolver = buildServerResolver; _dacPacDeployAsyncTaskFactory = dacPacDeployAsyncTaskFactory; _arguments = arguments.Value; }
/// <summary> /// Constructs the transport with the specified settings /// </summary> public AmazonSqsTransport(string inputQueueAddress, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, AmazonSQSTransportOptions options, IRebusTime rebusTime) { if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } _options = options ?? throw new ArgumentNullException(nameof(options)); _rebusTime = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime)); _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory)); _log = rebusLoggerFactory.GetLogger <AmazonSqsTransport>(); if (inputQueueAddress != null) { if (inputQueueAddress.Contains("/") && !Uri.IsWellFormedUriString(inputQueueAddress, UriKind.Absolute)) { var message = $"The input queue address '{inputQueueAddress}' is not valid - please either use a simple queue name (eg. 'my-queue') or a full URL for the queue endpoint (e.g. 'https://sqs.eu-central-1.amazonaws.com/234234234234234/somqueue')."; throw new ArgumentException(message, nameof(inputQueueAddress)); } } Address = inputQueueAddress; _log.Info("Initializing SQS client"); _client = _options.ClientFactory(); }
/// <summary>Creates new instance <see cref="KafkaTransport"/>. Allows you to configure /// all the parameters of the producer and the consumer used in this transport.</summary> /// <param name="rebusLoggerFactory"></param> /// <param name="asyncTaskFactory"></param> /// <param name="brokerList">Initial list of brokers as a CSV list of broker host or host:port.</param> /// <param name="inputQueueName">name of input queue</param> /// <param name="producerConfig">A collection of librdkafka configuration parameters /// (refer to https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md) /// and parameters specific to this client (refer to: /// <see cref="T:Confluent.Kafka.ConfigPropertyNames" />). /// At a minimum, 'bootstrap.servers' must be specified.</param> /// <param name="consumerConfig">A collection of librdkafka configuration parameters /// (refer to https://github.com/edenhill/librdkafka/blob/master/CONFIGURATION.md) /// and parameters specific to this client (refer to: /// <see cref="T:Confluent.Kafka.ConfigPropertyNames" />). /// At a minimum, 'bootstrap.servers' and 'group.id' must be /// specified.</param> /// <param name="cancellationToken"></param> public KafkaTransport(IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, string brokerList, string inputQueueName , ProducerConfig producerConfig, ConsumerConfig consumerConfig, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(brokerList)) { throw new NullReferenceException(nameof(brokerList)); } _producerConfig = producerConfig ?? throw new NullReferenceException(nameof(producerConfig)); _producerConfig.BootstrapServers = brokerList; if (consumerConfig != null) { var maxNameLength = 249; if (inputQueueName.Length > maxNameLength && _topicRegex.IsMatch(inputQueueName)) { throw new ArgumentException("Недопустимые символы или длинна топика (файла)", nameof(inputQueueName)); } Address = inputQueueName; _queueSubscriptionStorage = new KafkaSubscriptionStorage(rebusLoggerFactory, asyncTaskFactory, brokerList , inputQueueName, consumerConfig, cancellationToken); } _log = rebusLoggerFactory.GetLogger <KafkaTransport>(); _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory)); _cancellationToken = cancellationToken; }
/// <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)) { if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } _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)); _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory)); _cancellationToken = cancellationToken; _log = rebusLoggerFactory.GetLogger <AzureServiceBusTransport>(); _managementClient = new ManagementClient(connectionString); }
/// <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="leaseInterval">Interval of time messages are leased for</param> /// <param name="leaseTolerance">Buffer to allow lease overruns by</param> /// <param name="leasedByFactory">Factory for generating a string which identifies who has leased a message (eg. A hostname)</param> /// <param name="options">Additional options</param> public SqlServerLeaseTransport( IDbConnectionProvider connectionProvider, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, IRebusTime rebusTime, TimeSpan leaseInterval, TimeSpan?leaseTolerance, Func <string> leasedByFactory, SqlServerLeaseTransportOptions options ) : base(connectionProvider, inputQueueName, rebusLoggerFactory, asyncTaskFactory, rebusTime, options) { _leasedByFactory = leasedByFactory; _leaseInterval = leaseInterval; _leaseTolerance = leaseTolerance ?? TimeSpan.FromSeconds(15); var automaticLeaseRenewalInterval = options.LeaseAutoRenewInterval; if (!automaticLeaseRenewalInterval.HasValue) { _automaticLeaseRenewal = false; } else { _automaticLeaseRenewal = true; _automaticLeaseRenewalInterval = automaticLeaseRenewalInterval.Value; } }
internal KafkaSubscriptionStorage(IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, string brokerList , string inputQueueName, ConsumerConfig config, 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 = config ?? throw new NullReferenceException(nameof(config)); _config.BootstrapServers = brokerList; if (string.IsNullOrEmpty(_config.GroupId)) { _config.GroupId = Guid.NewGuid().ToString("N"); } _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory)); _log = rebusLoggerFactory.GetLogger <KafkaSubscriptionStorage>(); _cancellationToken = cancellationToken; _subscriptions.TryAdd(inputQueueName, new[] { inputQueueName }); }
/// <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="leaseInterval">Interval of time messages are leased for</param> /// <param name="leaseTolerance">Buffer to allow lease overruns by</param> /// <param name="leasedByFactory">Factory for generating a string which identifies who has leased a message (eg. A hostname)</param> /// <param name="automaticLeaseRenewalInterval">If non-<c>null</c> messages will be automatically re-leased after this time period has elapsed</param> public SqlServerLeaseTransport( IDbConnectionProvider connectionProvider, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, IRebusTime rebusTime, TimeSpan leaseInterval, TimeSpan?leaseTolerance, Func <string> leasedByFactory, TimeSpan?automaticLeaseRenewalInterval = null ) : base(connectionProvider, inputQueueName, rebusLoggerFactory, asyncTaskFactory, rebusTime) { _leasedByFactory = leasedByFactory; _leaseIntervalMilliseconds = (long)Math.Ceiling(leaseInterval.TotalMilliseconds); _leaseToleranceMilliseconds = (long)Math.Ceiling((leaseTolerance ?? TimeSpan.FromSeconds(15)).TotalMilliseconds); if (automaticLeaseRenewalInterval.HasValue == false) { _automaticLeaseRenewal = false; } else { _automaticLeaseRenewal = true; _automaticLeaseRenewalIntervalMilliseconds = (long)Math.Ceiling(automaticLeaseRenewalInterval.Value.TotalMilliseconds); } }
/// <summary> /// Constructs the transport with the specified settings /// </summary> public AmazonSQSTransport(string inputQueueAddress, AWSCredentials credentials, AmazonSQSConfig amazonSqsConfig, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, AmazonSQSTransportOptions options = null) { if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } _log = rebusLoggerFactory.GetLogger <AmazonSQSTransport>(); if (inputQueueAddress != null) { if (inputQueueAddress.Contains("/") && !Uri.IsWellFormedUriString(inputQueueAddress, UriKind.Absolute)) { var message = $"The input queue address '{inputQueueAddress}' is not valid - please either use a simple queue name (eg. 'my-queue') or a full URL for the queue endpoint (e.g. 'https://sqs.eu-central-1.amazonaws.com/234234234234234/somqueue')."; throw new ArgumentException(message, nameof(inputQueueAddress)); } } Address = inputQueueAddress; _credentials = credentials ?? throw new ArgumentNullException(nameof(credentials)); _amazonSqsConfig = amazonSqsConfig ?? throw new ArgumentNullException(nameof(amazonSqsConfig)); _asyncTaskFactory = asyncTaskFactory; _options = options ?? new AmazonSQSTransportOptions(); }
/// <summary> /// Constructor /// </summary> /// <param name="connectionProvider">A <see cref="IDbConnection"/> to obtain a database connection</param> /// <param name="lockTableName">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 MySqlExclusiveAccessLock( IDbConnectionProvider connectionProvider, string lockTableName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, IRebusTime rebusTime, MySqlExclusiveAccessLockOptions 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)); _lockTableName = lockTableName != null?TableName.Parse(lockTableName) : null; _log = rebusLoggerFactory.GetLogger <MySqlExclusiveAccessLock>(); _lockExpirationTimeout = options.LockExpirationTimeout ?? DefaultLockExpirationTimeout; var cleanupInterval = options.ExpiredLocksCleanupInterval ?? DefaultExpiredLocksCleanupInterval; var intervalSeconds = (int)cleanupInterval.TotalSeconds; _expiredLocksCleanupTask = asyncTaskFactory.Create("ExpiredLocksCleanup", PerformExpiredLocksCleanupCycle, intervalSeconds: intervalSeconds); _autoDeleteTable = options.AutoDeleteTable; }
public ReplyHandlerStep(ConcurrentDictionary<string, TimedMessage> messages, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, TimeSpan replyMaxAge) { _messages = messages; _replyMaxAge = replyMaxAge; _log = rebusLoggerFactory.GetCurrentClassLogger(); _cleanupTask = asyncTaskFactory.Create("CleanupAbandonedRepliesTask", CleanupAbandonedReplies); }
/// <summary> /// Constructs the transport, connecting to the service bus pointed to by the connection string. /// </summary> public AzureServiceBusTransport(string connectionString, string inputQueueAddress, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { if (connectionString == null) { throw new ArgumentNullException(nameof(connectionString)); } if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } if (asyncTaskFactory == null) { throw new ArgumentNullException(nameof(asyncTaskFactory)); } _log = rebusLoggerFactory.GetLogger <AzureServiceBusTransport>(); _namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); _connectionString = connectionString; _asyncTaskFactory = asyncTaskFactory; if (inputQueueAddress != null) { _inputQueueAddress = inputQueueAddress.ToLowerInvariant(); } // if a timeout has been specified, we respect that - otherwise, we pick a sensible default: _receiveTimeout = _connectionString.Contains("OperationTimeout") ? default(TimeSpan?) : TimeSpan.FromSeconds(5); }
/// <summary> /// Constructs the transport with the specified settings /// </summary> public AmazonSqsTransport(string inputQueueAddress, string accessKeyId, string secretAccessKey, AmazonSQSConfig amazonSqsConfig, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { if (accessKeyId == null) throw new ArgumentNullException(nameof(accessKeyId)); if (secretAccessKey == null) throw new ArgumentNullException(nameof(secretAccessKey)); if (amazonSqsConfig == null) throw new ArgumentNullException(nameof(amazonSqsConfig)); if (rebusLoggerFactory == null) throw new ArgumentNullException(nameof(rebusLoggerFactory)); Address = inputQueueAddress; _log = rebusLoggerFactory.GetCurrentClassLogger(); if (Address != null) { if (Address.Contains("/") && !Uri.IsWellFormedUriString(Address, UriKind.Absolute)) { throw new ArgumentException( "You could either have a simple queue name without slash (eg. \"inputqueue\") - or a complete URL for the queue endpoint. (eg. \"https://sqs.eu-central-1.amazonaws.com/234234234234234/somqueue\")", nameof(inputQueueAddress)); } } _accessKeyId = accessKeyId; _secretAccessKey = secretAccessKey; _amazonSqsConfig = amazonSqsConfig; _asyncTaskFactory = asyncTaskFactory; }
/// <summary> /// Constructs the in-mem error tracker with the configured number of delivery attempts as the MAX /// </summary> public InMemErrorTracker(int maxDeliveryAttempts, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { if (rebusLoggerFactory == null) throw new ArgumentNullException(nameof(rebusLoggerFactory)); if (asyncTaskFactory == null) throw new ArgumentNullException(nameof(asyncTaskFactory)); _maxDeliveryAttempts = maxDeliveryAttempts; _log = rebusLoggerFactory.GetCurrentClassLogger(); _cleanupOldTrackedErrorsTask = asyncTaskFactory.Create(BackgroundTaskName, CleanupOldTrackedErrors, intervalSeconds: 60); }
/// <summary> /// Constructs the step, using the specified <see cref="ITimeoutManager"/> to defer relevant messages /// and the specified <see cref="ITransport"/> to deliver messages when they're due. /// </summary> public HandleDeferredMessagesStep(ITimeoutManager timeoutManager, ITransport transport, Options options, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { _timeoutManager = timeoutManager; _transport = transport; _options = options; _log = rebusLoggerFactory.GetCurrentClassLogger(); _dueMessagesSenderBackgroundTask = asyncTaskFactory.Create(DueMessagesSenderTaskName, TimerElapsed, intervalSeconds: 1); }
/// <summary> /// Constructs the transport with the given <see cref="IDbConnectionProvider"/>, using the specified <paramref name="tableName"/> to send/receive messages, /// querying for messages with recipient = <paramref name="inputQueueName"/> /// </summary> public SqlServerTransport(IDbConnectionProvider connectionProvider, string tableName, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { _connectionProvider = connectionProvider; _tableName = tableName; _inputQueueName = inputQueueName; _log = rebusLoggerFactory.GetCurrentClassLogger(); ExpiredMessagesCleanupInterval = DefaultExpiredMessagesCleanupInterval; _expiredMessagesCleanupTask = asyncTaskFactory.Create("ExpiredMessagesCleanup", PerformExpiredMessagesCleanupCycle, intervalSeconds: 60); }
/// <summary> /// Constructs a MySql transport. /// </summary> /// <param name="connectionHelper"></param> /// <param name="tableName">The name of the table used as the transport.</param> /// <param name="inputQueueName">The name of the queue on which messages are received.</param> /// <param name="rebusLoggerFactory"></param> /// <param name="asyncTaskFactory"></param> public MySqlTransport(MySqlConnectionHelper connectionHelper, string tableName, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { _connectionHelper = connectionHelper; _tableName = tableName; _inputQueueName = inputQueueName; _asyncTaskFactory = asyncTaskFactory; ExpiredMessagesCleanupInterval = DefaultExpiredMessagesCleanupInterval; _expiredMessagesCleanupTask = asyncTaskFactory.Create("ExpiredMessagesCleanup", PerformExpiredMessagesCleanupCycle, intervalSeconds: 60); _log = rebusLoggerFactory.GetLogger <MySqlTransport>(); }
/// <summary> /// Constructs the transport, connecting to the service bus pointed to by the connection string. /// </summary> public BasicAzureServiceBusTransport(string connectionString, string inputQueueAddress, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { if (connectionString == null) throw new ArgumentNullException("connectionString"); _namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); _connectionString = connectionString; _rebusLoggerFactory = rebusLoggerFactory; _asyncTaskFactory = asyncTaskFactory; _log = rebusLoggerFactory.GetCurrentClassLogger(); if (inputQueueAddress != null) { _inputQueueAddress = inputQueueAddress.ToLowerInvariant(); } }
/// <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>(); }
/// <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 BasicAzureServiceBusTransport(string connectionString, string inputQueueAddress, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } _namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); _connectionString = connectionString; _rebusLoggerFactory = rebusLoggerFactory; _asyncTaskFactory = asyncTaskFactory; _log = rebusLoggerFactory.GetCurrentClassLogger(); if (inputQueueAddress != null) { _inputQueueAddress = inputQueueAddress.ToLowerInvariant(); } }
/// <summary> /// Constructs the step, using the specified <see cref="ITimeoutManager"/> to defer relevant messages /// and the specified <see cref="ITransport"/> to deliver messages when they're due. /// </summary> public HandleDeferredMessagesStep(ITimeoutManager timeoutManager, ITransport transport, Options options, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { if (timeoutManager == null) throw new ArgumentNullException(nameof(timeoutManager)); if (transport == null) throw new ArgumentNullException(nameof(transport)); if (options == null) throw new ArgumentNullException(nameof(options)); if (rebusLoggerFactory == null) throw new ArgumentNullException(nameof(rebusLoggerFactory)); if (asyncTaskFactory == null) throw new ArgumentNullException(nameof(asyncTaskFactory)); _timeoutManager = timeoutManager; _transport = transport; _options = options; _log = rebusLoggerFactory.GetCurrentClassLogger(); var dueTimeoutsPollIntervalSeconds = (int)options.DueTimeoutsPollInterval.TotalSeconds; var intervalToUse = dueTimeoutsPollIntervalSeconds >= 1 ? dueTimeoutsPollIntervalSeconds : 1; _dueMessagesSenderBackgroundTask = asyncTaskFactory.Create(DueMessagesSenderTaskName, TimerElapsed, intervalSeconds: intervalToUse); }
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)); }
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 }); }
/// <summary> /// Constructs the transport, connecting to the service bus pointed to by the connection string. /// </summary> public AzureServiceBusTransport(string connectionString, string inputQueueAddress, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, BusLifetimeEvents busLifetimeEvents) { if (connectionString == null) throw new ArgumentNullException(nameof(connectionString)); _namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); _connectionString = connectionString; _asyncTaskFactory = asyncTaskFactory; _log = rebusLoggerFactory.GetCurrentClassLogger(); if (inputQueueAddress != null) { _inputQueueAddress = inputQueueAddress.ToLowerInvariant(); } // if a timeout has been specified, we respect that - otherwise, we pick a sensible default: _receiveTimeout = _connectionString.Contains("OperationTimeout") ? default(TimeSpan?) : TimeSpan.FromSeconds(5); }
public KafkaTransport(IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, string brokerList, string inputQueueName, string groupId = null) { var maxNameLength = 249; if (inputQueueName.Length > maxNameLength && _topicRegex.IsMatch(inputQueueName)) { throw new ArgumentException("Недопустимые символы или длинна топика (файла)", 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}'. "); } _knownRoutes = new ConcurrentDictionary <string, string>(); _knownRoutes.TryAdd(inputQueueName, inputQueueName); Address = inputQueueName; _brokerList = brokerList; _groupId = groupId; _log = rebusLoggerFactory.GetLogger <KafkaTransport>(); _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory)); }
/// <summary>Creates new instance <see cref="KafkaTransport"/>. Performs a simplified /// configuration of the parameters of the manufacturer and the consumer used in this transport.</summary> /// <param name="rebusLoggerFactory"></param> /// <param name="asyncTaskFactory"></param> /// <param name="brokerList">Initial list of brokers as a CSV list of broker host or host:port.</param> /// <param name="inputQueueName">name of input queue</param> /// <param name="groupId">Id of group</param> /// <param name="cancellationToken"></param> public KafkaTransport(IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, string brokerList , string inputQueueName, string groupId = null, CancellationToken cancellationToken = default(CancellationToken)) { if (string.IsNullOrWhiteSpace(brokerList)) { throw new NullReferenceException(nameof(brokerList)); } _producerConfig = new ProducerConfig { BootstrapServers = brokerList, ApiVersionRequest = true, QueueBufferingMaxKbytes = 10240, //{ "socket.blocking.max.ms", 1 }, // **DEPRECATED * *No longer used. #if DEBUG Debug = "msg", #endif MessageTimeoutMs = 3000, }; _producerConfig.Set("request.required.acks", "-1"); _producerConfig.Set("queue.buffering.max.ms", "5"); if (!string.IsNullOrWhiteSpace(inputQueueName)) { var maxNameLength = 249; if (inputQueueName.Length > maxNameLength && _topicRegex.IsMatch(inputQueueName)) { throw new ArgumentException("Недопустимые символы или длинна топика (файла)", nameof(inputQueueName)); } Address = inputQueueName; _queueSubscriptionStorage = new KafkaSubscriptionStorage(rebusLoggerFactory, asyncTaskFactory, brokerList , inputQueueName, groupId, cancellationToken); } _log = rebusLoggerFactory.GetLogger <KafkaTransport>(); _asyncTaskFactory = asyncTaskFactory ?? throw new ArgumentNullException(nameof(asyncTaskFactory)); _cancellationToken = cancellationToken; }
/// <summary> /// Constructs the transport with the specified settings /// </summary> public AmazonSqsTransport(string inputQueueAddress, string accessKeyId, string secretAccessKey, AmazonSQSConfig amazonSqsConfig, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { if (accessKeyId == null) { throw new ArgumentNullException(nameof(accessKeyId)); } if (secretAccessKey == null) { throw new ArgumentNullException(nameof(secretAccessKey)); } if (amazonSqsConfig == null) { throw new ArgumentNullException(nameof(amazonSqsConfig)); } if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } Address = inputQueueAddress; _log = rebusLoggerFactory.GetCurrentClassLogger(); if (Address != null) { if (Address.Contains("/") && !Uri.IsWellFormedUriString(Address, UriKind.Absolute)) { throw new ArgumentException( "You could either have a simple queue name without slash (eg. \"inputqueue\") - or a complete URL for the queue endpoint. (eg. \"https://sqs.eu-central-1.amazonaws.com/234234234234234/somqueue\")", nameof(inputQueueAddress)); } } _accessKeyId = accessKeyId; _secretAccessKey = secretAccessKey; _amazonSqsConfig = amazonSqsConfig; _asyncTaskFactory = asyncTaskFactory; }
/// <summary> /// Constructs the transport with the specified settings /// </summary> public AmazonSqsTransport(string inputQueueAddress, AWSCredentials credentials, AmazonSQSConfig amazonSqsConfig, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, AmazonSQSTransportOptions options = null) { if (credentials == null) { throw new ArgumentNullException(nameof(credentials)); } if (amazonSqsConfig == null) { throw new ArgumentNullException(nameof(amazonSqsConfig)); } if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } Address = inputQueueAddress; _log = rebusLoggerFactory.GetLogger <AmazonSqsTransport>(); if (Address != null) { if (Address.Contains("/") && !Uri.IsWellFormedUriString(Address, UriKind.Absolute)) { throw new ArgumentException( "You could either have a simple queue name without slash (eg. \"inputqueue\") - or a complete URL for the queue endpoint. (eg. \"https://sqs.eu-central-1.amazonaws.com/234234234234234/somqueue\")", nameof(inputQueueAddress)); } } _credentials = credentials; _amazonSqsConfig = amazonSqsConfig; _asyncTaskFactory = asyncTaskFactory; _serializer = new AmazonSqsTransportMessageSerializer(); _transportOptions = options ?? new AmazonSQSTransportOptions(); }
/// <summary> /// Constructs the in-mem error tracker with the configured number of delivery attempts as the MAX /// </summary> public InMemErrorTracker(int maxDeliveryAttempts, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { _maxDeliveryAttempts = maxDeliveryAttempts; _log = rebusLoggerFactory.GetCurrentClassLogger(); _cleanupOldTrackedErrorsTask = asyncTaskFactory.Create(BackgroundTaskName, CleanupOldTrackedErrors, intervalSeconds: 60); }
/// <summary> /// Constructs the transport with the given <see cref="IDbConnectionProvider"/> /// </summary> 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; }
/// <summary> /// Constructs the transport with the specified settings /// </summary> public AmazonSqsTransport(string inputQueueAddress, string accessKeyId, string secretAccessKey, AmazonSQSConfig amazonSqsConfig, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, AmazonSQSTransportOptions options = null) : this(inputQueueAddress, Credentials(accessKeyId, secretAccessKey), amazonSqsConfig, rebusLoggerFactory, asyncTaskFactory, options) { }
/// <summary> /// Constructs the transport with the given <see cref="IDbConnectionProvider"/>, using the specified <paramref name="tableName"/> to send/receive messages, /// querying for messages with recipient = <paramref name="inputQueueName"/> /// </summary> public SqlServerTransport(IDbConnectionProvider connectionProvider, string tableName, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { if (connectionProvider == null) { throw new ArgumentNullException(nameof(connectionProvider)); } if (tableName == null) { throw new ArgumentNullException(nameof(tableName)); } if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } if (asyncTaskFactory == null) { throw new ArgumentNullException(nameof(asyncTaskFactory)); } ConnectionProvider = connectionProvider; TableName = TableName.Parse(tableName); InputQueueName = inputQueueName; _log = rebusLoggerFactory.GetLogger <SqlServerTransport>(); ExpiredMessagesCleanupInterval = DefaultExpiredMessagesCleanupInterval; _expiredMessagesCleanupTask = asyncTaskFactory.Create("ExpiredMessagesCleanup", PerformExpiredMessagesCleanupCycle, intervalSeconds: 60); }
/// <summary> /// Constructs the step, using the specified <see cref="ITimeoutManager"/> to defer relevant messages /// and the specified <see cref="ITransport"/> to deliver messages when they're due. /// </summary> public HandleDeferredMessagesStep(ITimeoutManager timeoutManager, ITransport transport, Options options, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { if (rebusLoggerFactory == null) { throw new ArgumentNullException(nameof(rebusLoggerFactory)); } if (asyncTaskFactory == null) { throw new ArgumentNullException(nameof(asyncTaskFactory)); } _timeoutManager = timeoutManager ?? throw new ArgumentNullException(nameof(timeoutManager)); _transport = transport ?? throw new ArgumentNullException(nameof(transport)); _options = options ?? throw new ArgumentNullException(nameof(options)); _log = rebusLoggerFactory.GetLogger <HandleDeferredMessagesStep>(); var dueTimeoutsPollIntervalSeconds = (int)options.DueTimeoutsPollInterval.TotalSeconds; var intervalToUse = dueTimeoutsPollIntervalSeconds >= 1 ? dueTimeoutsPollIntervalSeconds : 1; _dueMessagesSenderBackgroundTask = asyncTaskFactory.Create(DueMessagesSenderTaskName, TimerElapsed, intervalSeconds: intervalToUse); }
public AmazonInternalSettings(ConsoleLoggerFactory consoleLoggerFactory = null, TplAsyncTaskFactory tplAsyncTaskFactory = null, IAmazonCredentialsFactory amazonCredentialsFactory = null) : this() { m_RebusLoggerFactory = consoleLoggerFactory; m_AsyncTaskFactory = tplAsyncTaskFactory; m_AmazonCredentialsFactory = amazonCredentialsFactory; }
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); }
/// <summary> /// Constructs the step, using the specified <see cref="ITimeoutManager"/> to defer relevant messages /// and the specified <see cref="ITransport"/> to deliver messages when they're due. /// </summary> public HandleDeferredMessagesStep(ITimeoutManager timeoutManager, ITransport transport, Options options, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory) { _timeoutManager = timeoutManager; _transport = transport; _options = options; _log = rebusLoggerFactory.GetCurrentClassLogger(); var dueTimeoutsPollIntervalSeconds = (int)options.DueTimeoutsPollInterval.TotalSeconds; var intervalToUse = dueTimeoutsPollIntervalSeconds >= 1 ? dueTimeoutsPollIntervalSeconds : 1; _dueMessagesSenderBackgroundTask = asyncTaskFactory.Create(DueMessagesSenderTaskName, TimerElapsed, intervalSeconds: intervalToUse); }