private static IBusControl CreateBusUsingAzureServiceBus( IBusRegistrationContext context, IBusConfiguration configuration) { const string UriDomain = ".servicebus.windows.net"; return(MassTransit.Bus.Factory.CreateUsingAzureServiceBus(b => { var uri = configuration.HostUri; uri = new UriBuilder(AzureServiceBusScheme, uri.Host + UriDomain).Uri; b.Host(uri, h => { h.SharedAccessSignature(s => { s.KeyName = configuration.SecretName; s.SharedAccessKey = configuration.Secret; s.TokenTimeToLive = TimeSpan.FromDays(1); s.TokenScope = TokenScope.Namespace; }); }); b.ReceiveEndpoint(configuration.QueueName, r => { TuneForReportExecution(r); r.ConfigureConsumers(context); }); })); }
static void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator configurator) { configurator.UseMessageData(new MongoDbMessageDataRepository("mongodb://127.0.0.1", "attachments")); configurator.UseMessageScheduler(new Uri("queue:quartz")); configurator.ConfigureEndpoints(context); }
private static IBusControl ConfigureBus(IBusRegistrationContext provider) => Bus.Factory.CreateUsingRabbitMq(cfg => { cfg.Host("localhost"); cfg.ConfigureEndpoints(provider); });
public ReceiveEndpointDispatcherFactory(IBusRegistrationContext registration, IBusInstance busInstance) { _hostConfiguration = busInstance.HostConfiguration; _registration = registration; _dispatchers = new ConcurrentDictionary <string, Lazy <IReceiveEndpointDispatcher> >(); }
private static IBusControl ConfigureRabbitMQ(IBusRegistrationContext context) { IRabbitMQConfig config = context.GetRequiredService <IRabbitMQConfig>(); var bus = Bus.Factory.CreateUsingRabbitMq(cfg => { // cfg.UseHealthCheck(context); cfg.Host(config.Host, config.VirtualHost, rmqHost => { rmqHost.Username(config.UserName); rmqHost.Password(config.Password); }); cfg.ReceiveEndpoint(config.Endpoint, rmqEndpoint => { rmqEndpoint.PrefetchCount = config.PrefetchCount; rmqEndpoint.Durable = config.DurableQueue; rmqEndpoint.ConfigureConsumer <RegistrationSuccessfulConsumer>(context); }); }); bus.Start(); return(bus); }
protected IBusInstance CreateBus <T, TConfigurator>(T configurator, IBusRegistrationContext context, Action <IBusRegistrationContext, TConfigurator> configure, IEnumerable <IBusInstanceSpecification> specifications) where T : TConfigurator, IBusFactory where TConfigurator : IBusFactoryConfigurator { var loggerFactory = context.GetService <ILoggerFactory>(); if (loggerFactory != null) { LogContext.ConfigureCurrentLogContext(loggerFactory); } context.UseHealthCheck(configurator); var riders = new RiderConnectable(); configurator.ConnectBusObserver(new RiderBusObserver(riders)); configure?.Invoke(context, configurator); specifications ??= Enumerable.Empty <IBusInstanceSpecification>(); var busControl = configurator.Build(specifications); var instance = new TransportBusInstance(busControl, _hostConfiguration, riders); foreach (var specification in specifications) { specification.Configure(instance); } return(instance); }
public void ConfigureBus <TEndpointConfigurator>(IBusFactoryConfigurator <TEndpointConfigurator> configurator, IBusRegistrationContext context) where TEndpointConfigurator : IReceiveEndpointConfigurator { var account = CloudStorageAccount.Parse(""); configurator.UseMessageData(account.CreateMessageDataRepository("attachments")); }
public IBusInstance CreateBus(IBusRegistrationContext context, IEnumerable <IBusInstanceSpecification> specifications = null) { var inMemoryTestHarness = new InMemoryTestHarness(_virtualHost, specifications); inMemoryTestHarness.OnConfigureInMemoryBus += configurator => configurator.ConfigureEndpoints(context); return(new InMemoryTestHarnessBusInstance(inMemoryTestHarness, context)); }
static void ConfigureBus(IBusRegistrationContext busRegistrationContext, IServiceBusBusFactoryConfigurator configurator) { configurator.Host(""); configurator.UseServiceBusMessageScheduler(); configurator.ConfigureEndpoints(busRegistrationContext); }
static void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator configurator) { configurator.UseMessageScheduler(new Uri("queue:quartz")); configurator.ConfigureEndpoints(context); }
protected IBusInstance CreateBus <T, TConfigurator>(T configurator, IBusRegistrationContext context, Action <IBusRegistrationContext, TConfigurator> configure, IEnumerable <IBusInstanceSpecification> specifications) where T : TConfigurator, IBusFactory where TConfigurator : IBusFactoryConfigurator { var loggerFactory = context.GetService <ILoggerFactory>(); if (loggerFactory != null) { LogContext.ConfigureCurrentLogContext(loggerFactory); } else if (LogContext.Current == null) { LogContext.ConfigureCurrentLogContext(); } _hostConfiguration.LogContext = LogContext.Current; context.UseHealthCheck(configurator); configure?.Invoke(context, configurator); specifications ??= Enumerable.Empty <IBusInstanceSpecification>(); IEnumerable <IBusInstanceSpecification> busInstanceSpecifications = specifications as IBusInstanceSpecification[] ?? specifications.ToArray(); IEnumerable <ValidationResult> validationResult = configurator.Validate() .Concat(busInstanceSpecifications.SelectMany(x => x.Validate())); var result = BusConfigurationResult.CompileResults(validationResult); try { var busReceiveEndpointConfiguration = configurator.CreateBusEndpointConfiguration(x => x.ConfigureConsumeTopology = false); var host = _hostConfiguration.Build() as IHost <TEndpointConfigurator>; var bus = new MassTransitBus(host, _hostConfiguration.BusConfiguration.BusObservers, busReceiveEndpointConfiguration); TaskUtil.Await(() => _hostConfiguration.BusConfiguration.BusObservers.PostCreate(bus)); IBusInstance instance = CreateBusInstance(bus, host, _hostConfiguration, context); foreach (var specification in busInstanceSpecifications) { specification.Configure(instance); } return(instance); } catch (Exception ex) { TaskUtil.Await(() => _hostConfiguration.BusConfiguration.BusObservers.CreateFaulted(ex)); throw new ConfigurationException(result, "An exception occurred during bus creation", ex); } }
public TransportBusInstance(IBusControl busControl, IHost <TEndpointConfigurator> host, IHostConfiguration hostConfiguration, IBusRegistrationContext busRegistrationContext) { _host = host; _busRegistrationContext = busRegistrationContext; BusControl = busControl; HostConfiguration = hostConfiguration; }
public MessageReceiver(IBusRegistrationContext registration, IAsyncBusHandle busHandle, IBusInstance busInstance) { _hostConfiguration = busInstance.HostConfiguration as IServiceBusHostConfiguration ?? throw new ConfigurationException("The hostConfiguration was not properly configured for Azure Service Bus"); _registration = registration; _busHandle = busHandle; _receivers = new ConcurrentDictionary <string, IBrokeredMessageReceiver>(); }
static void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator configurator) { var readFileConsumer = new ReadFileConsumer(); configurator.UseMessageScheduler(new Uri("queue:quartz")); configurator.ReceiveEndpoint("file-watcher", e => { e.Instance(readFileConsumer); }); }
private static void ConfigureRabbitMQ(IBusRegistrationContext registrationContext, IRabbitMqBusFactoryConfigurator cfgBus) { var rabbitMQConfigurationOption = registrationContext.GetService<IOptions<RabbitMQConfiguration>>(); var rabbitMQConfiguration = rabbitMQConfigurationOption.Value; cfgBus.Host(new Uri($"rabbitmq://{rabbitMQConfiguration.Host}/{rabbitMQConfiguration.VirtualHost}"), cfgRabbitMq => { cfgRabbitMq.Username(rabbitMQConfiguration.Username); cfgRabbitMq.Password(rabbitMQConfiguration.Password); }); cfgBus.ConfigureEndpoints(registrationContext); }
static void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator configurator) { configurator.Host(AppConfig.RabbitMq.HostAddress, AppConfig.RabbitMq.VirtualHost, h => { h.Username(AppConfig.RabbitMq.Username); h.Password(AppConfig.RabbitMq.Password); }); configurator.ReceiveEndpoint("Sales.Orders.OrderCreated", cfg => { cfg.Consumer <PlaceOrderConsumer>(); }); }
public static void ReceiveEndpointForEachConsumer(this IRabbitMqBusFactoryConfigurator configurator, IBusRegistrationContext provider, string queuePrefix, ICollection <Assembly> fromAssemblies, Action <IRabbitMqReceiveEndpointConfigurator> endpointConfiguration = null) { foreach (var consumer in ConsumersProvider.GetConsumers(fromAssemblies)) { configurator.ReceiveEndpoint($"{queuePrefix}:{consumer.FullName}", endpointConfigurator => { endpointConfigurator.ConfigureConsumer(provider, consumer); endpointConfiguration?.Invoke(endpointConfigurator); }); } }
public override void ConfigureEndPointsAction( IRabbitMqBusFactoryConfigurator rabbitMqBusFactoryConfigurator, IBusRegistrationContext busRegistrationContext) { rabbitMqBusFactoryConfigurator.ReceiveEndpoint( nameof(SendNotificationCommand), e => { e.UseMessageRetry(r => r.Immediate(5)); e.UseInMemoryOutbox(); e.Consumer <SendNotificationConsumer>(busRegistrationContext); }); }
static void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator configurator) { configurator.Host(AppConfig.RabbitMq.HostAddress, AppConfig.RabbitMq.VirtualHost, h => { h.Username(AppConfig.RabbitMq.Username); h.Password(AppConfig.RabbitMq.Password); }); configurator.ReceiveEndpoint("Shipping.BusinessCustomers.ShippingArranged", cfg => { cfg.Consumer <OrderCreatedConsumer>(); cfg.Consumer <PaymentAcceptedConsumer>(); }); }
public IBusInstance CreateBus(IBusRegistrationContext context, IEnumerable <IBusInstanceSpecification> specifications) { var loggerFactory = context.GetService <ILoggerFactory>(); if (loggerFactory != null) { LogContext.ConfigureCurrentLogContext(loggerFactory); } var busControl = _configure(context); return(new DefaultBusInstance(busControl, context)); }
public void ConfigureExecuteActivity(IBusRegistrationContext busRegistrationContext, IRabbitMqBusFactoryConfigurator rabbitMqBusFactoryConfigurator) { foreach (var commandType in _types) { string endpointName = commandType.FullName.Replace(".", "").Replace("+", ""); rabbitMqBusFactoryConfigurator.ReceiveEndpoint(endpointName, ec => { ec.ConfigureExecuteActivity(busRegistrationContext, typeof(CommandActivity <>).MakeGenericType(commandType)); }); } }
static void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator configurator) { configurator.Host(AppConfig.RabbitMq.HostAddress, AppConfig.RabbitMq.VirtualHost, h => { h.Username(AppConfig.RabbitMq.Username); h.Password(AppConfig.RabbitMq.Password); }); configurator.ReceiveEndpoint("Billing.Payments.PaymentAccepted", cfg => { cfg.Consumer <OrderCreatedConsumer>(); cfg.Consumer <RecordPaymentAttemptConsumer>(); }); }
public static IBusControl Create(IBusRegistrationContext ctx) { return(Bus.Factory.CreateUsingRabbitMq(cfg => { cfg.Host(new Uri("rabbitmq://localhost/test"), h => { h.Username("guest"); h.Password("guest"); }); cfg.ConfigureEndpoints(ctx); })); }
private static void ConfigureRabbitMq(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator configurator) { var massTransitRabbitConfig = context.GetService <MassTransitRabbitConfig>(); var clusterInternalName = massTransitRabbitConfig.ClusterName; var virtualHost = massTransitRabbitConfig.VirtualHost; var connectionName = $"{Assembly.GetEntryAssembly()?.GetName().Name} ({Environment.MachineName})"; configurator.Host( new UriBuilder("rabbitmq", clusterInternalName, massTransitRabbitConfig.ClusterPort, virtualHost) .Uri, connectionName, hostConfigurator => { hostConfigurator.Username(massTransitRabbitConfig.UserName); hostConfigurator.Password(massTransitRabbitConfig.Password); hostConfigurator.PublisherConfirmation = true; hostConfigurator.UseCluster( cluster => { foreach (var node in massTransitRabbitConfig.ClusterNodes) { cluster.Node(node); } }); if (massTransitRabbitConfig.UseSSL) { hostConfigurator.UseSsl(sslConfigurator => sslConfigurator.Protocol = SslProtocols.None); } }); configurator.UseDelayedMessageScheduler(); configurator.UseSerilogEnricher(); configurator.UseRetry( retryConfig => retryConfig.Exponential( 5, TimeSpan.FromMilliseconds(200), TimeSpan.FromSeconds(60), TimeSpan.FromSeconds(1))); var serviceInstanceOptions = new ServiceInstanceOptions() .EnableJobServiceEndpoints() .SetEndpointNameFormatter(KebabCaseEndpointNameFormatter.Instance); configurator.ConfigureServiceEndpoints(context, serviceInstanceOptions); // configurator.ConfigureEndpoints(context); }
private static void ConfigureRabbitMQ(IBusRegistrationContext registrationContext, IRabbitMqBusFactoryConfigurator cfgBus) { var rabbitMQConfigurationOption = registrationContext.GetService <IOptions <RabbitMQConfiguration> >(); var rabbitMQConfiguration = rabbitMQConfigurationOption.Value; cfgBus.Host(new Uri($"rabbitmq://{rabbitMQConfiguration.Host}/{rabbitMQConfiguration.VirtualHost}"), cfgRabbitMq => { cfgRabbitMq.Username(rabbitMQConfiguration.Username); cfgRabbitMq.Password(rabbitMQConfiguration.Password); }); var repository = registrationContext.GetService <ISagaRepository <CoffeeState> >(); cfgBus.ReceiveEndpoint("state-machine", e => e.StateMachineSaga(registrationContext.GetService <CoffeeStateMachine>(), repository)); }
private static void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator cfg) { cfg.Host("localhost", "/", x => { x.Username("guest"); x.Password("guest"); }); cfg.PrefetchCount = 10; cfg.UseMessageRetry(r => { r.Immediate(1); }); cfg.UseLogging(); cfg.ConfigureEndpoints(context); }
public static IBusControl ConfigureBus(IBusRegistrationContext provider) { //Bus.Factory.CreateUsingRabbitMq(config => //{ // config.Host("rabbitmq://localhost", "VirtualHost", // hostConfigurator => // { // hostConfigurator.Username("guest"); // hostConfigurator.Password("guest"); // }); //}); return(Bus.Factory.CreateUsingRabbitMq(config => { config.ConfigureEndpoints(provider); })); }
private static void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator cfg) { cfg.Host("localhost", "/", x => { x.Username("guest"); x.Password("guest"); }); cfg.PrefetchCount = 10; cfg.UseMessageRetry(r => r.Exponential(4, TimeSpan.FromMilliseconds(500), TimeSpan.FromSeconds(10), TimeSpan.FromMilliseconds(500))); cfg.ConfigureEndpoints(context); cfg.UseInMemoryOutbox(c => c.ConcurrentMessageDelivery = true); }
/// <summary> /// Register receive EndPoint and bind with type <typeparamref name="T"/>. /// </summary> /// <param name="busRegistrationContext">Bus registration contex.</param> /// <param name="busFactoryConfigurator">Configuration factory.</param> /// <param name="endpointConsumerConfigurator">Configure consumer delegate.</param> /// <param name="amazonMqOptions">Force connection params</param> /// <param name="createSeparateQueue">True for Publish, false when only Send.</param> /// <typeparam name="T">Consumer type.</typeparam> /// <typeparam name="TMessage">Consumer message type.</typeparam> /// <exception cref="ArgumentNullException"/> public static void RegisterReceiveEndpoint <T, TMessage>(this IBusRegistrationContext busRegistrationContext, IAmazonSqsBusFactoryConfigurator busFactoryConfigurator, Action <IEndpointConfigurator>?endpointConsumerConfigurator = null, AmazonMqOptions?amazonMqOptions = null, bool createSeparateQueue = false) where T : class, IConsumer <TMessage> where TMessage : class, IConsumer { if (busRegistrationContext == null) { throw new ArgumentNullException(nameof(busRegistrationContext)); } if (busFactoryConfigurator == null) { throw new ArgumentNullException(nameof(busFactoryConfigurator)); } RegisterConsumersEndpoint <TMessage>(busRegistrationContext, busFactoryConfigurator, endpointConsumerConfigurator, new[] { typeof(T) }, amazonMqOptions, createSeparateQueue); }
private void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator cfg) { var settings = context.GetRequiredService <IOptions <RabbitMqSettings> >().Value; cfg.Host(settings.Host, settings.VirtualHost, h => { h.Username(settings.Username); h.Password(settings.Password); if (settings.SSLActive) { h.UseSsl(ssl => { ssl.ServerName = Dns.GetHostName(); ssl.AllowPolicyErrors(SslPolicyErrors.RemoteCertificateNameMismatch); ssl.Certificate = GetX509Certificate(settings); ssl.Protocol = SslProtocols.Tls12; ssl.CertificateSelectionCallback = CertificateSelectionCallback; }); } }); cfg.UsePublishFilter(typeof(Filters.MyPublishFilter <>), context); cfg.UseSendFilter(typeof(Filters.MySendFilter <>), context); cfg.UseConsumeFilter(typeof(Filters.MyConsumerFilter <>), context); cfg.UseHealthCheck(context); cfg.UseJsonSerializer(); // Because we are using json within Quartz for serializer type cfg.UseInMemoryScheduler(context.GetRequiredService <ISchedulerFactory>()); cfg.ConfigureEndpoints(context); cfg.UseInMemoryOutbox(); //cfg.ManagementEndpoint(c => //{ // c.UseMessageRetry(r => // { // r.Ignore<ArgumentNullException>(); // r.Immediate(5); // }); //}); X509Certificate CertificateSelectionCallback(object sender, string targethost, X509CertificateCollection localcertificates, X509Certificate remotecertificate, string[] acceptableissuers) { var serverCertificate = localcertificates.OfType <X509Certificate2>() .FirstOrDefault(cert => cert.Thumbprint.ToLower() == settings.SSLThumbprint.ToLower()); return(serverCertificate ?? throw new Exception("Wrong certificate")); } }