Example #1
0
        public static void Main()
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                _cancelKeySignal.Set();
            };

            XmlConfigurator.ConfigureAndWatch(new FileInfo(PathUtil.InBaseDirectory("log4net.config")));
            _log.Info("Starting in memory directory");

            var busFactory = new BusFactory();

            InjectDirectoryServiceSpecificConfiguration(busFactory);

            busFactory
            .WithConfiguration(new AppSettingsBusConfiguration(), ConfigurationManager.AppSettings["Environment"])
            .WithScan()
            .WithEndpoint(ConfigurationManager.AppSettings["Endpoint"])
            .WithPeerId(ConfigurationManager.AppSettings["PeerId"]);

            using (busFactory.CreateAndStartBus())
            {
                _log.Info("In memory directory started");

                _log.Info("Starting dead peer detector");
                var deadPeerDetector = busFactory.Container.GetInstance <IDeadPeerDetector>();
                deadPeerDetector.Start();

                _cancelKeySignal.WaitOne();

                _log.Info("Stopping dead peer detector");
                deadPeerDetector.Stop();
            }
        }
Example #2
0
        protected override void Run(CancellationToken cancellationToken)
        {
            var busFactory = new BusFactory(_container).WithScan()
                             .WithConfiguration("tcp://localhost:129", "Demo")
                             .WithPeerId("Receiver.*");

            using (busFactory.CreateAndStartBus())
            {
                cancellationToken.WaitHandle.WaitOne();
            }
        }
Example #3
0
        protected override void Run(CancellationToken cancellationToken)
        {
            var busFactory = new BusFactory().WithConfiguration("tcp://localhost:129", "Demo")
                             .WithPeerId("Publisher.*");

            using (var bus = busFactory.CreateAndStartBus())
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    bus.Publish(new SomethingHappened());

                    Thread.Sleep(500);
                }
            }
        }
Example #4
0
        public static void Main()
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                _cancelKeySignal.Set();
            };

            XmlConfigurator.ConfigureAndWatch(new FileInfo(InBaseDirectory("log4net.config")));
            _log.Info("Starting persistence");

            var appSettingsConfiguration = new AppSettingsConfiguration();
            var useCassandraStorage      = ConfigurationManager.AppSettings["PersistenceStorage"] == "Cassandra";
            var busFactory = new BusFactory().WithConfiguration(appSettingsConfiguration, ConfigurationManager.AppSettings["Environment"])
                             .WithScan()
                             .WithEndpoint(ConfigurationManager.AppSettings["Endpoint"])
                             .WithPeerId(ConfigurationManager.AppSettings["PeerId"]);

            InjectPersistenceServiceSpecificConfiguration(busFactory, appSettingsConfiguration, useCassandraStorage);

            using (busFactory.CreateAndStartBus())
            {
                _log.Info("Starting initialisers");
                var inMemoryMessageMatcherInitializer = busFactory.Container.GetInstance <InMemoryMessageMatcherInitializer>();
                inMemoryMessageMatcherInitializer.BeforeStart();

                OldestNonAckedMessageUpdaterPeriodicAction oldestNonAckedMessageUpdaterPeriodicAction = null;
                if (useCassandraStorage)
                {
                    oldestNonAckedMessageUpdaterPeriodicAction = busFactory.Container.GetInstance <OldestNonAckedMessageUpdaterPeriodicAction>();
                    oldestNonAckedMessageUpdaterPeriodicAction.AfterStart();
                }

                _log.Info("Persistence started");

                _cancelKeySignal.WaitOne();

                _log.Info("Stopping initialisers");
                oldestNonAckedMessageUpdaterPeriodicAction?.BeforeStop();

                var messageReplayerInitializer = busFactory.Container.GetInstance <MessageReplayerInitializer>();
                messageReplayerInitializer.BeforeStop();

                inMemoryMessageMatcherInitializer.AfterStop();

                _log.Info("Persistence stopped");
            }
        }
Example #5
0
        protected override void Run(CancellationToken cancellationToken)
        {
            var busFactory = new BusFactory().WithScan()
                             .WithConfiguration("tcp://localhost:129", "Demo")
                             .WithPeerId("Publisher.*");

            using (var bus = busFactory.CreateAndStartBus())
                while (!cancellationToken.IsCancellationRequested)
                {
                    _stopwatch.Restart();
                    bus.Send(new CountDoneThingsCommand(_random.Next(1, 100)))
                    .Wait(cancellationToken); // wait until the command has been fully handled
                    _stopwatch.Stop();

                    _log.InfoFormat("The command has been handled in {0}", _stopwatch.Elapsed);
                }
        }
Example #6
0
        public static void Main()
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                _cancelKeySignal.Set();
            };

            XmlConfigurator.ConfigureAndWatch(LogManager.GetRepository(typeof(Program).Assembly), new FileInfo(PathUtil.InBaseDirectory("log4net.config")));
            var storageType = ConfigurationManager.AppSettings["Storage"] !;

            _log.Info($"Starting in directory with storage type '{storageType}'");

            var busFactory = new BusFactory();

            InjectDirectoryServiceSpecificConfiguration(busFactory, Enum.Parse <StorageType>(storageType));

            busFactory
            .WithConfiguration(new AppSettingsBusConfiguration(), ConfigurationManager.AppSettings["Environment"] !)
            .WithScan()
            .WithEndpoint(ConfigurationManager.AppSettings["Endpoint"] !)
            .WithPeerId(ConfigurationManager.AppSettings["PeerId"] !);

            using (busFactory.CreateAndStartBus())
            {
                _log.Info("Directory started");

                _log.Info("Starting dead peer detector");
                var deadPeerDetector = busFactory.Container.GetInstance <IDeadPeerDetector>();
                deadPeerDetector.Start();

                _cancelKeySignal.WaitOne();

                _log.Info("Stopping dead peer detector");
                deadPeerDetector.Stop();
            }
        }