/// <summary>
        /// Configures an AzureServiceBus host using a connection string (Endpoint=...., etc).
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
        /// <param name="connectionName">The client-provided connection name.</param>
        /// <param name="connectionString">The connection string in the proper format</param>
        /// <param name="hostConfigurator">The configuration callback to configure the AzureServiceBus.</param>
        public static void UseAzureServiceBus(this IMassTransitBuilder builder, string connectionName, string connectionString, Action <IServiceBusHostBuilder> hostConfigurator = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (connectionString == null)
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            // in case they pass a URI by mistake (it happens)
            if (Uri.TryCreate(connectionString, UriKind.Absolute, out var hostAddress))
            {
                UseAzureServiceBus(builder, connectionName, hostAddress, hostConfigurator);
                return;
            }

            var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
            var hostBuilder      = new ServiceBusHostBuilder(builder.Services, connectionName, namespaceManager.Address);

            hostBuilder.UseTokenProvider(namespaceManager.Settings.TokenProvider);
            hostBuilder.UseOperationTimeout(namespaceManager.Settings.OperationTimeout);

            hostConfigurator?.Invoke(hostBuilder);
        }
 public static IServiceCollection AddMassTransitActivities <TOptions>(this IServiceCollection services,
                                                                      IMassTransitBuilder <TOptions> massTransitBuilder) where TOptions : class
 {
     services.AddMassTransitActivities();
     massTransitBuilder.Build(services);
     return(services);
 }
        /// <summary>
        /// Configures a ActiveMQ bus by using the specified <paramref name="options"/>.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="options"><see cref="ActiveMqOptions"/></param>
        /// <param name="hostConfigurator">The configuration callback to configure the ActiveMQ bus.</param>
        public static void UseActiveMq(this IMassTransitBuilder builder, ActiveMqOptions options, Action <IActiveMqHostBuilder> hostConfigurator = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            UseActiveMq(builder, options.ConnectionName, options.Host, options.Port, hostBuilder =>
            {
                if (options.UseSsl)
                {
                    hostBuilder.UseSsl();
                }

                if (!string.IsNullOrEmpty(options.Username))
                {
                    hostBuilder.UseUsername(options.Username);
                }

                if (!string.IsNullOrEmpty(options.Password))
                {
                    hostBuilder.UsePassword(options.Password);
                }

                hostConfigurator?.Invoke(hostBuilder);
            });
        }
Exemple #4
0
        /// <summary>
        /// Configures a HTTP host using a MassTransit host address.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
        /// <param name="connectionName">The client-provided connection name.</param>
        /// <param name="hostAddress">The address of the HTTP service bus in MassTransit format (http://host:port/).</param>
        /// <param name="method">The HTTP method (i.e. verb) to use, defaults to POST.</param>
        /// <param name="hostConfigurator">The configuration callback to configure the HTTP bus.</param>
        public static void UseHttp(this IMassTransitBuilder builder, string connectionName, Uri hostAddress, HttpMethod method, Action <IHttpHostBuilder> hostConfigurator = null)
        {
            if (hostAddress == null)
            {
                throw new ArgumentNullException(nameof(hostAddress));
            }

            UseHttp(builder, connectionName, hostAddress.Scheme, hostAddress.Host, hostAddress.Port, method, hostConfigurator);
        }
Exemple #5
0
        /// <summary>
        /// Configures a HTTP host by using the specified <paramref name="options"/>.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="options"><see cref="HttpOptions"/></param>
        /// <param name="hostConfigurator">The configuration callback to configure the HTTP bus.</param>
        public static void UseHttp(this IMassTransitBuilder builder, HttpOptions options, Action <IHttpHostBuilder> hostConfigurator = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            var method = HttpHostBuilder.ToHttpMethod(options.Method);

            UseHttp(builder, options.ConnectionName, options.Scheme, options.Host, options.Port, method, hostConfigurator);
        }
        /// <summary>
        /// Configures an InMemory bus by using the specified base address.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="baseAddress">Contains an optional override for the default base address.</param>
        /// <param name="connectionName">The client-provided connection name.</param>
        /// <param name="hostConfigurator">The configuration callback to configure the InMemory bus.</param>
        public static void UseInMemory(this IMassTransitBuilder builder, Uri baseAddress, string connectionName, Action <IInMemoryHostBuilder> hostConfigurator)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            var hostBuilder = new InMemoryHostBuilder(builder.Services, baseAddress, connectionName);

            hostConfigurator?.Invoke(hostBuilder);
        }
        /// <summary>
        /// Configures a ActiveMQ bus by using the specified application configuration.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="configuration">The <see cref="IConfiguration"/> being bound.</param>
        /// <param name="hostConfigurator">The configuration callback to configure the ActiveMQ bus.</param>
        public static void UseActiveMq(this IMassTransitBuilder builder, IConfiguration configuration, Action <IActiveMqHostBuilder> hostConfigurator = null)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            var connectionName = configuration["ConnectionName"];
            var hostBuilder    = new ActiveMqHostBuilder(builder.Services, connectionName, configuration);

            hostConfigurator?.Invoke(hostBuilder);
        }
Exemple #8
0
        /// <summary>
        /// Configures an AzureServiceBus host by using the specified <paramref name="options"/>.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="options"><see cref="ServiceBusOptions"/></param>
        /// <param name="hostConfigurator">The configuration callback to configure the AzureServiceBus.</param>
        public static void UseAzureServiceBus(this IMassTransitBuilder builder, ServiceBusOptions options, Action <IServiceBusHostBuilder> hostConfigurator = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            UseAzureServiceBus(builder, options.ConnectionName, options.HostAddress, hostBuilder =>
            {
                hostBuilder.UseTokenProvider(options.TokenProvider);

                if (options.OperationTimeout.HasValue)
                {
                    hostBuilder.UseOperationTimeout(options.OperationTimeout.Value);
                }

                if (options.RetryMinBackoff.HasValue)
                {
                    hostBuilder.UseRetryMinBackoff(options.RetryMinBackoff.Value);
                }

                if (options.RetryMaxBackoff.HasValue)
                {
                    hostBuilder.UseRetryMaxBackoff(options.RetryMaxBackoff.Value);
                }

                if (options.RetryLimit.HasValue)
                {
                    hostBuilder.UseRetryLimit(options.RetryLimit.Value);
                }

                switch (options.TransportType)
                {
                case TransportType.Amqp:
                    hostBuilder.UseAmqp(options.AmqpTransportSettings);
                    break;

                case TransportType.NetMessaging:
                    hostBuilder.UseNetMessaging(options.NetMessagingTransportSettings);
                    break;
                }

                if (options.BatchFlushInterval.HasValue)
                {
                    hostBuilder.UseBatchFlushInterval(options.BatchFlushInterval.Value);
                }

                hostConfigurator?.Invoke(hostBuilder);
            });
        }
        /// <summary>
        /// Configures a AmazonSQS bus.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
        /// <param name="connectionName">The client-provided connection name.</param>
        /// <param name="region">The AWS region to connect to.</param>
        /// <param name="hostConfigurator">The configuration callback to configure the AmazonSQS bus.</param>
        public static void UseAmazonSqs(this IMassTransitBuilder builder, string connectionName, RegionEndpoint region, Action <IAmazonSqsHostBuilder> hostConfigurator = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (hostConfigurator == null)
            {
                throw new ArgumentNullException(nameof(hostConfigurator));
            }

            var hostBuilder = new AmazonSqsHostBuilder(builder.Services, connectionName, region);

            hostConfigurator.Invoke(hostBuilder);
        }
        /// <summary>
        /// Configures a ActiveMQ bus.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
        /// <param name="connectionName">The client-provided connection name.</param>
        /// <param name="hostAddress">The URI host address of the ActiveMQ host (example: activemq://host:port/).</param>
        /// <param name="hostConfigurator">The configuration callback to configure the ActiveMQ bus.</param>
        public static void UseActiveMq(this IMassTransitBuilder builder, string connectionName, Uri hostAddress, Action <IActiveMqHostBuilder> hostConfigurator = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (hostAddress == null)
            {
                throw new ArgumentNullException(nameof(hostAddress));
            }

            var hostBuilder = new ActiveMqHostBuilder(builder.Services, connectionName, hostAddress);

            hostConfigurator?.Invoke(hostBuilder);
        }
        /// <summary>
        /// Configures a RabbitMq bus by using the specified settings.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="host">The host name of the RabbitMq broker.</param>
        /// <param name="port">The port to connect to on the RabbitMq broker.</param>
        /// <param name="virtualHost">The virtual host to use.</param>
        /// <param name="connectionName">The client-provided connection name.</param>
        /// <param name="hostConfigurator">The configuration callback to configure the RabbitMq bus.</param>
        public static void UseRabbitMq(this IMassTransitBuilder builder, string host, ushort port, string virtualHost, string connectionName, Action <IRabbitMqHostBuilder> hostConfigurator)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }
            if (virtualHost == null)
            {
                throw new ArgumentNullException(nameof(virtualHost));
            }

            var hostBuilder = new RabbitMqHostBuilder(builder.Services, host, port, virtualHost, connectionName);

            hostConfigurator?.Invoke(hostBuilder);
        }
        /// <summary>
        /// Configures a RabbitMq bus by using the specified <paramref name="options"/>.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="options"><see cref="RabbitMqOptions"/></param>
        /// <param name="hostConfigurator">The configuration callback to configure the RabbitMq bus.</param>
        public static void UseRabbitMq(this IMassTransitBuilder builder, RabbitMqOptions options, Action <IRabbitMqHostBuilder> hostConfigurator)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            UseRabbitMq(builder, options.Host, options.Port, options.VirtualHost, options.ConnectionName, hostBuilder =>
            {
                hostBuilder.UseUsername(options.Username);
                hostBuilder.UsePassword(options.Password);

                if (options.Heartbeat.HasValue)
                {
                    hostBuilder.UseHeartbeat(options.Heartbeat.Value);
                }

                hostConfigurator?.Invoke(hostBuilder);
            });
        }
        /// <summary>
        /// Configures an AzureServiceBus host by using the specified <paramref name="options"/>.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="options"><see cref="ServiceBusOptions"/></param>
        /// <param name="hostConfigurator">The configuration callback to configure the AzureServiceBus.</param>
        public static void UseAzureServiceBus(this IMassTransitBuilder builder, ServiceBusOptions options, Action <IServiceBusHostBuilder> hostConfigurator = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            UseAzureServiceBus(builder, options.ConnectionName, options.HostAddress, hostBuilder =>
            {
                hostBuilder.UseTokenProvider(options.TokenProvider);

                if (options.OperationTimeout.HasValue)
                {
                    hostBuilder.UseOperationTimeout(options.OperationTimeout.Value);
                }

                if (options.RetryMinBackoff.HasValue)
                {
                    hostBuilder.UseRetryMinBackoff(options.RetryMinBackoff.Value);
                }

                if (options.RetryMaxBackoff.HasValue)
                {
                    hostBuilder.UseRetryMaxBackoff(options.RetryMaxBackoff.Value);
                }

                if (options.RetryLimit.HasValue)
                {
                    hostBuilder.UseRetryLimit(options.RetryLimit.Value);
                }

                if (options.TransportType.HasValue)
                {
                    hostBuilder.UseTransport(options.TransportType.Value);
                }

                hostConfigurator?.Invoke(hostBuilder);
            });
        }
        /// <summary>
        /// Configures a AmazonSQS bus by using the specified <paramref name="options"/>.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
        /// <param name="options"><see cref="AmazonSqsOptions"/></param>
        /// <param name="hostConfigurator">The configuration callback to configure the AmazonSQS bus.</param>
        public static void UseAmazonSqs(this IMassTransitBuilder builder, AmazonSqsOptions options, Action <IAmazonSqsHostBuilder> hostConfigurator = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            UseAmazonSqs(builder, options.ConnectionName, hostBuilder =>
            {
                if (!string.IsNullOrEmpty(options.RegionSystemName))
                {
                    var region = RegionEndpoint.GetBySystemName(options.RegionSystemName);
                    hostBuilder.UseRegion(region);
                }

                var credentials = options.GetCredentials();
                if (credentials != null)
                {
                    hostBuilder.UseCredentials(credentials);
                }

                if (options.SqsConfig != null)
                {
                    hostBuilder.UseConfig(options.SqsConfig);
                }

                if (options.SnsConfig != null)
                {
                    hostBuilder.UseConfig(options.SnsConfig);
                }

                hostConfigurator?.Invoke(hostBuilder);
            });
        }
Exemple #15
0
        /// <summary>
        /// Configures a HTTP host using a MassTransit host address.
        /// </summary>
        /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
        /// <param name="connectionName">The client-provided connection name.</param>
        /// <param name="scheme">Specifies the HTTP or HTTPS scheme.</param>
        /// <param name="host">The HTTP host to connect to (should be a valid hostname).</param>
        /// <param name="port">The HTTP port to connect to.</param>
        /// <param name="method">The HTTP method (i.e. verb) to use, defaults to POST.</param>
        /// <param name="hostConfigurator">The configuration callback to configure the HTTP bus.</param>
        public static void UseHttp(this IMassTransitBuilder builder, string connectionName, string scheme, string host, int port, HttpMethod method, Action <IHttpHostBuilder> hostConfigurator = null)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }
            if (scheme == null)
            {
                throw new ArgumentNullException(nameof(scheme));
            }
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }

            var hostBuilder = new HttpHostBuilder(builder.Services, connectionName, scheme, host, port);

            if (method != null)
            {
                hostBuilder.UseMethod(method);
            }

            hostConfigurator?.Invoke(hostBuilder);
        }
 /// <summary>
 /// Configures an InMemory bus.
 /// </summary>
 /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
 /// <param name="connectionName">The client-provided connection name.</param>
 /// <param name="hostConfigurator">The configuration callback to configure the InMemory bus.</param>
 public static void UseInMemory(this IMassTransitBuilder builder, string connectionName, Action <IInMemoryHostBuilder> hostConfigurator)
 {
     UseInMemory(builder, null, connectionName, hostConfigurator);
 }
 /// <summary>
 /// Configures a ActiveMQ bus.
 /// </summary>
 /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
 /// <param name="connectionName">The client-provided connection name.</param>
 /// <param name="host">The host name of the ActiveMQ broker.</param>
 /// <param name="hostConfigurator">The configuration callback to configure the ActiveMQ bus.</param>
 public static void UseActiveMq(this IMassTransitBuilder builder, string connectionName, string host, Action <IActiveMqHostBuilder> hostConfigurator = null)
 {
     UseActiveMq(builder, connectionName, host, null, hostConfigurator);
 }
        public static IServiceCollection AddMassTransitSchedulingActivities <TOptions>(this IServiceCollection services,
                                                                                       IMassTransitBuilder <TOptions> massTransitBuilder,
                                                                                       Action <OptionsBuilder <MessageScheduleOptions> > options) where TOptions : class
        {
            var optionsBuilder = services.AddOptions <MessageScheduleOptions>();

            options?.Invoke(optionsBuilder);

            services.AddMassTransitActivities()
            .AddActivity <CancelScheduledMassTransitMessage>()
            .AddActivity <ScheduleSendMassTransitMessage>();

            massTransitBuilder.Build(services);
            return(services);
        }
Exemple #19
0
 /// <summary>
 /// Configures a HTTP host using a MassTransit host address.
 /// </summary>
 /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
 /// <param name="connectionName">The client-provided connection name.</param>
 /// <param name="scheme">Contains either HTTP or HTTPS.</param>
 /// <param name="host">The HTTP host to connect to (should be a valid hostname).</param>
 /// <param name="port">The HTTP port to connect to.</param>
 /// <param name="hostConfigurator">The configuration callback to configure the HTTP bus.</param>
 public static void UseHttp(this IMassTransitBuilder builder, string connectionName, string scheme, string host, int port, Action <IHttpHostBuilder> hostConfigurator = null)
 {
     UseHttp(builder, connectionName, scheme, host, port, null, hostConfigurator);
 }
 /// <summary>
 /// Configures a RabbitMq bus.
 /// </summary>
 /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
 /// <param name="host">The host name of the RabbitMq broker.</param>
 /// <param name="port">The port to connect to on the RabbitMq broker.</param>
 /// <param name="virtualHost">The virtual host to use.</param>
 /// <param name="hostConfigurator">The configuration callback to configure the RabbitMq bus.</param>
 public static void UseRabbitMq(this IMassTransitBuilder builder, string host, ushort port, string virtualHost, Action <IRabbitMqHostBuilder> hostConfigurator)
 {
     UseRabbitMq(builder, host, port, virtualHost, null, hostConfigurator);
 }
 /// <summary>
 /// Configures a RabbitMq bus.
 /// </summary>
 /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
 /// <param name="host">The host name of the RabbitMq broker.</param>
 /// <param name="virtualHost">The virtual host to use.</param>
 /// <param name="connectionName">The client-provided connection name.</param>
 /// <param name="hostConfigurator">The configuration callback to configure the RabbitMq bus.</param>
 public static void UseRabbitMq(this IMassTransitBuilder builder, string host, string virtualHost, string connectionName, Action <IRabbitMqHostBuilder> hostConfigurator)
 {
     UseRabbitMq(builder, host, RabbitMqOptions.DefaultPort, virtualHost, connectionName, hostConfigurator);
 }
 /// <summary>
 /// Configures a RabbitMq bus.
 /// </summary>
 /// <param name="builder"><see cref="IMassTransitBuilder"/></param>
 /// <param name="hostAddress">The URI host address of the RabbitMQ host (example: rabbitmq://host:port/vhost).</param>
 /// <param name="hostConfigurator">The configuration callback to configure the RabbitMq bus.</param>
 public static void UseRabbitMq(this IMassTransitBuilder builder, Uri hostAddress, Action <IRabbitMqHostBuilder> hostConfigurator)
 {
     UseRabbitMq(builder, hostAddress, null, hostConfigurator);
 }
 /// <summary>
 /// Configures an InMemory bus by using the specified base address.
 /// </summary>
 /// <param name="builder"><see cref="IMassTransitBuilder"/></param>.
 /// <param name="baseAddress">Contains an optional override for the default base address.</param>
 /// <param name="hostConfigurator">The configuration callback to configure the InMemory bus.</param>
 public static void UseInMemory(this IMassTransitBuilder builder, Uri baseAddress, Action <IInMemoryHostBuilder> hostConfigurator)
 {
     UseInMemory(builder, baseAddress, null, hostConfigurator);
 }