Exemple #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();
            }
        }
Exemple #2
0
        protected override void Run(CancellationToken cancellationToken)
        {
            var busFactory = new BusFactory().WithScan()
                                             .WithConfiguration("tcp://localhost:129", "Demo")
                                             .WithPeerId("Receiver.*");

            using (busFactory.CreateAndStartBus())
            {
                cancellationToken.WaitHandle.WaitOne();
            }
        }
Exemple #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);
                }
            }
        }
Exemple #4
0
        private static void InjectDirectoryServiceSpecificConfiguration(BusFactory busFactory)
        {
            busFactory.ConfigureContainer(c =>
            {
                c.ForSingletonOf<IDirectoryConfiguration>().Use<AppSettingsDirectoryConfiguration>();

                c.For<IDeadPeerDetector>().Use<DeadPeerDetector>();
                c.ForSingletonOf<IPeerRepository>().Use<MemoryPeerRepository>();
                c.ForSingletonOf<PeerDirectoryServer>().Use<PeerDirectoryServer>();
                c.ForSingletonOf<IPeerDirectory>().Use(ctx => ctx.GetInstance<PeerDirectoryServer>());

                c.ForSingletonOf<IMessageDispatcher>().Use(typeof(Func<IContext, MessageDispatcher>).Name, ctx =>
                {
                    var dispatcher = ctx.GetInstance<MessageDispatcher>();
                    dispatcher.ConfigureHandlerFilter(x => x != typeof(PeerDirectoryClient));

                    return dispatcher;
                });
            });
        }