コード例 #1
0
        static IBusControl ConfigureBus(IRegistrationContext <IServiceProvider> provider)
        {
            AppConfig = provider.GetRequiredService <IOptions <AppConfig> >().Value;

            return(Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                IRabbitMqHost host = cfg.Host(AppConfig.Host, AppConfig.VirtualHost, h =>
                {
                    h.Username(AppConfig.Username);
                    h.Password(AppConfig.Password);
                });

                // 1. Configuring consistent exchange

                string consistentExchangeName = "x-consistent-hash";
                DeclareConsistentExchange(host, consistentExchangeName);

                // 2. Configuring endpoints bindings to queues
                cfg.ReceiveEndpoint("qq1", ep =>
                {
                    ep.ConfigureConsumeTopology = false;
                    ep.Bind(
                        "x-consistent-hash",
                        x =>
                    {
                        x.Durable = true;
                        x.ExchangeType = "x-consistent-hash";
                        x.RoutingKey = "10";
                    });

                    ep.PrefetchCount = 1;

                    ep.Consumer <QuoteCreatedConsumer1>(provider.Container);
                });

                cfg.ReceiveEndpoint("qq2", ep =>
                {
                    ep.ConfigureConsumeTopology = false;
                    ep.Bind(
                        "x-consistent-hash",
                        x =>
                    {
                        x.Durable = true;
                        x.ExchangeType = "x-consistent-hash";
                        x.RoutingKey = "10";
                    });

                    ep.PrefetchCount = 1;

                    ep.Consumer <QuoteCreatedConsumer2>(provider.Container);
                });

                // 3. Binding message endpoints to consistent exchange
                cfg.ConnectBusObserver(new BindIncomingMessageExchangeAction(
                                           host,
                                           consistentExchangeName,
                                           typeof(IQuoteCreated)
                                           ));
            }));
        }
コード例 #2
0
        private static IBusControl ConfigureBus(IRegistrationContext <IServiceProvider> provider)
        {
            AppConfig = provider.GetRequiredService <IOptions <AppConfig> >().Value;

            return(Bus.Factory.CreateUsingRabbitMq(cfg =>
            {
                var host = cfg.Host(AppConfig.Host, AppConfig.VirtualHost, h =>
                {
                    h.Username(AppConfig.Username);
                    h.Password(AppConfig.Password);
                });

                cfg.ConfigureEndpoints(provider);
            }));
        }