Ejemplo n.º 1
0
        private static IBusControl CreateIBusControl()
        {
            var config = new BusConfiguration
            {
                // Endpoint=sb://rrdevtest.servicebus.windows.net/;SharedAccessKeyName=XXXX;SharedAccessKey=YYYY
                ConnectionUri = "sb://rrdevtest.servicebus.windows.net",
                Login         = "******",
                Password      = "******"
            };

            var configurator = new AzureSbBusConfigurator(config);
            var bus          = configurator
                               .CreateBus((cfg, host) =>
            {
                // Command Consumers
                cfg.ReceiveEndpoint <WorldCommand>(c =>
                {
                    c.Consumer <WorldCommandConsumer>();
                });

                // TODO: below doesn't work, OR does it??
                cfg.UseRetry(r => r.Exponential(3, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(5)));
                // TODO: but this works ..
                // cfg.UseRetry(Retry.Exponential(3, TimeSpan.FromSeconds(5), TimeSpan.FromMinutes(2), TimeSpan.FromSeconds(5))); // works
            });

            return(bus);
        }
Ejemplo n.º 2
0
        private static IBusControl CreateIBusControl()
        {
            var connstring = new JsonConfigFileReader().GetValue("AzureSbConnectionString");

            var bus = new AzureSbBusConfigurator(connstring)
                      .CreateBus((cfg, host) =>
            {
                //TODO: How to handle pool of receivers? aka "Competing Consumers"
                // https://masstransit.readthedocs.io/en/latest/configuration/gotchas.html#how-to-setup-a-competing-consumer
                // http://docs.masstransit-project.com/en/latest/overview/underthehood.html

                // Command Consumers
                if (_enableCommandConsumers)
                {
                    cfg.ReceiveEndpoint <IUpdateFooCommand>(c =>    // The interface = the queue name
                    {
                        // LAB: Try turn all consumers off and see what happens when sending the commands ..

                        c.Consumer <UpdateFooCommandConsumer>();         // What class will consume the messages
                        c.Consumer <UpdateFooVersion2CommandConsumer>(); // What class will consume the messages
                        c.Consumer <IUpdateFooCommandConsumer>();        // What class will consume the messages
                    });
                }


                // Event Consumers
                if (_enableEventConsumers)
                {
                    cfg.ReceiveEndpoint <IBarEvent>(c =>    // The interface name = the queue name
                    {
                        c.Consumer <BarEventConsumer>();    // What class will consume the messages
                    });
                    cfg.ReceiveEndpoint <IUpdateProductsStartedEvent>(c =>
                    {
                        c.Consumer <UpdateProductsStartedEventConsumer>();
                    });
                    cfg.ReceiveEndpoint <ISagaUpdateProductsBatchCommand>(c =>
                    {
                        c.Consumer <UpdateProductsBatchCommandConsumer>();
                    });
                }

                // Request Reply Consumers
                if (_enableRequestReplyConsumers)
                {
                    cfg.ReceiveEndpoint <ServeBarsCommand>(c =>    // The interface name = the queue name
                    {
                        c.Consumer <ServeBarsCommandConsumer>();   // What class will consume the messages
                    });
                }

                // Saga Consumers
                _machine             = new UpdateProductsStateMachine();
                _updProductsSagaRepo = new InMemorySagaRepository <UpdateProductsSaga>();

                if (_enableSagaConsumers)
                {
                    // It looks like all messages related to the saga must be sent to the same queue? But what if we can't control this? (Look it up)
                    cfg.ReceiveEndpoint("update_products_saga", c =>
                    {
                        c.StateMachineSaga(_machine, _updProductsSagaRepo);
                    });
                }

                // Manual Consumers
                //cfg.ReceiveEndpoint("manual_queue", c =>  // The interface = the queue name
                //{
                //    c.Consumer<AnotherBarEventConsumer>(); // What class will consume the messages
                //});
            });

            // Use this to debug. Example: You send stuff that should arrive to a saga but it doesn't, and you wanna know if the messages are even received, then place breakpoints there.
            bus.ConnectReceiveObserver(new ConsoleOutReceiveObserver());

            return(bus);
        }