public static Uri UseInMemoryScheduler(this IBusFactoryConfigurator configurator, string queueName = "quartz") { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } ISchedulerFactory schedulerFactory = new StdSchedulerFactory(); var scheduler = TaskUtil.Await(() => schedulerFactory.GetScheduler()); Uri inputAddress = null; configurator.ReceiveEndpoint(queueName, e => { var partitioner = configurator.CreatePartitioner(16); e.Consumer(() => new ScheduleMessageConsumer(scheduler), x => x.Message <ScheduleMessage>(m => m.UsePartitioner(partitioner, p => p.Message.CorrelationId))); e.Consumer(() => new CancelScheduledMessageConsumer(scheduler), x => x.Message <CancelScheduledMessage>(m => m.UsePartitioner(partitioner, p => p.Message.TokenId))); configurator.UseMessageScheduler(e.InputAddress); var observer = new SchedulerBusObserver(scheduler, e.InputAddress); configurator.ConnectBusObserver(observer); inputAddress = e.InputAddress; }); return(inputAddress); }
public static void AddScheduling(this IBusFactoryConfigurator configurator, Action <InMemorySchedulerOptions> configure) { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } var options = new InMemorySchedulerOptions(); configure?.Invoke(options); if (options.SchedulerFactory == null) { throw new ArgumentNullException(nameof(options.SchedulerFactory)); } Uri inputAddress = null; var observer = new SchedulerBusObserver(options); configurator.ReceiveEndpoint(options.QueueName, e => { var partitioner = configurator.CreatePartitioner(Environment.ProcessorCount); e.Consumer(() => new ScheduleMessageConsumer(observer.Scheduler), x => x.Message <ScheduleMessage>(m => m.UsePartitioner(partitioner, p => p.Message.CorrelationId))); e.Consumer(() => new CancelScheduledMessageConsumer(observer.Scheduler), x => x.Message <CancelScheduledMessage>(m => m.UsePartitioner(partitioner, p => p.Message.TokenId))); configurator.UseMessageScheduler(e.InputAddress); configurator.ConnectBusObserver(observer); }); }
public static void ConfigureTurnoutEndpoints <T>(this IReceiveEndpointConfigurator configurator, IBusFactoryConfigurator busFactoryConfigurator, IReceiveEndpointConfigurator turnoutEndpointConfigurator, IReceiveEndpointConfigurator expiredEndpointConfigurator, Action <ITurnoutServiceConfigurator <T> > configure) where T : class { configurator.AddDependency(turnoutEndpointConfigurator); turnoutEndpointConfigurator.AddDependency(expiredEndpointConfigurator); var specification = new TurnoutServiceSpecification <T>(configurator); configure(specification); specification.ManagementAddress = turnoutEndpointConfigurator.InputAddress; var partitioner = busFactoryConfigurator.CreatePartitioner(specification.PartitionCount); expiredEndpointConfigurator.Consumer(() => new JobCustodian <T>(specification.JobRegistry), x => { x.Message <SuperviseJob <T> >(m => m.UsePartitioner(partitioner, p => p.Message.JobId)); }); turnoutEndpointConfigurator.Consumer(() => new JobSupervisor <T>(specification.Service, specification.JobRegistry), x => { x.Message <CancelJob>(m => m.UsePartitioner(partitioner, p => p.Message.JobId)); x.Message <SuperviseJob <T> >(m => m.UsePartitioner(partitioner, p => p.Message.JobId)); }); IJobFactory <T> jobFactory = specification.JobFactory; configurator.Consumer(() => new JobProducer <T>(specification.Service, jobFactory)); busFactoryConfigurator.ConnectBusObserver(new JobServiceBusObserver(specification.Service)); }
/// <summary> /// Connects a receive endpoint observer to the bus, that will be resolved from the container /// </summary> /// <param name="configurator">The bus configurator</param> /// <param name="provider">Typically use <see cref="IBusRegistrationContext"/> here when configuring the bus</param> /// <typeparam name="T">The observer type</typeparam> /// <returns>The observer connect handle (likely ignored)</returns> public static ConnectHandle ConnectReceiveEndpointObserver <T>(this IBusFactoryConfigurator configurator, IConfigurationServiceProvider provider) where T : class, IReceiveEndpointObserver { var observer = new ConnectReceiveEndpointObserverBusObserver <T>(provider); return(configurator.ConnectBusObserver(observer)); }
public static void UseHangfireScheduler(this IBusFactoryConfigurator configurator, IHangfireComponentResolver hangfireComponentResolver, string queueName = "hangfire", Action <BackgroundJobServerOptions> configureServer = null) { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } if (hangfireComponentResolver == null) { throw new ArgumentNullException(nameof(hangfireComponentResolver)); } configurator.ReceiveEndpoint(queueName, e => { var partitioner = configurator.CreatePartitioner(Environment.ProcessorCount); e.Consumer(() => new ScheduleMessageConsumer(hangfireComponentResolver), x => { x.Message <ScheduleMessage>(m => m.UsePartitioner(partitioner, p => p.Message.CorrelationId)); x.Message <CancelScheduledMessage>(m => m.UsePartitioner(partitioner, p => p.Message.TokenId)); }); e.Consumer(() => new ScheduleRecurringMessageConsumer(hangfireComponentResolver)); var observer = new SchedulerBusObserver(hangfireComponentResolver, e.InputAddress, configureServer); configurator.ConnectBusObserver(observer); configurator.UseMessageScheduler(e.InputAddress); }); }
/// <summary> /// Applies the configuration to the bus. /// </summary> /// <param name="busName"></param> /// <param name="configurator"></param> public void Apply(string busName, IBusFactoryConfigurator configurator) { foreach (var observer in observers) { if (observer != null) { configurator.ConnectBusObserver(observer); } } }
public static void EnableWindowsPerformanceCounters(this IBusFactoryConfigurator configurator) { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } var observer = new PerformanceCounterBusObserver(new WindowsCounterFactory()); configurator.ConnectBusObserver(observer); }
public static void AddJsonQueueTableSqlServerGateway(this IBusFactoryConfigurator configurator, string tableName, Func <SqlConnection> connectionFactory, TimeSpan pollingInterval) { var poller = new SqlServerMessageTablePoller(tableName, connectionFactory, new QueueJsonTableMessageFactory(tableName, connectionFactory)); configurator.ConnectBusObserver(new BusObserver(poller, pollingInterval)); }
public void ConfigureBus <TEndpointConfigurator>(IBusFactoryConfigurator <TEndpointConfigurator> configurator, IBusRegistrationContext context) where TEndpointConfigurator : IReceiveEndpointConfigurator { var options = context.GetRequiredService <QuartzConfiguration>(); var schedulerAddress = new Uri($"queue:{options.Queue}"); _logger.LogInformation("Configuring Quartz: {SchedulerAddress}", schedulerAddress); configurator.ConnectBusObserver(context.GetRequiredService <SchedulerBusObserver>()); }
public static void EnableStatsdPerformanceCounters(this IBusFactoryConfigurator configurator, Action <StatsDConfiguration> action) { var statsDConfiguration = StatsDConfiguration.Defaults(); action(statsDConfiguration); if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } var observer = new PerformanceCounterBusObserver(new StatsDCounterFactory(statsDConfiguration)); configurator.ConnectBusObserver(observer); }
public static void UseRetry(this IBusFactoryConfigurator configurator, Action <IRetryConfigurator> configure) { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } var observer = new RetryBusObserver(); configurator.ConnectBusObserver(observer); var specification = new ConsumeContextRetryPipeSpecification(observer.Stopping); configure?.Invoke(specification); configurator.AddPipeSpecification(specification); }
/// <summary> /// Configures the message retry for the consumer consumer, regardless of message type. /// </summary> /// <param name="configurator"></param> /// <param name="busFactoryConfigurator"> /// The bus factory configurator, to connect the observer, to cancel retries if the bus is stopped /// </param> /// <param name="configure"></param> public static void UseMessageRetry <TConsumer>(this IConsumerConfigurator <TConsumer> configurator, IBusFactoryConfigurator busFactoryConfigurator, Action <IRetryConfigurator> configure) where TConsumer : class { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } var retryObserver = new RetryBusObserver(); busFactoryConfigurator.ConnectBusObserver(retryObserver); var observer = new MessageRetryConsumerConfigurationObserver <TConsumer>(configurator, retryObserver.Stopping, configure); configurator.ConnectConsumerConfigurationObserver(observer); }
/// <summary> /// Configure the bus to capture metrics for publication using Prometheus. /// </summary> /// <param name="configurator"></param> /// <param name="configureOptions"></param> /// <param name="serviceName"> /// The service name for metrics reporting, defaults to the current process main module filename /// </param> public static void UsePrometheusMetrics(this IBusFactoryConfigurator configurator, Action <PrometheusMetricsOptions> configureOptions = null, string serviceName = default) { var options = PrometheusMetricsOptions.CreateDefault(); configureOptions?.Invoke(options); PrometheusMetrics.TryConfigure(GetServiceName(serviceName), options); configurator.ConnectConsumerConfigurationObserver(new PrometheusConsumerConfigurationObserver()); configurator.ConnectHandlerConfigurationObserver(new PrometheusHandlerConfigurationObserver()); configurator.ConnectSagaConfigurationObserver(new PrometheusSagaConfigurationObserver()); configurator.ConnectActivityConfigurationObserver(new PrometheusActivityConfigurationObserver()); configurator.ConnectEndpointConfigurationObserver(new PrometheusReceiveEndpointConfiguratorObserver()); configurator.ConnectBusObserver(new PrometheusBusObserver()); }
public static void UseRetry <TSaga>(this IPipeConfigurator <SagaConsumeContext <TSaga> > configurator, IBusFactoryConfigurator connector, Action <IRetryConfigurator> configure) where TSaga : class, ISaga { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } var observer = new RetryBusObserver(); connector.ConnectBusObserver(observer); var specification = new ConsumeContextRetryPipeSpecification <SagaConsumeContext <TSaga>, RetrySagaConsumeContext <TSaga> >(Factory, observer.Stopping); configure?.Invoke(specification); configurator.AddPipeSpecification(specification); }
/// <summary> /// For all configured messages type (handlers, consumers, and sagas), configures message retry using the retry configuration specified. /// Retry is configured once for each message type, and is added prior to the consumer factory or saga repository in the pipeline. /// </summary> /// <param name="configurator"></param> /// <param name="connector">The bus factory configurator, to connect the observer, to cancel retries if the bus is stopped</param> /// <param name="configureRetry"></param> public static void UseMessageRetry(this IConsumePipeConfigurator configurator, IBusFactoryConfigurator connector, Action <IRetryConfigurator> configureRetry) { if (configurator == null) { throw new ArgumentNullException(nameof(configurator)); } if (configureRetry == null) { throw new ArgumentNullException(nameof(configureRetry)); } var retryObserver = new RetryBusObserver(); connector.ConnectBusObserver(retryObserver); var observer = new RetryConfigurationObserver(configurator, retryObserver.Stopping, configureRetry); }
/// <summary> /// Enable the loading of message data for the any message type that includes a MessageData property. /// </summary> /// <param name="configurator">The bus factory configurator.</param> /// <param name="selector"> /// The repository selector. /// See extension methods, e.g. <see cref="MessageDataRepositorySelectorExtensions.FileSystem" />. /// </param> public static IMessageDataRepository UseMessageData(this IBusFactoryConfigurator configurator, Func <IMessageDataRepositorySelector, IMessageDataRepository> selector) { if (configurator is null) { throw new ArgumentNullException(nameof(configurator)); } if (selector is null) { throw new ArgumentNullException(nameof(selector)); } var repository = selector(new MessageDataRepositorySelector(configurator)); UseMessageData(configurator, repository); if (repository is IBusObserver observer) { configurator.ConnectBusObserver(observer); } return(repository); }
/// <summary> /// Uses the health check, in combination with the MassTransit Hosted Service, to monitor the bus /// </summary> /// <param name="busConfigurator"></param> /// <param name="provider"></param> public static void UseHealthCheck(this IBusFactoryConfigurator busConfigurator, IServiceProvider provider) { var healthCheck = provider.GetRequiredService <BusHealthCheck>(); busConfigurator.ConnectBusObserver(healthCheck); }
internal static void UseHealthCheck(IBusFactoryConfigurator busConfigurator, BusHealthCheck healthCheck) { busConfigurator.ConnectBusObserver(healthCheck); }
/// <summary> /// Connect an observer to the bus, to observe creation, start, stop, fault events. /// </summary> /// <param name="configurator"></param> /// <param name="observer"></param> public static void BusObserver(this IBusFactoryConfigurator configurator, IBusObserver observer) { configurator.ConnectBusObserver(observer); }
public void UseHealthCheck(IBusFactoryConfigurator configurator) { configurator.ConnectBusObserver(_busHealth); configurator.ConnectEndpointConfigurationObserver(_busHealth); }
/// <summary> /// Connect an observer to the bus, to observe creation, start, stop, fault events. /// </summary> /// <param name="configurator"></param> /// <param name="observerFactory">Factory to create the bus observer</param> public static void BusObserver <T>(this IBusFactoryConfigurator configurator, Func <T> observerFactory) where T : IBusObserver { configurator.ConnectBusObserver(observerFactory()); }