コード例 #1
0
        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);
                });
            }));
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        private static IBusControl ConfigureBus(IBusRegistrationContext provider)
        => Bus.Factory.CreateUsingRabbitMq(cfg =>
        {
            cfg.Host("localhost");

            cfg.ConfigureEndpoints(provider);
        });
コード例 #4
0
        public ReceiveEndpointDispatcherFactory(IBusRegistrationContext registration, IBusInstance busInstance)
        {
            _hostConfiguration = busInstance.HostConfiguration;
            _registration      = registration;

            _dispatchers = new ConcurrentDictionary <string, Lazy <IReceiveEndpointDispatcher> >();
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        public void ConfigureBus <TEndpointConfigurator>(IBusFactoryConfigurator <TEndpointConfigurator> configurator,
                                                         IBusRegistrationContext context)
            where TEndpointConfigurator : IReceiveEndpointConfigurator
        {
            var account = CloudStorageAccount.Parse("");

            configurator.UseMessageData(account.CreateMessageDataRepository("attachments"));
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        static void ConfigureBus(IBusRegistrationContext busRegistrationContext, IServiceBusBusFactoryConfigurator configurator)
        {
            configurator.Host("");

            configurator.UseServiceBusMessageScheduler();

            configurator.ConfigureEndpoints(busRegistrationContext);
        }
コード例 #10
0
        static void ConfigureBus(IBusRegistrationContext context, IRabbitMqBusFactoryConfigurator configurator)
        {
            configurator.UseMessageScheduler(new Uri("queue:quartz"));



            configurator.ConfigureEndpoints(context);
        }
コード例 #11
0
        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);
            }
        }
コード例 #12
0
        public TransportBusInstance(IBusControl busControl, IHost <TEndpointConfigurator> host, IHostConfiguration hostConfiguration, IBusRegistrationContext
                                    busRegistrationContext)
        {
            _host = host;
            _busRegistrationContext = busRegistrationContext;

            BusControl        = busControl;
            HostConfiguration = hostConfiguration;
        }
コード例 #13
0
        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>();
        }
コード例 #14
0
        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);
            });
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: Spaceva/CoffeeMassTransit
        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);
        }
コード例 #16
0
 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>();
     });
 }
コード例 #17
0
 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);
         });
     }
 }
コード例 #18
0
 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);
     });
 }
コード例 #19
0
 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>();
     });
 }
コード例 #20
0
        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));
        }
コード例 #21
0
ファイル: ActivitiesBuilder.cs プロジェクト: FWTL/Auth
        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));
                });
            }
        }
コード例 #22
0
 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>();
     });
 }
コード例 #23
0
        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);
            }));
        }
コード例 #24
0
        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);
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: Spaceva/CoffeeMassTransit
        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));
        }
コード例 #26
0
        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);
        }
コード例 #27
0
 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);
     }));
 }
コード例 #28
0
        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);
        }
コード例 #29
0
        /// <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);
        }
コード例 #30
0
        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"));
            }
        }