示例#1
0
 /// <summary>
 /// Constructs the step, getting the input queue address from the given <see cref="ITransport"/>
 /// </summary>
 public AssignDefaultHeadersStep(ITransport transport, IRebusTime rebusTime, string defaultReturnAddressOrNull)
 {
     _rebusTime     = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     _senderAddress = transport.Address;
     _returnAddress = defaultReturnAddressOrNull ?? transport.Address;
     _hasOwnAddress = !string.IsNullOrWhiteSpace(_senderAddress);
 }
示例#2
0
 /// <summary>
 /// Creates the transport using the given <paramref name="baseDirectory"/> to store messages in the form of JSON files
 /// </summary>
 public FileSystemTransport(string baseDirectory, string inputQueueName, FileSystemTransportOptions options, IRebusTime rebusTime)
 {
     _baseDirectory = baseDirectory ?? throw new ArgumentNullException(nameof(baseDirectory));
     _options       = options ?? throw new ArgumentNullException(nameof(options));
     _rebusTime     = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     Address        = inputQueueName;
 }
        /// <summary>
        /// Constructs the transport using a <see cref="CloudStorageAccount"/>
        /// </summary>
        public GooglePubSubTransport(CloudStorageAccount storageAccount, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, GooglePubSubTransportOptions options, IRebusTime rebusTime)
        {
            if (storageAccount == null)
            {
                throw new ArgumentNullException(nameof(storageAccount));
            }
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }

            _options   = options;
            _rebusTime = rebusTime;
            _log       = rebusLoggerFactory.GetLogger <GooglePubSubTransport>();
            _initialVisibilityDelay = options.InitialVisibilityDelay;

            var queueClient = storageAccount.CreateCloudQueueClient();

            _queueFactory = new CloudQueueClientQueueFactory(queueClient);

            if (inputQueueName != null)
            {
                if (!Regex.IsMatch(inputQueueName, QueueNameValidationRegex))
                {
                    throw new ArgumentException($"The inputQueueName {inputQueueName} is not valid - it can contain only alphanumeric characters and hyphens, and must not have 2 consecutive hyphens.", nameof(inputQueueName));
                }
                Address = inputQueueName.ToLowerInvariant();
            }
        }
 /// <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);
     }
 }
示例#5
0
 public SqsAmazonSendMessageProcessor(string destinationAddress, IAmazonInternalSettings amazonInternalSettings, AmazonSQSQueueContext amazonSqsQueueContext, IRebusTime rebusTime)
 {
     this._destinationAddress     = destinationAddress;
     this._amazonInternalSettings = amazonInternalSettings;
     this._amazonSqsQueueContext  = amazonSqsQueueContext;
     this._rebusTime = rebusTime;
 }
示例#6
0
        /// <summary> </summary>
        /// <param name="connectionHelper"></param>
        /// <param name="tableName"></param>
        /// <param name="inputQueueName"></param>
        /// <param name="rebusLoggerFactory"></param>
        /// <param name="asyncTaskFactory"></param>
        /// <param name="rebusTime"></param>
        public OracleTransport(OracleFactory connectionHelper, string tableName, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, IRebusTime rebusTime)
        {
            if (rebusLoggerFactory == null)
            {
                throw new ArgumentNullException(nameof(rebusLoggerFactory));
            }
            if (asyncTaskFactory == null)
            {
                throw new ArgumentNullException(nameof(asyncTaskFactory));
            }
            if (tableName == null)
            {
                throw new ArgumentNullException(nameof(tableName));
            }

            _log       = rebusLoggerFactory.GetLogger <OracleTransport>();
            _rebusTime = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
            _factory   = connectionHelper ?? throw new ArgumentNullException(nameof(connectionHelper));
            _table     = new DbName(tableName);
            _sendSql   = SendCommand.Sql(_table);

            // One-way clients don't have an input queue to receive from or cleanup
            if (inputQueueName != null)
            {
                Address     = inputQueueName;
                _receiveSql = BuildReceiveSql();
                _expiredSql = BuildExpiredSql();
                _expiredMessagesCleanupTask = asyncTaskFactory.Create("ExpiredMessagesCleanup", PerformExpiredMessagesCleanupCycle, intervalSeconds: 60);
            }
        }
示例#7
0
            public ErrorTracking AddError(IRebusTime rebusTime, Exception caughtException, bool final)
            {
                //// don't change anymore if this one is already final
                //if (Final) return this;

                return(new ErrorTracking(rebusTime, _caughtExceptions.Concat(new[] { new CaughtException(_rebusTime.Now, caughtException) }), final));
            }
示例#8
0
    /// <summary>
    /// Constructs the transport with the given <see cref="IDbConnectionProvider"/>
    /// </summary>
    public SqlServerTransport(IDbConnectionProvider connectionProvider, string inputQueueName, IRebusLoggerFactory rebusLoggerFactory, IAsyncTaskFactory asyncTaskFactory, IRebusTime rebusTime, SqlServerTransportOptions 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 <SqlServerTransport>();

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

        _expiredMessagesCleanupTask = asyncTaskFactory.Create("ExpiredMessagesCleanup", PerformExpiredMessagesCleanupCycle, intervalSeconds: intervalSeconds);
        _autoDeleteQueue            = options.AutoDeleteQueue;

        _nativeTimeoutManagerDisabled = options.NativeTimeoutManagerDisabled;
    }
        /// <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;
        }
示例#10
0
 /// <summary>
 /// Creates the timeout manager, storing timeouts in the given <paramref name="basePath"/>
 /// </summary>
 public FileSystemTimeoutManager(string basePath, IRebusLoggerFactory rebusLoggerFactory, IRebusTime rebusTime)
 {
     _basePath  = basePath ?? throw new ArgumentNullException(nameof(basePath));
     _rebusTime = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     _lockFile  = Path.Combine(basePath, "lock.txt");
     _log       = rebusLoggerFactory.GetLogger <FileSystemTimeoutManager>();
 }
        /// <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();
        }
示例#12
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="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;
            }
        }
 public AmazonRecieveMessage(IAmazonInternalSettings amazonInternalSettings, AmazonSQSQueueContext amazonSQSQueueContext, IAmazonMessageProcessorFactory amazonMessageProcessorFactory, IRebusTime rebusTime)
 {
     _amazonMessageProcessorFactory = amazonMessageProcessorFactory;
     m_amazonInternalSettings       = amazonInternalSettings ?? throw new ArgumentNullException(nameof(amazonInternalSettings));
     m_amazonSqsQueueContext        = amazonSQSQueueContext ?? throw new ArgumentNullException(nameof(amazonSQSQueueContext));
     m_log      = m_amazonInternalSettings.RebusLoggerFactory.GetLogger <AmazonRecieveMessage>();
     _rebusTime = rebusTime;
 }
示例#14
0
 /// <summary>
 /// Creates the data storage
 /// </summary>
 public FileSystemDataBusStorage(string directoryPath, IRebusLoggerFactory rebusLoggerFactory, IRebusTime rebusTime)
 {
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _directoryPath = directoryPath ?? throw new ArgumentNullException(nameof(directoryPath));
     _rebusTime     = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     _log           = rebusLoggerFactory.GetLogger <FileSystemDataBusStorage>();
 }
        public ExceptionTypeCircuitBreaker(Type exceptionType, CircuitBreakerSettings settings, IRebusTime rebusTime)
        {
            this.exceptionType = exceptionType ?? throw new ArgumentNullException(nameof(exceptionType));
            this.settings      = settings ?? throw new ArgumentNullException(nameof(settings));
            this.rebusTime     = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));

            State = CircuitBreakerState.Closed;

            _errorDates = new ConcurrentDictionary <long, DateTimeOffset>();
        }
示例#16
0
 /// <summary>
 /// Creates the timeout manager, using the given document store to store <see cref="Timeout"/> documents
 /// </summary>
 public RavenDbTimeoutManager(IDocumentStore documentStore, IRebusLoggerFactory rebusLoggerFactory, IRebusTime rebusTime)
 {
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _documentStore = documentStore ?? throw new ArgumentNullException(nameof(documentStore));
     _rebusTime     = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     _log           = rebusLoggerFactory.GetLogger <RavenDbTimeoutManager>();
 }
        public static bool MessageIsExpired(this TransportMessage message, IRebusTime rebusTime, Message sqsMessage)
        {
            if (message.Headers.TryGetValue(Headers.TimeToBeReceived, out var value) == false)
            {
                return(false);
            }

            var timeToBeReceived = TimeSpan.Parse(value, CultureInfo.InvariantCulture);

            return(MessageIsExpiredUsingRebusSentTime(message, rebusTime, timeToBeReceived) || MessageIsExpiredUsingNativeSqsSentTimestamp(sqsMessage, rebusTime, timeToBeReceived));
        }
示例#18
0
        /// <summary>
        /// Establishes a fake presence of a configured data bus, using the given <see cref="InMemDataStore"/> to retrieve data
        /// </summary>
        public static IDisposable EstablishContext(InMemDataStore dataStore, IRebusTime rebusTime)
        {
            if (dataStore == null)
            {
                throw new ArgumentNullException(nameof(dataStore));
            }

            TestBackdoor.EnableTestMode(new InMemDataBusStorage(dataStore, rebusTime));

            return(new CleanUp(TestBackdoor.Reset));
        }
示例#19
0
 /// <summary>
 /// Constructs the timeout manager
 /// </summary>
 public MySqlTimeoutManager(MySqlConnectionHelper connectionHelper, string tableName, IRebusLoggerFactory rebusLoggerFactory, IRebusTime rebusTime)
 {
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _connectionHelper = connectionHelper ?? throw new ArgumentNullException(nameof(connectionHelper));
     _tableName        = tableName ?? throw new ArgumentNullException(nameof(tableName));
     _rebusTime        = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     _log = rebusLoggerFactory.GetLogger <MySqlTimeoutManager>();
 }
 /// <summary>
 /// Constructs the timeout manager
 /// </summary>
 public OracleTimeoutManager(OracleFactory connectionHelper, string tableName, IRebusLoggerFactory rebusLoggerFactory, IRebusTime rebusTime)
 {
     if (rebusLoggerFactory == null)
     {
         throw new ArgumentNullException(nameof(rebusLoggerFactory));
     }
     _connectionHelper = connectionHelper ?? throw new ArgumentNullException(nameof(connectionHelper));
     _table            = new DbName(tableName) ?? throw new ArgumentNullException(nameof(tableName));
     _log       = rebusLoggerFactory.GetLogger <OracleTimeoutManager>();
     _rebusTime = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
 }
        /// <summary>
        /// Constructor for the Google Cloud Storage data bus
        /// </summary>
        /// <param name="storageClient">Reference to the single instance of Google StorageClient</param>
        /// <param name="loggerFactory">Reference to the logger factory to create the logger</param>
        /// <param name="rebusTime">Reference to the rebus time interface for getting the current time</param>
        /// <param name="options">Options to configure the storage bus</param>
        public GoogleCloudStorageDataBusStorage(StorageClient storageClient, IRebusLoggerFactory loggerFactory, IRebusTime rebusTime, GoogleCloudStorageDataBusOptions options)
        {
            _rebusTime     = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
            _options       = options ?? throw new ArgumentNullException(nameof(options));
            _storageClient = storageClient ?? throw new ArgumentNullException(nameof(storageClient));

            // Auto create the bucket when we start up, if required
            CloudUtils.CreateBucketIfNotExists(storageClient, loggerFactory, options);

            // Create our retry policy with Polly with a exponential back off strategy for retries, with jitter and retrying immediately on the first failure
            _retry = CloudUtils.CreateRetryPolicy(options);
        }
示例#22
0
 /// <summary>
 /// Creates the data bus storage
 /// </summary>
 public AzureBlobsDataBusStorage(IRebusLoggerFactory loggerFactory, IRebusTime rebusTime, AzureBlobsDataBusStorageOptions options, CloudBlobContainer cloudBlobContainer)
 {
     if (loggerFactory == null)
     {
         throw new ArgumentNullException(nameof(loggerFactory));
     }
     _rebusTime     = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     _options       = options ?? throw new ArgumentNullException(nameof(options));
     _container     = cloudBlobContainer ?? throw new ArgumentNullException(nameof(cloudBlobContainer));
     _containerName = cloudBlobContainer.Name;
     _log           = loggerFactory.GetLogger <AzureBlobsDataBusStorage>();
 }
示例#23
0
        /// <summary>
        /// Constructs the file system transport to create "queues" as subdirectories of the specified base directory.
        /// While it is apparent that <seealso cref="_baseDirectory"/> must be a valid directory name, please note that
        /// <seealso cref="_inputQueue"/> must not contain any invalid path either.
        /// </summary>
        public FileSystemTransport(IRebusTime rebusTime, string baseDirectory, string inputQueue)
        {
            _rebusTime     = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
            _baseDirectory = baseDirectory;

            if (inputQueue == null)
            {
                return;
            }

            EnsureQueueNameIsValid(inputQueue);

            _inputQueue = inputQueue;
        }
示例#24
0
 /// <summary>
 /// Creates the fake data bus, optionally using the given in-mem data store to store attachments
 /// </summary>
 public FakeDataBus(IRebusTime rebusTime)
 {
     // if there is an "ambient" storage, use that
     if (TestBackdoor.TestDataBusStorage != null)
     {
         _dataBusStorage = TestBackdoor.TestDataBusStorage;
     }
     // last resort: just fake it in mem
     else
     {
         _inMemDataStore = new InMemDataStore();
         _dataBusStorage = new InMemDataBusStorage(_inMemDataStore, rebusTime);
     }
 }
示例#25
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>();
 }
 /// <summary>
 /// Creates the data storage
 /// </summary>
 public SqlServerDataBusStorage(IDbConnectionProvider connectionProvider, string tableName, bool ensureTableIsCreated, IRebusLoggerFactory rebusLoggerFactory, IRebusTime rebusTime, 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;
     _rebusTime            = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
     _log = rebusLoggerFactory.GetLogger <SqlServerDataBusStorage>();
 }
示例#27
0
        /// <summary>
        /// Creates the storage using the given Mongo database
        /// </summary>
        public MongoDbDataBusStorage(IRebusTime rebusTime, IMongoDatabase database, string bucketName)
        {
            if (string.IsNullOrWhiteSpace(bucketName))
            {
                throw new ArgumentException("Please pass a valid MongoDB GridFS bucket name", nameof(bucketName));
            }
            _rebusTime = rebusTime ?? throw new ArgumentNullException(nameof(rebusTime));
            _database  = database ?? throw new ArgumentNullException(nameof(database));

            _bucketName = bucketName;
            _bucket     = new GridFSBucket(_database, new GridFSBucketOptions
            {
                BucketName     = _bucketName,
                WriteConcern   = WriteConcern.Acknowledged,
                ReadPreference = ReadPreference.SecondaryPreferred,
            });
        }
示例#28
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>();
        }
示例#29
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;
            }
        }
示例#30
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, ITopicNameConvention topicNameConvention, IRebusTime rebusTime)
        {
            _workerFactory       = workerFactory;
            _router              = router;
            _transport           = transport;
            _pipelineInvoker     = pipelineInvoker;
            _subscriptionStorage = subscriptionStorage;
            _options             = options;
            _busLifetimeEvents   = busLifetimeEvents;
            _dataBus             = dataBus;
            _log = rebusLoggerFactory.GetLogger <RebusBus>();
            _topicNameConvention = topicNameConvention;
            _rebusTime           = rebusTime;

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

            _busName = options.OptionalBusName ?? defaultBusName;
        }