예제 #1
0
        private void ConfigureHandlers()
        {
            var redis = ConnectionMultiplexer.Connect("localhost");
            var brandView = new OrderView(new RedisReadModelRepository<OrderDto>(redis.GetDatabase()));
            ServiceLocator.BrandView = brandView;

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

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

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

            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));

            var bus = new RabbitMqBus(b);

            ServiceLocator.Bus = bus;
        }
예제 #2
0
        private void ConfigureHandlers()
        {
            var redis       = ConnectionMultiplexer.Connect("localhost");
            var productView = new ProductView(new RedisRepository <ProductModel>(redis.GetDatabase()));

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

            var subscriptionName = "Product_readmodel";
            var topicFilter      = "Product.Common.Events";

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

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

            ServiceLocator.Bus         = new RabbitMqBus(bus);
            ServiceLocator.ProductView = productView;
        }
예제 #3
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 = "Microservices_Products_ReadModels_API";
            var topicFilter1     = "Microservices.Products.Infrastructure.Events";

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

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

            var bus = new RabbitMqBus(b);

            ServiceLocator.Bus = bus;
        }
예제 #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <ServiceLocator>(sp =>
            {
                ServiceLocator locator = new ServiceLocator();

                var b       = RabbitHutch.CreateBus("host=192.168.1.105;username=test;password=test");
                var bus     = new RabbitMqBus(b);
                locator.Bus = bus;

                var messageBusEndPoint = "Sales_service";
                var topicFilter        = "Products.Common.Events";

                IPAddress ip             = IPAddress.Parse("192.168.1.105");
                var eventStorePort       = 1113;
                var eventStoreConnection = EventStoreConnection.Create(new IPEndPoint(ip, eventStorePort));
                // var connectionString = "ConnectTo=tcp://admin:[email protected]:12900; Gossip Timeout = 500";
                // var eventStoreConnection = EventStoreConnection.Create(connectionString);
                eventStoreConnection.ConnectAsync().Wait();
                var repository = new EventStoreRepository(eventStoreConnection, bus);

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

                var eventMappings = new EventHandlerDiscovery()
                                    .Scan(new ProductEventsHandler(locator))
                                    .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));


                return(locator);
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
예제 #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddSingleton <ServiceLocator>(sp =>
            {
                ServiceLocator locator = new ServiceLocator();

                var redis         = ConnectionMultiplexer.Connect("192.168.1.105:6379,name=venom");
                var brandView     = new OrderView(new RedisReadModelRepository <OrderDto>(redis.GetDatabase()));
                locator.BrandView = brandView;

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

                var messageBusEndPoint = "Sales_readmodel";
                var topicFilter        = "Sales.Common.Events";

                var b = RabbitHutch.CreateBus("host=192.168.1.105;username=test;password=test");

                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));

                var bus = new RabbitMqBus(b);

                locator.Bus = bus;


                return(locator);
            });
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
        }
예제 #6
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));
        }
예제 #7
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));
        }
예제 #8
0
        private void ConfigureHandlers()
        {
            //Should get this from a config setting instead of hardcoding it.
            var redis       = ConnectionMultiplexer.Connect("localhost");
            var productView = new ProductView(new RedisReadModelRepository <ProductDto>(redis.GetDatabase()));

            ServiceLocator.ProductView = productView;

            IBaristaClient masterDataClient = new BaristaClient();

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

            var subscriptionName = "journeydesigner_readmodel";
            var topicFilter1     = "MasterData.Common.Events";
            var topicFilter2     = "Barista.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).WithTopic(topicFilter2));

            var bus = new RabbitMqBus(b);

            ServiceLocator.Bus = bus;
        }