/// <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; } }
/// <summary> /// Configures Rebus to use SQL Server as its transport in "one-way client mode" (i.e. as a send only endpoint). Unlike the <c>UseSqlServer</c> calls the leased version of the SQL /// Server transport does not hold a transaction open for the entire duration of the message handling. Instead it marks a /// message as being "leased" for a period of time. If the lease has expired then a worker is permitted to acquire the that /// message again and try reprocessing /// </summary> /// <param name="configurer">Static to extend</param> /// <param name="transportOptions">Options controlling the transport setup</param> public static SqlServerLeaseTransportOptions UseSqlServerInLeaseModeAsOneWayClient(this StandardConfigurer <ITransport> configurer, SqlServerLeaseTransportOptions transportOptions) { return(Configure( configurer, (context, provider, inputQueue) => { if (transportOptions.LeasedByFactory == null) { transportOptions.SetLeasedByFactory(() => Environment.MachineName); } return new SqlServerLeaseTransport( provider, transportOptions.InputQueueName, context.Get <IRebusLoggerFactory>(), context.Get <IAsyncTaskFactory>(), context.Get <IRebusTime>(), transportOptions.LeaseInterval ?? SqlServerLeaseTransport.DefaultLeaseTime, transportOptions.LeaseTolerance ?? SqlServerLeaseTransport.DefaultLeaseTolerance, transportOptions.LeasedByFactory, transportOptions ); }, transportOptions ) .AsOneWayClient()); }