Ejemplo n.º 1
0
        private void ConfigureHandlers()
        {
            var redis = ConnectionMultiplexer.Connect("localhost");
            var productView = new ProductView(new RedisReadModelRepository<ProductDto>(redis.GetDatabase()));
            ServiceLocator.ProductView = productView;

            var eventMappings = new EventHandlerDiscovery()
                                .Scan(productView)
                                .Handlers;

            var subscriptionName = "admin_readmodel";
            var topicFilter1 = "Admin.Common.Events";

            var b = RabbitHutch.CreateBus("host=localhost");

            b.Subscribe<PublishedMessage>(subscriptionName,
            m =>
            {
                Aggregate handler;
                var messageType = Type.GetType(m.MessageTypeName);
                var handlerFound = eventMappings.TryGetValue(messageType, out handler);
                if (handlerFound)
                {
                    var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType);
                    handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version);
                }
            },
            q => q.WithTopic(topicFilter1));

            var bus = new RabbitMqBus(b);

            ServiceLocator.Bus = bus;
        }
Ejemplo n.º 2
0
        private void ConfigureHandlers()
        {
            var b = RabbitHutch.CreateBus("host=localhost");

            var messageBusEndPoint = "barista";
            var topicFilter = "Cashier.Common.Events";

            var bus = new RabbitMqBus(b);
            ServiceLocator.Bus = bus;

            //Should get this from a config setting instead of hardcoding it.
            var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, 12900));
            eventStoreConnection.ConnectAsync().Wait();
            var repository = new EventStoreRepository(eventStoreConnection, bus);

            ServiceLocator.OrderCommands = new BaristaOrderCommandHandlers(repository);

            var cashierEventHandler = new CashierOrderEventHandler(repository);
            ServiceLocator.CahierEventHandler = cashierEventHandler;

            var eventMappings = new EventHandlerDiscovery()
                .Scan(cashierEventHandler)
                .Handlers;

            b.Subscribe<PublishedMessage>(messageBusEndPoint,
            m =>
            {
                Aggregate handler;
                var messageType = Type.GetType(m.MessageTypeName);
                var handlerFound = eventMappings.TryGetValue(messageType, out handler);
                if (handlerFound)
                {
                    var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType);
                    handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version);
                }
            },
            q => q.WithTopic(topicFilter));
        }
Ejemplo n.º 3
0
        private void ConfigureHandlers()
        {
            var b = RabbitHutch.CreateBus("host=localhost");
            var bus = new RabbitMqBus(b);
            ServiceLocator.Bus = bus;

            var messageBusEndPoint = "cashier_service";
            var topicFilter = "Admin.Common.Events";

            var eventStorePort = 12900;

            var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(IPAddress.Loopback, eventStorePort));
            eventStoreConnection.ConnectAsync().Wait();
            var repository = new EventStoreRepository(eventStoreConnection, bus);

            ServiceLocator.OrderCommands = new OrderCommandHandlers(repository);
            ServiceLocator.ProductView = new ProductView();

            var eventMappings = new EventHandlerDiscovery()
                .Scan(new AdminEventsHandler())
                .Handlers;

            b.Subscribe<PublishedMessage>(messageBusEndPoint,
            m =>
            {
                Aggregate handler;
                var messageType = Type.GetType(m.MessageTypeName);
                var handlerFound = eventMappings.TryGetValue(messageType, out handler);
                if (handlerFound)
                {
                    var @event = JsonConvert.DeserializeObject(m.SerialisedMessage, messageType);
                    handler.AsDynamic().ApplyEvent(@event, ((Event)@event).Version);
                }
            },
            q => q.WithTopic(topicFilter));
        }