/// <summary>
 /// Enables the callbacks feature.
 /// </summary>
 /// <param name="config">The endpoint configuration.</param>
 /// <param name="makesRequests">
 /// The value that indicates whether the endpoint can make callback requests. If <c>true</c>, the endpoint must be uniquely
 /// addressable.
 /// </param>
 public static void EnableCallbacks(this EndpointConfiguration config, bool makesRequests = true)
 {
     if (makesRequests)
     {
         config.EnableFeature <CallbackRequestSupport>();
         config.EnableFeature <CallbackReplySupport>();
     }
     else
     {
         config.EnableFeature <CallbackReplySupport>();
     }
 }
Beispiel #2
0
 static AttachmentSettings SetAttachments(EndpointConfiguration configuration, SettingsHolder settings, AttachmentSettings attachments)
 {
     settings.Set(attachments);
     configuration.EnableFeature <AttachmentFeature>();
     configuration.DisableFeature <AttachmentsUsedWhenNotEnabledFeature>();
     return(attachments);
 }
Beispiel #3
0
 public static void EnableTopicExchange(this EndpointConfiguration config, string topicExchange = null)
 {
     if (!string.IsNullOrWhiteSpace(topicExchange))
     {
         config.GetSettings().Set(TopicExchangeClient.TopicExchangeEndpointNameKey, topicExchange);
     }
     config.EnableFeature <TopicExchangeClient>();
 }
Beispiel #4
0
        public static void SerializeOutgoingIntegrationTypes(this EndpointConfiguration configuration,
                                                             Type[] handledTypes)
        {
            var settings = configuration.GetSettings();

            settings.Set(SerializeIntegrationTypeFeature.HandledTypesKey, handledTypes);
            configuration.EnableFeature <SerializeIntegrationTypeFeature>();
        }
 /// <summary>
 /// Sets the ServiceControl queue address.
 /// </summary>
 /// <param name="config">The endpoint's configuration to modify</param>
 /// <param name="serviceControlQueue">ServiceControl queue address.</param>
 /// <param name="customSagaEntitySerialization">A custom strategy for serializing saga state.</param>
 public static void AuditSagaStateChanges(this EndpointConfiguration config, string serviceControlQueue, Func <object, Dictionary <string, string> > customSagaEntitySerialization = null)
 {
     config.EnableFeature <SagaAuditFeature>();
     config.GetSettings().Set(SettingsKeys.SagaAuditQueue, serviceControlQueue);
     if (customSagaEntitySerialization != null)
     {
         config.GetSettings().Set(SettingsKeys.CustomSerialization, customSagaEntitySerialization);
     }
 }
        /// <summary>
        /// Enables the outbox feature.
        /// </summary>
        /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param>
        public static OutboxSettings EnableOutbox(this EndpointConfiguration config)
        {
            Guard.AgainstNull(nameof(config), config);

            var outboxSettings = new OutboxSettings(config.Settings);

            config.EnableFeature <Features.Outbox>();
            return(outboxSettings);
        }
        /// <summary>
        /// Allows the user to control how the gateway behaves.
        /// </summary>
        /// <param name="config">The <see cref="EndpointConfiguration"/> instance to apply the settings to.</param>
        public static GatewaySettings Gateway(this EndpointConfiguration config)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            config.EnableFeature <Features.Gateway>();

            return(new GatewaySettings(config));
        }
        /// <summary>
        /// Enables the outbox feature.
        /// </summary>
        /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param>
        public static OutboxSettings EnableOutbox(this EndpointConfiguration config)
        {
            Guard.AgainstNull(nameof(config), config);

            var outboxSettings = new OutboxSettings(config.Settings);

            config.Settings.SetDefault(TransportTransactionMode.ReceiveOnly);
            config.EnableFeature <Features.Outbox>();
            return(outboxSettings);
        }
        /// <summary>
        /// Allows the user to control how the gateway behaves.
        /// </summary>
        /// <param name="config">The <see cref="EndpointConfiguration"/> instance to apply the settings to.</param>
        /// <param name="storageConfiguration">the storage configuration for the gateway's deduplication mechanism</param>
        public static GatewaySettings Gateway(this EndpointConfiguration config, GatewayDeduplicationConfiguration storageConfiguration)
        {
            Guard.AgainstNull(nameof(config), config);
            Guard.AgainstNull(nameof(storageConfiguration), storageConfiguration);

            config.EnableFeature <Features.Gateway>();

            config.GetSettings().Set(storageConfiguration);

            return(new GatewaySettings(config));
        }
        /// <summary>
        /// Enable Serilog Tracing for this endpoint.
        /// </summary>
        public static SerilogTracingSettings EnableSerilogTracing(this EndpointConfiguration configuration, ILogger logger)
        {
            Guard.AgainstNull(configuration, nameof(configuration));
            Guard.AgainstNull(logger, nameof(logger));
            configuration.Recoverability().AddUnrecoverableException <ConfigurationException>();
            configuration.EnableFeature <TracingFeature>();
            var settings    = configuration.GetSettings();
            var attachments = new SerilogTracingSettings(logger, configuration);

            settings.Set(attachments);
            return(attachments);
        }
Beispiel #11
0
        public static void OnEndpointStarted(this EndpointConfiguration configuration, Func <IMessageSession, Task> onEndpointStarted)
        {
            if (onEndpointStarted == null)
            {
                throw new ArgumentNullException(nameof(onEndpointStarted));
            }

            var settings = configuration.GetSettings();

            settings.Set(NServiceBusExtensionsEndpointStartedSetting, onEndpointStarted);
            configuration.EnableFeature <EndpointStartupCallback>();
        }
        /// <summary>
        /// Configures NServiceBus to use the given data bus definition.
        /// </summary>
        /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param>
        public static DataBusExtensions <T> UseDataBus <T>(this EndpointConfiguration config) where T : DataBusDefinition, new()
        {
            Guard.AgainstNull(nameof(config), config);
            var type       = typeof(DataBusExtensions <>).MakeGenericType(typeof(T));
            var extension  = (DataBusExtensions <T>)Activator.CreateInstance(type, config.Settings);
            var definition = (DataBusDefinition)Activator.CreateInstance(typeof(T));

            config.Settings.Set("SelectedDataBus", definition);

            config.EnableFeature <Features.DataBus>();

            return(extension);
        }
 /// <summary>
 /// Sets the ServiceControl queue address.
 /// </summary>
 /// <param name="config">The enddpoint congfiguration to modify.</param>
 /// <param name="serviceControlQueue">ServiceControl queue address.</param>
 /// <param name="frequency">The frequency to send heartbeats.</param>
 /// <param name="timeToLive">The maximum time to live for the heartbeat.</param>
 public static void SendHeartbeatTo(this EndpointConfiguration config, string serviceControlQueue, TimeSpan?frequency = null, TimeSpan?timeToLive = null)
 {
     config.EnableFeature <HeartbeatsFeature>();
     config.GetSettings().Set("NServiceBus.Heartbeat.Queue", serviceControlQueue);
     if (timeToLive.HasValue)
     {
         config.GetSettings().Set("NServiceBus.Heartbeat.Ttl", timeToLive.Value);
     }
     if (frequency.HasValue)
     {
         config.GetSettings().Set("NServiceBus.Heartbeat.Interval", frequency.Value);
     }
 }
Beispiel #14
0
        /// <summary>
        /// Enable SQL attachments for this endpoint.
        /// </summary>
        public static AttachmentSettings EnableAttachments(
            this EndpointConfiguration configuration,
            Func <Task <SqlConnection> > connectionFactory,
            GetTimeToKeep timeToKeep)
        {
            Guard.AgainstNull(configuration, nameof(configuration));
            Guard.AgainstNull(timeToKeep, nameof(timeToKeep));
            Guard.AgainstNull(connectionFactory, nameof(connectionFactory));
            var settings    = configuration.GetSettings();
            var attachments = new AttachmentSettings(connectionFactory, timeToKeep);

            settings.Set <AttachmentSettings>(attachments);
            configuration.EnableFeature <AttachmentFeature>();
            configuration.DisableFeature <AttachmentsUsedWhenNotEnabledFeature>();
            return(attachments);
        }
Beispiel #15
0
        /// <summary>
        /// If you want full control over the limit and the duration then this overload allows to set any rates.
        ///
        /// Max rate:   5 calls every second:
        ///
        ///     endpointConfiguration.ApplyRateLimiting(5);
        ///
        /// </summary>
        public static void ApplyRateLimiting(this EndpointConfiguration instance, int limitPerSecond)
        {
            if (limitPerSecond < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(limitPerSecond), limitPerSecond, "Must be larger than 0");
            }
            var properties = new global::Properties
            {
                Duration = TimeSpan.FromSeconds(1),
                Limit    = limitPerSecond,
            };
            var settings = instance.GetSettings();

            settings.Set <global::Properties>(properties);
            instance.EnableFeature <RateLimiterFeature>();
        }
Beispiel #16
0
        /// <summary>
        /// Enable SQL attachments for this endpoint.
        /// </summary>
        public static DedupeSettings EnableDedupe(
            this EndpointConfiguration configuration,
            Func <CancellationToken, Task <DbConnection> > connectionBuilder)
        {
            Guard.AgainstNull(configuration, nameof(configuration));
            Guard.AgainstNull(connectionBuilder, nameof(connectionBuilder));
            var recoverability = configuration.Recoverability();

            recoverability.AddUnrecoverableException <NotSupportedException>();
            var settings       = configuration.GetSettings();
            var dedupeSettings = new DedupeSettings(connectionBuilder);

            settings.Set(dedupeSettings);
            configuration.EnableFeature <DeduplicationFeature>();
            return(dedupeSettings);
        }
Beispiel #17
0
        /// <summary>
        /// Enable SQL attachments for this endpoint.
        /// </summary>
        public static AttachmentSettings EnableAttachments(
            this EndpointConfiguration configuration,
            string fileShare,
            GetTimeToKeep timeToKeep)
        {
            Guard.AgainstNull(configuration, nameof(configuration));
            Guard.AgainstNull(timeToKeep, nameof(timeToKeep));
            Guard.AgainstNullOrEmpty(fileShare, nameof(fileShare));
            var settings    = configuration.GetSettings();
            var attachments = new AttachmentSettings(fileShare, timeToKeep);

            settings.Set(attachments);
            configuration.EnableFeature <AttachmentFeature>();
            configuration.DisableFeature <AttachmentsUsedWhenNotEnabledFeature>();
            return(attachments);
        }
        /// <summary>
        /// Configures NServiceBus to use a custom <see cref="IDataBus" /> implementation.
        /// </summary>
        /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param>
        /// <param name="dataBusType">The <see cref="IDataBus" /> <see cref="Type" /> to use.</param>
        public static DataBusExtensions UseDataBus(this EndpointConfiguration config, Type dataBusType)
        {
            Guard.AgainstNull(nameof(config), config);
            Guard.AgainstNull(nameof(dataBusType), dataBusType);

            if (!typeof(IDataBus).IsAssignableFrom(dataBusType))
            {
                throw new ArgumentException("The type needs to implement IDataBus.", nameof(dataBusType));
            }

            config.Settings.Set("SelectedDataBus", new CustomDataBus());
            config.Settings.Set("CustomDataBusType", dataBusType);

            config.EnableFeature <Features.DataBus>();

            return(new DataBusExtensions(config.Settings));
        }
Beispiel #19
0
        /// <summary>
        /// If you want full control over the limit and the duration then this overload allows to set any rates.
        ///
        /// Minute max rates:   100 calls every minute:
        ///
        ///     endpointConfiguration.ApplyRateLimiting(100, TimeSpan.FromMinutes(1));
        ///
        /// </summary>
        public static void ApplyRateLimiting(this EndpointConfiguration instance, int limit, TimeSpan duration)
        {
            if (limit < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(limit), limit, "Must be larger than 0");
            }
            if (duration < MinimumDuration)
            {
                throw new ArgumentOutOfRangeException(nameof(duration), duration, $"Must be larger than {MinimumDuration.TotalMilliseconds}ms.");
            }
            var properties = new global::Properties
            {
                Duration = duration,
                Limit    = limit,
            };
            var settings = instance.GetSettings();

            settings.Set <global::Properties>(properties);
            instance.EnableFeature <RateLimiterFeature>();
        }
Beispiel #20
0
        /// <summary>
        /// Limits the processing rate per second based on <param name="limitPerSecond"/>. It will calculate the smallest interval based on the specified concurrency.
        ///
        /// If you do not want to use the smallest interval but want to allow for burst then set concurrency to the max burst size.
        ///
        /// Smallest interval based on concurrency:
        /// If you allow for 100 messages per second, with a concurrency of 4 then the logic will limit processing of 4 messages every 400 milliseconds.
        ///
        ///     endpointConfiguration.ApplyRateLimiting(limitPerSecond:10, concurrency:4);
        ///
        /// Bursts:
        /// If you allow for burst of 250 items as a rate of 10 messages per second then the logic will limit processing of 250 messages every 25 seconds.
        ///
        ///     endpointConfiguration.ApplyRateLimiting(limitPerSecond:10, concurrency:250);
        /// </summary>
        public static void ApplyRateLimiting(this EndpointConfiguration instance, int limitPerSecond, int burstSize)
        {
            if (limitPerSecond < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(limitPerSecond), limitPerSecond, "Must be larger than 0");
            }
            var properties = new global::Properties
            {
                Duration = TimeSpan.FromSeconds(1.0 / limitPerSecond * burstSize),
                Limit    = burstSize,
            };
            var minimumBurstSize = limitPerSecond / 10D;

            if (burstSize < minimumBurstSize)
            {
                throw new ArgumentOutOfRangeException(nameof(burstSize), burstSize, $"Must be larger than {Math.Ceiling(minimumBurstSize):N0} when {nameof(limitPerSecond)}={limitPerSecond}.");
            }
            var settings = instance.GetSettings();

            settings.Set <global::Properties>(properties);
            instance.EnableFeature <RateLimiterFeature>();
        }
Beispiel #21
0
        public static void RegisterPartitionsForThisEndpoint(this EndpointConfiguration endpointConfiguration,
                                                             string localPartitionKey, string[] allPartitionKeys)
        {
            endpointConfiguration.MakeInstanceUniquelyAddressable(localPartitionKey);

            var settings = endpointConfiguration.GetSettings();

            var endpointName         = settings.EndpointName();
            var distributionStrategy = new PartitionAwareDistributionStrategy(endpointName, _ => localPartitionKey,
                                                                              DistributionStrategyScope.Send);

            var distributionPolicy = settings.GetOrCreate <DistributionPolicy>();

            distributionPolicy.SetDistributionStrategy(distributionStrategy);

            var destinationEndpointInstances =
                allPartitionKeys.Select(key => new EndpointInstance(endpointName, key)).ToList();

            var endpointInstances = settings.GetOrCreate <EndpointInstances>();

            endpointInstances.AddOrReplaceInstances(endpointName, destinationEndpointInstances);

            endpointConfiguration.EnableFeature <HardcodeReplyToAddressToLogicalAddressFeature>();
        }
Beispiel #22
0
 /// <summary>
 /// Enables the given feature.
 /// </summary>
 /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param>
 public static void EnableFeature <T>(this EndpointConfiguration config) where T : Feature
 {
     Guard.AgainstNull(nameof(config), config);
     config.EnableFeature(typeof(T));
 }
 public static void EnableSLAPerformanceCounter(this EndpointConfiguration config)
 {
     Guard.AgainstNull(nameof(config), config);
     config.EnableFeature <SLAMonitoring>();
 }
Beispiel #24
0
 public static void UseAttributeRouting(this EndpointConfiguration endpointConfiguration)
 {
     endpointConfiguration.EnableFeature <AttributeRoutingFeature>();
 }
Beispiel #25
0
        internal DispatchRetriesConfiguration(EndpointConfiguration configuration)
        {
            _configuration = configuration;

            configuration.EnableFeature <DispatchRetriesFeature>();
        }