Example #1
0
        private static IContainer BootstrapContainer(TransportSettings transportSettings, string appNameBase)
        {
            ObjectFactory.Initialize(cfg =>
            {
                cfg.AddRegistry <CentralMonRegistry>();

                cfg.For <TransportSettings>().Singleton().Use(transportSettings);

                cfg.For <IServiceBus>().Use(context => ServiceBusFactory.New(sbc =>
                {
                    string rcvQueueUri = transportSettings.GetQueueUri(appNameBase);
                    sbc.ReceiveFrom(rcvQueueUri);

                    transportSettings.ApplyGlobalConfig(sbc);

                    sbc.UseControlBus();

                    sbc.Subscribe(sub =>
                    {
                        sub.LoadFrom(ObjectFactory.Container);
                    });
                }));
            });

            var container = ObjectFactory.Container;

            CentralMonRegistry.Build(container);
            return(container);
        }
Example #2
0
        static void Main(string[] args)
        {
            try
            {
                TransportSettings ts = TransportSettings.UseRabbitMq("localhost");
                int    saltNumber    = new Random().Next(1000, 10000);
                string appName       = string.Format("cclient_{0}", saltNumber);

                var bus = ServiceBusFactory.New(sbc =>
                {
                    sbc.ReceiveFrom(ts.GetQueueUri(appName));
                    sbc.UseControlBus();

                    ts.ApplyGlobalConfig(sbc);
                });

                bus.PublishRequest(new NodeSetupRequest
                {
                    NodeId                   = appName,
                    CorrelationId            = CombGuid.Generate(),
                    NqApplicationId          = 1000,
                    NqInstanceNumber         = 0,
                    NqApplicationVersionInfo = "1.0.0.0"
                }, x =>
                {
                    x.HandleTimeout(TimeSpan.FromSeconds(10d), () =>
                    {
                        Console.WriteLine("Node setup request timed out - please ensure server connectivity and try again.");
                        throw new TimeoutException();
                    });
                    x.HandleFault(fault =>
                    {
                        Console.WriteLine("Node setup request total error.");
                        throw new IOException();
                    });
                    x.Handle <NodeSetupResponse>(msg =>
                    {
                        Console.WriteLine("Got NodeSetupResponse: " + msg.ToString());
                        x.SetTimeout(TimeSpan.FromSeconds(30));
                    });
                });

                using (var ms = new MessageSubscriber(bus))
                {
                    ms.Subscribe();
                    Console.WriteLine("Waiting for messages. Press Escape to exit.");

                    while (Console.ReadKey().Key != ConsoleKey.Escape)
                    {
                        Thread.Sleep(10);
                    }
                }

                bus.Dispose();
            }
            catch (TimeoutException)
            { }
            catch (IOException) { }
        }
        private void StartTimeoutService(TransportSettings settings)
        {
            //
            // setup the time out service
            //
            string subscriptionQueueUri = settings.GetQueueUri(SubscriptionServiceQueueName ?? STR_DefaultSubscriptionServiceQueueName);
            string timeoutQueueUri      = settings.GetQueueUri(TimeoutServiceQueueName ?? STR_DefaultTimeoutServiceQueueName);
            var    timeoutBus           = ServiceBusFactory.New(sbc =>
            {
                sbc.UseControlBus();

                sbc.ReceiveFrom(timeoutQueueUri);
                sbc.UseSubscriptionService(subscriptionQueueUri);
            });

            var timeoutService = new TimeoutService(timeoutBus, new InMemorySagaRepository <TimeoutSaga>());

            timeoutService.Start();
        }
        private string StartSubscriptionService(TransportSettings settings)
        {
            string subscriptionQueueUri = settings.GetQueueUri(SubscriptionServiceQueueName ?? STR_DefaultSubscriptionServiceQueueName);

            //
            // setup the subscription service
            //
            var subscriptionBus = ServiceBusFactory.New(sbc =>
            {
                sbc.UseRabbitMq();
                sbc.SetConcurrentConsumerLimit(1);

                sbc.ReceiveFrom(subscriptionQueueUri);
            });

            var subscriptionSagas       = new InMemorySagaRepository <SubscriptionSaga>();
            var subscriptionClientSagas = new InMemorySagaRepository <SubscriptionClientSaga>();
            var subscriptionService     = new SubscriptionService(subscriptionBus, subscriptionSagas, subscriptionClientSagas);

            subscriptionService.Start();
            return(subscriptionQueueUri);
        }