Example #1
0
        public void ItShouldGetConsumersFromTheContainer()
        {
            using (var container = new Container()) {
                var consumerAssemblies = new[] { GetType().Assembly };
                container.Register(typeof(Consumes <> .All), consumerAssemblies);
                var endpointUri = new Uri("loopback://localhost/queue");
                container.RegisterSingleton(() =>
                                            ServiceBusFactory.New(sbc => {
                    sbc.ReceiveFrom(endpointUri);
                    sbc.Subscribe(subs => {
                        // ReSharper disable AccessToDisposedClosure
                        subs.LoadFrom(container);
                        // ReSharper restore AccessToDisposedClosure
                    });
                }));
                container.Verify();

                var bus     = container.GetInstance <IServiceBus>();
                var message = new FakeMessage {
                    Moment = DateTime.Now
                };
                bus.GetEndpoint(endpointUri).Send(message);

                Thread.Sleep(100);
                Assert.Equal(1, FakeMessage.MessageConsumedCount);
            }
        }
Example #2
0
        /// <summary>
        /// Call to initialize the service bus instance, including any configuration.
        /// </summary>
        /// <param name="configure">A lambda/action that does the bus configugration.</param>
        /// <exception cref="ConfigurationException">
        /// If the bus has already been initialized by a call
        /// to this method.</exception>
        public static void Initialize(Action <ServiceBusConfigurator> configure)
        {
            if (_instance != null)
            {
                throw new ConfigurationException("Bus.Instance has already been initialized. Call Shutdown first.");
            }

            _instance = ServiceBusFactory.New(configure);
        }
Example #3
0
        public void SetupServiceBus(string[] assemblyPaths, CommandDefinition cmdDef, Dictionary <string, object> connectionSettings)
        {
            _subscriptionQueueService = connectionSettings.GetValue("subscriptionQueueService") as string;

            if (_bus == null)
            {
                if (CommandContentFormat == "JSON")
                {
                    if (_subscriptionQueueService.IsValid())
                    {
                        _bus = ServiceBusFactory.New(sbc =>
                        {
                            sbc.UseMsmq();
                            sbc.UseMsmq(x => x.UseSubscriptionService(_subscriptionQueueService));
                            sbc.ReceiveFrom("msmq://localhost/ServiceBusMQ");
                            sbc.UseJsonSerializer();
                            sbc.UseControlBus();
                        });
                    }
                    else
                    {
                        _bus = ServiceBusFactory.New(sbc =>
                        {
                            sbc.UseMsmq();
                            //sbc.UseMsmq(x => x.UseSubscriptionService(subscriptionServiceUriString));
                            sbc.ReceiveFrom("msmq://localhost/ServiceBusMQ");
                            sbc.UseJsonSerializer();
                            sbc.UseControlBus();
                        });
                    }
                }
                else
                {
                    if (_subscriptionQueueService != string.Empty)
                    {
                        _bus = ServiceBusFactory.New(sbc =>
                        {
                            sbc.UseMsmq();
                            sbc.UseMsmq(x => x.UseSubscriptionService(_subscriptionQueueService));
                            sbc.ReceiveFrom("msmq://localhost/ServiceBusMQ");
                            sbc.UseControlBus();
                        });
                    }
                    else
                    {
                        _bus = ServiceBusFactory.New(sbc =>
                        {
                            sbc.UseMsmq();
                            //sbc.UseMsmq(x => x.UseSubscriptionService(subscriptionServiceUriString));
                            sbc.ReceiveFrom("msmq://localhost/ServiceBusMQ");
                            sbc.UseControlBus();
                        });
                    }
                }
                Thread.Sleep(TimeSpan.FromSeconds(10));
            }
        }