Exemplo n.º 1
0
        protected override IDisposable InitializeFactory(IObservable <IConnected <IBroker> > brokerStream)
        {
            var eventStoreConnection = GetEventStoreConnection(Config.EventStore);
            var mon      = new ConnectionStatusMonitor(eventStoreConnection);
            var esStream = mon.GetEventStoreConnectedStream(eventStoreConnection);

            eventStoreConnection.ConnectAsync().Wait();

            return(Factory.Initialize(brokerStream, esStream));
        }
Exemplo n.º 2
0
        public void Start()
        {
            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                _reset.Set();
            };

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Information()
                         .WriteTo.ColoredConsole()
                         .CreateLogger();

            var config = ServiceConfiguration.FromArgs(_args);

            try
            {
                using (var connectionFactory = BrokerConnectionFactory.Create(config.Broker))
                {
                    var brokerStream = connectionFactory.GetBrokerStream();


                    var esFactory = _factory as IServiceHostFactoryWithEventStore;

                    if (esFactory != null)
                    {
                        // TODO TIDY

                        var eventStoreConnection = GetEventStoreConnection(config.EventStore);
                        var mon      = new ConnectionStatusMonitor(eventStoreConnection);
                        var esStream = mon.GetEventStoreConnectedStream(eventStoreConnection);
                        eventStoreConnection.ConnectAsync().Wait();

                        using (esFactory.Initialize(brokerStream, esStream))
                        {
                            connectionFactory.Start();

                            _reset.WaitOne();
                        }
                    }
                    else
                    {
                        using (_factory.Initialize(brokerStream))
                        {
                            connectionFactory.Start();
                            _reset.WaitOne();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Log.Error(e, "Error connecting to broker");
            }
        }
        public static IWebHostBuilder UseEventStore(this IWebHostBuilder hostBuilder)
        {
            var configuration        = new EventStoreConfiguration(ServiceConstants.EventStoreUrl);
            var eventStoreConnection = new ExternalEventStore(EventStoreUri.FromConfig(configuration)).Connection;

            eventStoreConnection.ConnectAsync().Wait();

            var monitor          = new ConnectionStatusMonitor(eventStoreConnection);
            var eventStoreStream = monitor.GetEventStoreConnectedStream(eventStoreConnection);

            hostBuilder.ConfigureServices((services) =>
            {
                services.Add(new ServiceDescriptor(typeof(IEventStoreConnection), eventStoreConnection));
                services.Add(new ServiceDescriptor(typeof(IObservable <IConnected <IEventStoreConnection> >), eventStoreStream));
            });

            return(hostBuilder);
        }
Exemplo n.º 4
0
 public static IObservable <IConnected <IEventStoreConnection> > GetEventStoreConnectedStream(this ConnectionStatusMonitor monitor,
                                                                                              IEventStoreConnection connection)
 {
     return(monitor.ConnectionInfoChanged.Where(x => x.Status == ConnectionStatus.Connected ||
                                                x.Status == ConnectionStatus.Disconnected)
            .Select(c => c.Status == ConnectionStatus.Connected
                       ? Connected.Yes(connection)
                       : Connected.No <IEventStoreConnection>()));
 }