Пример #1
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();
            configuration.RegisterEQueueComponents();

            var producerSetting = new ProducerSetting
            {
                BrokerAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), PortConfiguration.BrokerProducerPort),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), PortConfiguration.BrokerAdminPort)
            };

            var consumerSetting = new ConsumerSetting
            {
                BrokerAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), PortConfiguration.BrokerConsumerPort),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), PortConfiguration.BrokerAdminPort)
            };

            _applicationMessagePublisher = new ApplicationMessagePublisher(producerSetting);
            _domainEventPublisher = new DomainEventPublisher(producerSetting);
            _exceptionPublisher = new PublishableExceptionPublisher(producerSetting);

            configuration.SetDefault<IMessagePublisher<IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault<IMessagePublisher<IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            _commandConsumer = new CommandConsumer(setting: consumerSetting).Subscribe(TopicConfiguration.AccountCommandTopic);
            _eventConsumer = new DomainEventConsumer(setting: consumerSetting).Subscribe(TopicConfiguration.AccountDomainEventTopic);
            _exceptionConsumer = new PublishableExceptionConsumer(setting: consumerSetting).Subscribe(TopicConfiguration.AccountExceptionTopic);

            return enodeConfiguration;
        }
Пример #2
0
        public async Task ShouldBeAbleToSendAndReceive()
        {
            var receiverLoggerMock = new Mock <ILogger <DomainEventReceiver> >();
            var receiverSection    = configRoot.GetSection("Receiver.Settings");
            var receiverSettings   = GetSettings(receiverSection);
            var receiver           = new DomainEventReceiver(receiverSettings, serviceProvider, receiverLoggerMock.Object);

            var publisherLoggerMock = new Mock <ILogger <DomainEventPublisher> >();
            var publisherSection    = configRoot.GetSection("Publisher.Settings");
            var publisherSettings   = GetSettings(publisherSection);
            var publisher           = new DomainEventPublisher(publisherSettings, publisherLoggerMock.Object);

            var @event = new TestEvent {
                TheInt    = r.Next(),
                TheString = Guid.NewGuid().ToString()
            };

            await publisher.SendAsync(@event);

            receiver.Receive(new Dictionary <string, Type> {
                { typeof(TestEvent).FullName, typeof(TestEvent) }
            });
            var start = DateTime.Now;

            while (TestEvent.Instance == null && (DateTime.Now - start) < new TimeSpan(0, 0, 30))
            {
                Thread.Sleep(1000);
            } // run for 30 seconds
            Assert.Equal(@event.TheString, TestEvent.Instance.TheString);
            Assert.Equal(@event.TheInt, TestEvent.Instance.TheInt);
        }
        public void MessageHandler_ValidMessage_RegisteredHandlerCalled()
        {
            // Arrange
            MyTarget target = new MyTarget();

            var messageConsumer         = Substitute.For <IMessageConsumer>();
            var serviceProvider         = Substitute.For <IServiceProvider>();
            var logger                  = Substitute.For <ILogger <DomainEventDispatcher> >();
            var eventTypeNamingStrategy = Substitute.For <IEventTypeNamingStrategy>();

            eventTypeNamingStrategy.GetEventTypeName(typeof(MyDomainEvent)).Returns(typeof(MyDomainEvent).FullName);

            DomainEventDispatcher dispatcher = new DomainEventDispatcher(
                _subscriberId, target.domainEventHandlers(), messageConsumer, eventTypeNamingStrategy, logger);

            dispatcher.Initialize();

            // Act
            dispatcher.MessageHandler(DomainEventPublisher.MakeMessageForDomainEvent(aggregateType,
                                                                                     aggregateId, new Dictionary <string, string>()
            {
                { MessageHeaders.Id, messageId }
            },
                                                                                     new MyDomainEvent(), eventTypeNamingStrategy), serviceProvider);

            // Assert
            Assert.True(target.Queue.TryPeek(out var dee));
            Assert.NotNull(dee);
            Assert.AreEqual(aggregateId, dee.AggregateId);
            Assert.AreEqual(aggregateType, dee.AggregateType);
            Assert.AreEqual(messageId, dee.EventId);
        }
        public void REGISTER_PROJECTIONS()
        {
            var appendStore = new FileAppendOnlyStore( @"C:\Users\wydev\Documents\GitHub\Clones\lokad-iddd-sample\DomainTests\Store\");
            var eventStore = new EventStore(appendStore);
            var publisher = new DomainEventPublisher(eventStore,0,500);
            var store = new FileDocumentReaderWriter<CustomerId,CustomerTransactions>(@"C:\Users\wydev\Documents\GitHub\Clones\lokad-iddd-sample\DomainTests\Store\",
                                                                                new ViewStrategy(@"C:\Users\wydev\Documents\GitHub\Clones\lokad-iddd-sample\DomainTests\Views\"));
            IDocumentWriter<CustomerId,CustomerTransactions> writer = store;

            var projection = new CustomerTransactionsProjection(writer);

            publisher.RegisterProjection(projection);
            var id = new CustomerId(2);
            var @event = new CustomerCreated
                        {
                            Id = id,
                            Name = "Microsoft",
                            Currency = Currency.Eur
                        };

            IList<IEvent> Changes = new List<IEvent>();
            Changes.Add(@event);

            eventStore.AppendToStream(id,0,Changes);

            publisher.ProcessNewEvents();
        }
        public async Task ShouldPublishEvent2()
        {
            // arange
            string topic     = Guid.NewGuid().ToString();
            var    processor = new TestMessageProcessor();

            host.RegisterMessageProcessor(topic + "TestEvent", processor);

            var settings = publisterSettings.Copy();

            settings.Topic = topic;
            var publisher     = new DomainEventPublisher(settings, new NullLogger <DomainEventPublisher>());
            var correlationId = Guid.NewGuid().ToString();

            // act
            var @event = new TestEvent()
            {
                IntValue = random.Next(), StringValue = Guid.NewGuid().ToString()
            };
            await publisher.PublishAsync(@event, correlationId).ConfigureAwait(false);

            // assert
            Assert.Single(processor.Messages);
            var message = processor.Messages[0];

            Assert.Equal(@event.IntValue, JsonConvert.DeserializeObject <TestEvent>(message.GetBody <string>()).IntValue);
            Assert.Equal(@event.StringValue, JsonConvert.DeserializeObject <TestEvent>(message.GetBody <string>()).StringValue);
            Assert.Equal(@event.GetType().FullName, message.ApplicationProperties[Constants.MESSAGE_TYPE_KEY]);
            Assert.Equal(correlationId, message.Properties.CorrelationId);
        }
Пример #6
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"d:\equeue-store";

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();

            _broker = BrokerController.Create();

            _commandResultProcessor = new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000));
            _commandService = new CommandService(_commandResultProcessor);
            _eventPublisher = new DomainEventPublisher();

            configuration.SetDefault<ICommandService, CommandService>(_commandService);
            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);

            //注意,这里实例化之前,需要确保各种MessagePublisher要先注入到IOC,因为CommandConsumer, DomainEventConsumer都依赖于IMessagePublisher<T>
            _commandConsumer = new CommandConsumer();
            _eventConsumer = new DomainEventConsumer();

            _commandConsumer.Subscribe("NoteCommandTopic");
            _eventConsumer.Subscribe("NoteEventTopic");

            return enodeConfiguration;
        }
        public void Publish_DoesNotExecuteHandlersForASpecificEvent_When_ThereAreNoGeneralSubscribersAndNoSpecificSubscribersForThatEvent()
        {
            //arrange
            var specificHandlerExecuted1 = false;
            var specificHandlerExecuted2 = false;
            var publisher = new DomainEventPublisher();

            Action <DomainEvent> specificEventHandle1 = domainEventParam =>
            {
                specificHandlerExecuted1 = true;
            };

            Action <DomainEvent> specificEventHandle2 = domainEventParam =>
            {
                specificHandlerExecuted2 = true;
            };

            publisher.Subscribe <TestDomainEvent2>(specificEventHandle1);
            publisher.Subscribe <TestDomainEvent2>(specificEventHandle2);

            //act
            publisher.Publish <TestDomainEvent>(new TestDomainEvent());

            //assert
            Assert.AreEqual(false, specificHandlerExecuted1);
            Assert.AreEqual(false, specificHandlerExecuted2);
        }
Пример #8
0
        public E2EBase()
        {
            r = new Random();

            //Config
            var config = new ConfigurationBuilder()
                         .AddJsonFile("config.json")
                         .AddJsonFile("config.user.json", true);
            var configRoot = config.Build();

            //IoC
            var collection = new ServiceCollection();

            collection.AddSingleton <IDomainEventHandler <TestEvent>, TestEventHandler>();
            serviceProvider = collection.BuildServiceProvider();

            eventTypes = new Dictionary <string, Type> {
                { typeof(TestEvent).FullName, typeof(TestEvent) }
            };

            mockLogger = new MockLogger <DomainEventPublisher>();

            var publisherSection = configRoot.GetSection("Publisher.Settings");

            publisherSettings       = GetSettings <DomainEventPublisherSettings>(publisherSection);
            publisherSettings.Topic = publisherSection["Address"];
            publisher = new DomainEventPublisher(publisherSettings, mockLogger);

            var receiverSection = configRoot.GetSection("Receiver.Settings");

            receiverSettings       = GetSettings <DomainEventReceiverSettings>(receiverSection);
            receiverSettings.Queue = publisherSection["Address"];
            enabled = configRoot.GetValue <bool>("EnableE2ETests");
        }
Пример #9
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            var producerSetting = new ProducerSetting
            {
                BrokerAddress      = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerProducerPort),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerAdminPort)
            };
            var consumerSetting = new ConsumerSetting
            {
                BrokerAddress      = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerConsumerPort),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerAdminPort)
            };

            _applicationMessagePublisher = new ApplicationMessagePublisher(producerSetting);
            _domainEventPublisher        = new DomainEventPublisher(producerSetting);
            _exceptionPublisher          = new PublishableExceptionPublisher(producerSetting);

            configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault <IMessagePublisher <IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            _commandConsumer   = new CommandConsumer("ConferenceCommandConsumerGroup", consumerSetting).Subscribe(Topics.ConferenceCommandTopic);
            _eventConsumer     = new DomainEventConsumer("ConferenceEventConsumerGroup", consumerSetting).Subscribe(Topics.ConferenceDomainEventTopic);
            _exceptionConsumer = new PublishableExceptionConsumer("ConferenceExceptionConsumerGroup", consumerSetting).Subscribe(Topics.ConferenceExceptionTopic);

            return(enodeConfiguration);
        }
Пример #10
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"d:\equeue-store";

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();

            _broker = BrokerController.Create();

            _commandResultProcessor = new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000));
            _commandService = new CommandService(_commandResultProcessor);
            _applicationMessagePublisher = new ApplicationMessagePublisher();
            _domainEventPublisher = new DomainEventPublisher();
            _exceptionPublisher = new PublishableExceptionPublisher();

            configuration.SetDefault<ICommandService, CommandService>(_commandService);
            configuration.SetDefault<IMessagePublisher<IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault<IMessagePublisher<IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            _commandConsumer = new CommandConsumer().Subscribe("BankTransferCommandTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer().Subscribe("BankTransferApplicationMessageTopic");
            _eventConsumer = new DomainEventConsumer().Subscribe("BankTransferEventTopic");
            _exceptionConsumer = new PublishableExceptionConsumer().Subscribe("BankTransferExceptionTopic");

            return enodeConfiguration;
        }
        public async Task ShouldScheduleEvent4()
        {
            // arrange
            string topic     = Guid.NewGuid().ToString();
            var    processor = new TestMessageProcessor();

            host.RegisterMessageProcessor("barbaz", processor);

            var settings = publisterSettings.Copy();

            settings.Topic = topic;
            var publisher     = new DomainEventPublisher(settings, new NullLogger <DomainEventPublisher>());
            var correlationId = Guid.NewGuid().ToString();
            var scheduleDate  = DateTime.UtcNow.AddDays(1);

            // act
            var @event = new TestEvent()
            {
                IntValue = random.Next(), StringValue = Guid.NewGuid().ToString()
            };
            await publisher.ScheduleAsync <TestEvent>(@event, scheduleDate, new EventProperties()
            {
                EventType = "foo", Topic = "bar", RoutingKey = "baz", CorrelationId = correlationId
            }).ConfigureAwait(false);

            // assert
            Assert.Single(processor.Messages);
            var message = processor.Messages[0];

            Assert.Equal(@event.IntValue, JsonConvert.DeserializeObject <TestEvent>(message.GetBody <string>()).IntValue);
            Assert.Equal(@event.StringValue, JsonConvert.DeserializeObject <TestEvent>(message.GetBody <string>()).StringValue);
            Assert.Equal("foo", message.ApplicationProperties[Constants.MESSAGE_TYPE_KEY]);
            Assert.Equal(correlationId, message.Properties.CorrelationId);
            ((DateTime)message.MessageAnnotations[new Symbol(Constants.SCHEDULED_ENQUEUE_TIME_UTC)]).Should().BeCloseTo(scheduleDate);
        }
        public void REGISTER_PROJECTIONS()
        {
            var appendStore = new FileAppendOnlyStore(@"C:\Users\wydev\Documents\GitHub\Clones\lokad-iddd-sample\DomainTests\Store\");
            var eventStore  = new EventStore(appendStore);
            var publisher   = new DomainEventPublisher(eventStore, 0, 500);
            var store       = new FileDocumentReaderWriter <CustomerId, CustomerTransactions>(@"C:\Users\wydev\Documents\GitHub\Clones\lokad-iddd-sample\DomainTests\Store\",
                                                                                              new ViewStrategy(@"C:\Users\wydev\Documents\GitHub\Clones\lokad-iddd-sample\DomainTests\Views\"));
            IDocumentWriter <CustomerId, CustomerTransactions> writer = store;

            var projection = new CustomerTransactionsProjection(writer);

            publisher.RegisterProjection(projection);
            var id     = new CustomerId(2);
            var @event = new CustomerCreated
            {
                Id       = id,
                Name     = "Microsoft",
                Currency = Currency.Eur
            };

            IList <IEvent> Changes = new List <IEvent>();

            Changes.Add(@event);

            eventStore.AppendToStream(id, 0, Changes);

            publisher.ProcessNewEvents();
        }
Пример #13
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            _broker = new BrokerController();
            _commandResultProcessor = new CommandResultProcessor();
            _commandService         = new CommandService(_commandResultProcessor);
            _eventPublisher         = new DomainEventPublisher();

            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);

            _commandConsumer = new CommandConsumer();
            _eventConsumer   = new DomainEventConsumer();

            _commandConsumer
            .Subscribe("AccountCommandTopic")
            .Subscribe("SectionCommandTopic")
            .Subscribe("PostCommandTopic")
            .Subscribe("ReplyCommandTopic");
            _eventConsumer
            .Subscribe("AccountEventTopic")
            .Subscribe("SectionEventTopic")
            .Subscribe("PostEventTopic")
            .Subscribe("ReplyEventTopic");

            return(enodeConfiguration);
        }
Пример #14
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            var nameServerEndpoint  = new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort);
            var nameServerEndpoints = new List <IPEndPoint> {
                nameServerEndpoint
            };

            _eventPublisher = new DomainEventPublisher(new ProducerSetting
            {
                NameServerList = nameServerEndpoints
            });
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);

            _commandConsumer = new CommandConsumer(setting: new ConsumerSetting
            {
                NameServerList = nameServerEndpoints
            });
            _commandConsumer
            .Subscribe("AccountCommandTopic")
            .Subscribe("SectionCommandTopic")
            .Subscribe("PostCommandTopic")
            .Subscribe("ReplyCommandTopic");

            return(enodeConfiguration);
        }
        public async Task ShouldPublishWithUsing()
        {
            // arrange
            string         topic     = Guid.NewGuid().ToString();
            List <Message> messages  = new List <Message>();
            var            processor = new TestMessageProcessor(50, messages);

            host.RegisterMessageProcessor(topic + "TestEvent", processor);

            var settings = publisterSettings.Copy();

            settings.Topic = topic;
            var count = 10;

            // act
            using (var publisher = new DomainEventPublisher(settings, new NullLogger <DomainEventPublisher>())) {
                publisher.Connect();
                for (int i = 0; i < count; i++)
                {
                    var @event = new TestEvent()
                    {
                        IntValue = random.Next(), StringValue = Guid.NewGuid().ToString()
                    };
                    await publisher.PublishAsync(@event).ConfigureAwait(false);
                }
            }

            // assert
            Assert.Equal(count, processor.Messages.Count);
        }
Пример #16
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            var producerSetting = new ProducerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.NameServerPort)
                }
            };
            var consumerSetting = new ConsumerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.NameServerPort)
                }
            };

            _applicationMessagePublisher = new ApplicationMessagePublisher(producerSetting);
            _domainEventPublisher        = new DomainEventPublisher(producerSetting);

            configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);

            _commandConsumer = new CommandConsumer("PaymentCommandConsumerGroup", consumerSetting).Subscribe(Topics.PaymentCommandTopic);
            _eventConsumer   = new DomainEventConsumer("PaymentEventConsumerGroup", consumerSetting).Subscribe(Topics.PaymentDomainEventTopic);

            return(enodeConfiguration);
        }
Пример #17
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration   = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"c:\equeue-store";

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();

            _nameServerController = new NameServerController();
            _broker = BrokerController.Create();

            _commandResultProcessor = new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000));
            _commandService         = new CommandService(_commandResultProcessor);
            _eventPublisher         = new DomainEventPublisher();

            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);

            //注意,这里实例化之前,需要确保各种MessagePublisher要先注入到IOC,因为CommandConsumer, DomainEventConsumer都依赖于IMessagePublisher<T>
            _commandConsumer = new CommandConsumer();
            _eventConsumer   = new DomainEventConsumer();

            _commandConsumer.Subscribe("NoteCommandTopic");
            _eventConsumer.Subscribe("NoteEventTopic");

            return(enodeConfiguration);
        }
Пример #18
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration   = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"d:\equeue-store";

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();

            _broker = BrokerController.Create();

            _commandResultProcessor      = new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000));
            _commandService              = new CommandService(_commandResultProcessor);
            _applicationMessagePublisher = new ApplicationMessagePublisher();
            _domainEventPublisher        = new DomainEventPublisher();
            _exceptionPublisher          = new PublishableExceptionPublisher();

            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault <IMessagePublisher <IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            _commandConsumer            = new CommandConsumer().Subscribe("BankTransferCommandTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer().Subscribe("BankTransferApplicationMessageTopic");
            _eventConsumer     = new DomainEventConsumer().Subscribe("BankTransferEventTopic");
            _exceptionConsumer = new PublishableExceptionConsumer().Subscribe("BankTransferExceptionTopic");

            return(enodeConfiguration);
        }
Пример #19
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            _broker = new BrokerController();

            _commandResultProcessor      = new CommandResultProcessor();
            _commandService              = new CommandService(_commandResultProcessor);
            _applicationMessagePublisher = new ApplicationMessagePublisher();
            _domainEventPublisher        = new DomainEventPublisher();
            _exceptionPublisher          = new PublishableExceptionPublisher();

            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault <IMessagePublisher <IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            _commandConsumer            = new CommandConsumer().Subscribe("BankTransferCommandTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer().Subscribe("BankTransferApplicationMessageTopic");
            _eventConsumer     = new DomainEventConsumer().Subscribe("BankTransferEventTopic");
            _exceptionConsumer = new PublishableExceptionConsumer().Subscribe("BankTransferExceptionTopic");

            return(enodeConfiguration);
        }
Пример #20
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            var producerSetting = new ProducerSetting
            {
                BrokerAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerProducerPort),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerAdminPort)
            };
            var consumerSetting = new ConsumerSetting
            {
                BrokerAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerConsumerPort),
                BrokerAdminAddress = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerAdminPort)
            };

            _domainEventPublisher = new DomainEventPublisher(producerSetting);

            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);

            _commandService = new CommandService(null, producerSetting);

            configuration.SetDefault<ICommandService, CommandService>(_commandService);

            _commandConsumer = new CommandConsumer("RegistrationCommandConsumerGroup", consumerSetting).Subscribe(Topics.RegistrationCommandTopic);
            _eventConsumer = new DomainEventConsumer("RegistrationEventConsumerGroup", consumerSetting).Subscribe(Topics.RegistrationDomainEventTopic);
            _applicationMessageConsumer = new ApplicationMessageConsumer("RegistrationMessageConsumerGroup", consumerSetting)
                .Subscribe(Topics.ConferenceApplicationMessageTopic)
                .Subscribe(Topics.PaymentApplicationMessageTopic);

            return enodeConfiguration;
        }
Пример #21
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration   = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"c:\person-equeue-store-test";

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();

            var nameServerEndpoint  = new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort);
            var nameServerEndpoints = new List <IPEndPoint> {
                nameServerEndpoint
            };
            var nameServerSetting = new NameServerSetting()
            {
                BindingAddress = nameServerEndpoint
            };

            _nameServer = new NameServerController(nameServerSetting);

            var brokerSetting = new BrokerSetting(false, brokerStorePath);

            brokerSetting.NameServerList             = nameServerEndpoints;
            brokerSetting.BrokerInfo.ProducerAddress = new IPEndPoint(IPAddress.Loopback, ConfigSettings.BrokerProducerPort).ToAddress();
            brokerSetting.BrokerInfo.ConsumerAddress = new IPEndPoint(IPAddress.Loopback, ConfigSettings.BrokerConsumerPort).ToAddress();
            brokerSetting.BrokerInfo.AdminAddress    = new IPEndPoint(IPAddress.Loopback, ConfigSettings.BrokerAdminPort).ToAddress();
            _broker = BrokerController.Create(brokerSetting);

            var producerSetting = new ProducerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort)
                }
            };
            var consumerSetting = new ConsumerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(IPAddress.Loopback, ConfigSettings.NameServerPort)
                }
            };

            _commandResultProcessor = new CommandResultProcessor(new IPEndPoint(IPAddress.Loopback, 9003));
            _commandService         = new CommandService(_commandResultProcessor, producerSetting);
            _eventPublisher         = new DomainEventPublisher(producerSetting);

            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);

            _commandConsumer = new CommandConsumer(setting: consumerSetting)
                               .Subscribe(Topics.PersonCommandTopic);
            _eventConsumer = new DomainEventConsumer(setting: consumerSetting)
                             .Subscribe(Topics.PersonDomainEventTopic);

            return(enodeConfiguration);
        }
        public static async Task DispatchDomainEventsAsync(this IMediator mediator, DomainEventPublisher ctx)
        {
            var domainEvents = ctx.Events;

            foreach (var domainEvent in domainEvents)
            {
                await mediator.Publish(domainEvent);
            }
        }
Пример #23
0
        public async Task ShouldBeAbleToScheduleAndReceive()
        {
            var tokenSource        = new CancellationTokenSource();
            var token              = tokenSource.Token;
            var receiverLoggerMock = new Mock <ILogger <DomainEventReceiver> >();
            var receiverSection    = configRoot.GetSection("Receiver.Settings");
            var receiverSettings   = GetSettings <ServiceBusReceiverSettings>(receiverSection);
            var receiver           = new DomainEventReceiver(receiverSettings, serviceProvider, receiverLoggerMock.Object);

            receiver.Closed += (r, e) => tokenSource.Cancel();

            var publisherLoggerMock = new Mock <ILogger <DomainEventPublisher> >();
            var publisherSection    = configRoot.GetSection("Publisher.Settings");
            var publisherSettings   = GetSettings <ServiceBusPublisherSettings>(publisherSection);
            var publisher           = new DomainEventPublisher(publisherSettings, publisherLoggerMock.Object);

            var @event = new TestEvent {
                TheInt    = r.Next(),
                TheString = Guid.NewGuid().ToString()
            };

            var correlationId = Guid.NewGuid().ToString();

            try {
                await publisher.ScheduleMessageAsync(@event, correlationId, DateTime.UtcNow.AddSeconds(20));
            } finally {
                Assert.Null(publisher.Error);
            }

            receiver.Receive(new Dictionary <string, Type> {
                { typeof(TestEvent).FullName,
                  typeof(TestEvent) }
            });
            var start   = DateTime.Now;
            var elapsed = DateTime.Now.Subtract(start);

            while (!TestEvent.Instances.ContainsKey(correlationId) && (DateTime.Now - start) < new TimeSpan(0, 0, 30))
            {
                if (token.IsCancellationRequested)
                {
                    if (receiver.Error != null)
                    {
                        Assert.Equal(string.Empty, receiver.Error.Description);
                        Assert.Equal(string.Empty, receiver.Error.Condition);
                    }
                    Assert.True(receiver.Error == null);
                }
                Thread.Sleep(1000);
                elapsed = DateTime.Now.Subtract(start);
            } // run for 30 seconds
            Assert.True(elapsed.TotalSeconds >= 20);
            Assert.True(TestEvent.Instances.Any());
            Assert.True(TestEvent.Instances.ContainsKey(correlationId));
            Assert.NotNull(TestEvent.Instances[correlationId]);
            Assert.Equal(@event.TheString, TestEvent.Instances[correlationId].TheString);
            Assert.Equal(@event.TheInt, TestEvent.Instances[correlationId].TheInt);
        }
Пример #24
0
 public ARWorldApplication(string roomName, EventStore eventStore, DomainEventPublisher domainEventPublisher)
 {
     _roomName            = roomName;
     EventStore           = eventStore;
     DomainEventPublisher = domainEventPublisher;
     DomainEventPublisher.EventStream
     .Subscribe(e => { EventStore.AppendToStream(new IEvent[] { e }); })
     .AddTo(_compositeDisposable);
 }
Пример #25
0
 public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
 {
     var configuration = enodeConfiguration.GetCommonConfiguration();
     configuration.RegisterEQueueComponents();
     _broker = BrokerController.Create();
     _eventPublisher = new DomainEventPublisher();
     configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);
     return enodeConfiguration;
 }
Пример #26
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration,
            bool useMockDomainEventPublisher = false,
            bool useMockApplicationMessagePublisher = false,
            bool useMockPublishableExceptionPublisher = false)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"c:\equeue-store";
            var brokerSetting = new BrokerSetting(brokerStorePath);

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();
            _broker = BrokerController.Create(brokerSetting);
            _commandService = new CommandService(new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9001)));
            _eventPublisher = new DomainEventPublisher();
            _applicationMessagePublisher = new ApplicationMessagePublisher();
            _publishableExceptionPublisher = new PublishableExceptionPublisher();

            if (useMockDomainEventPublisher)
            {
                configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, MockDomainEventPublisher>();
            }
            else
            {
                configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);
            }

            if (useMockApplicationMessagePublisher)
            {
                configuration.SetDefault<IMessagePublisher<IApplicationMessage>, MockApplicationMessagePublisher>();
            }
            else
            {
                configuration.SetDefault<IMessagePublisher<IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            }

            if (useMockPublishableExceptionPublisher)
            {
                configuration.SetDefault<IMessagePublisher<IPublishableException>, MockPublishableExceptionPublisher>();
            }
            else
            {
                configuration.SetDefault<IMessagePublisher<IPublishableException>, PublishableExceptionPublisher>(_publishableExceptionPublisher);
            }

            configuration.SetDefault<ICommandService, CommandService>(_commandService);

            _commandConsumer = new CommandConsumer(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.FirstOffset }).Subscribe("CommandTopic");
            _eventConsumer = new DomainEventConsumer(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.FirstOffset }).Subscribe("EventTopic");
            _applicationMessageConsumer = new ApplicationMessageConsumer(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.FirstOffset }).Subscribe("ApplicationMessageTopic");
            _publishableExceptionConsumer = new PublishableExceptionConsumer(setting: new ConsumerSetting { ConsumeFromWhere = ConsumeFromWhere.FirstOffset }).Subscribe("PublishableExceptionTopic");

            return enodeConfiguration;
        }
Пример #27
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();
            _broker         = BrokerController.Create();
            _eventPublisher = new DomainEventPublisher();
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);
            return(enodeConfiguration);
        }
        public void Subscribe_Handle_Adds_SubscriberWithHandle()
        {
            //arrange
            var publisher = new DomainEventPublisher();
            Action <DomainEvent> handle = domainEvent => { };

            //act
            publisher.Subscribe <DomainEvent>(handle);

            //assert
        }
		public void Subscribe_Handle_Adds_SubscriberWithHandle()
		{
			//arrange
			var publisher = new DomainEventPublisher();
			Action<DomainEvent> handle = domainEvent => { };

			//act
			publisher.Subscribe<DomainEvent>(handle);

			//assert
		}
        public void Publish_ExecutesOnlySpecificAndGeneralHandlersForEvent_When_ThereIsAMixOfGeneralSubscribersAndSpecificSubcribersForThatEventAndSpecificSubscribersForOtherEvents()
        {
            //arrange
            var generalHandlerExecuted1       = false;
            var generalHandlerExecuted2       = false;
            var specificHandlerExecuted1      = false;
            var specificHandlerExecuted2      = false;
            var specificOtherHandlerExecuted1 = false;
            var specificOtherHandlerExecuted2 = false;
            var publisher       = new DomainEventPublisher();
            var testDomainEvent = new TestDomainEvent();
            Action <DomainEvent> generalEventHandle1 = domainEventParam =>
            {
                generalHandlerExecuted1 = true;
            };
            Action <DomainEvent> generalEventHandle2 = domainEventParam =>
            {
                generalHandlerExecuted2 = true;
            };
            Action <DomainEvent> specificEventHandle1 = domainEventParam =>
            {
                specificHandlerExecuted1 = true;
            };
            Action <DomainEvent> specificEventHandle2 = domainEventParam =>
            {
                specificHandlerExecuted2 = true;
            };
            Action <DomainEvent> specificOtherEventHandle1 = domainEventParam =>
            {
                specificOtherHandlerExecuted1 = true;
            };
            Action <DomainEvent> specificOtherEventHandle2 = domainEventParam =>
            {
                specificOtherHandlerExecuted2 = true;
            };

            publisher.Subscribe <DomainEvent>(generalEventHandle1);
            publisher.Subscribe <DomainEvent>(generalEventHandle2);
            publisher.Subscribe <TestDomainEvent>(specificEventHandle1);
            publisher.Subscribe <TestDomainEvent>(specificEventHandle2);
            publisher.Subscribe <TestDomainEvent2>(specificOtherEventHandle1);
            publisher.Subscribe <TestDomainEvent2>(specificOtherEventHandle2);

            //act
            publisher.Publish <TestDomainEvent>(new TestDomainEvent());

            //assert
            Assert.AreEqual(true, generalHandlerExecuted1);
            Assert.AreEqual(true, generalHandlerExecuted2);
            Assert.AreEqual(true, specificHandlerExecuted1);
            Assert.AreEqual(true, specificHandlerExecuted2);
            Assert.AreEqual(false, specificOtherHandlerExecuted1);
            Assert.AreEqual(false, specificOtherHandlerExecuted2);
        }
    // this is a separate method because you will need to set employerId
    // from multiple locations and should only ever call SetEmployerId
    // internally
    public Result ChangeEmployer(EmployerId id)
    {
        var result = this.SetEmployerId(id);

        if (result.Success)
        {
            DomainEventPublisher.Publish(
                new EmployeeEmployerChanged(id, this.id));
        }
        return(result);
    }
Пример #32
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var assemblies = new[] { Assembly.GetExecutingAssembly() };
            enodeConfiguration.RegisterTopicProviders(assemblies);

            var configuration = enodeConfiguration.GetCommonConfiguration();
            configuration.RegisterEQueueComponents();

            _eventPublisher = new DomainEventPublisher();
            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);
            return enodeConfiguration;
        }
		public void Subscribe_DomainEventSubscriber_Adds_DomainEventSubscriber()
		{
			//arrange
			var publisher = new DomainEventPublisher();
			Action<DomainEvent> handle = domainEvent => { };
			var domainEventSubscriber = new DomainEventSubscriber(handle, typeof(DomainEvent));

			//act
			publisher.Subscribe(domainEventSubscriber);
			
			//assert
		}
        public void Subscribe_DomainEventSubscriber_Adds_DomainEventSubscriber()
        {
            //arrange
            var publisher = new DomainEventPublisher();
            Action <DomainEvent> handle = domainEvent => { };
            var domainEventSubscriber   = new DomainEventSubscriber(handle, typeof(DomainEvent));

            //act
            publisher.Subscribe(domainEventSubscriber);

            //assert
        }
Пример #35
0
        public async Task ShouldReceiveMessage_RejectAsync()
        {
            receiverSettings.Queue = Guid.NewGuid().ToString();

            List <Message> messages = new List <Message>();

            host.RegisterMessageProcessor(receiverSettings.Queue + "TestEvent", new TestMessageProcessor(50, messages));
            linkProcessor = new TestLinkProcessor();
            host.RegisterLinkProcessor(linkProcessor);

            int count = 1;

            publisterSettings.Topic = receiverSettings.Queue;
            var publisher = new DomainEventPublisher(publisterSettings, new NullLogger <DomainEventPublisher>());

            for (int i = 0; i < count; i++)
            {
                var @event = new TestEvent()
                {
                    IntValue = random.Next(), StringValue = Guid.NewGuid().ToString()
                };
                await publisher.PublishAsync(@event).ConfigureAwait(false);
            }

            var source = new TestMessageSource(new Queue <Message>(messages));

            host.RegisterMessageSource(receiverSettings.Queue, source);
            using (var receiver = new DomainEventReceiver(receiverSettings, provider, new NullLogger <DomainEventReceiver>())) {
                receiver.Start(eventTypes);
                int waits = 0;
                do
                {
                    await Task.Delay(1000).ConfigureAwait(false);

                    if (receiver.Link.LinkState == LinkState.Attached)
                    {
                        break;
                    }
                    waits++;
                }while (waits < 20);

                for (int i = 0; i < count; i++)
                {
                    var message = receiver.Receive(TimeSpan.FromSeconds(10));
                    message.Reject();
                    await Task.Delay(1000).ConfigureAwait(false);
                }
            }

            Assert.Equal(count, source.DeadLetterCount);
            Assert.Equal(0, source.Count);
        }
Пример #36
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            //生产者设置
            var producerSetting = new ProducerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.NameServerPort)
                }
            };
            //消费者设置
            var consumerSetting = new ConsumerSetting
            {
                NameServerList = new List <IPEndPoint> {
                    new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.NameServerPort)
                }
            };

            //命令生成者
            _commandService = new CommandService();
            _commandService.Initialize(setting: producerSetting);
            //事件生产者
            _domainEventPublisher = new DomainEventPublisher().Initialize(setting: producerSetting);
            //消息生产者
            _applicationMessagePublisher = new ApplicationMessagePublisher().Initialize(setting: producerSetting);
            //异常生产者
            _exceptionPublisher = new PublishableExceptionPublisher().Initialize(setting: producerSetting);

            configuration.SetDefault <ICommandService, CommandService>(_commandService);
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault <IMessagePublisher <IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault <IMessagePublisher <IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            //命令消费者
            _commandConsumer = new CommandConsumer().Initialize(setting: consumerSetting)
                               .Subscribe(Topics.ShopCommandTopic);
            //事件消费者
            _eventConsumer = new DomainEventConsumer().Initialize(setting: consumerSetting)
                             .Subscribe(Topics.ShopDomainEventTopic);

            //消息消费者
            _applicationMessageConsumer = new ApplicationMessageConsumer().Initialize(setting: consumerSetting)
                                          .Subscribe(Topics.ShopApplicationMessageTopic);
            //异常消费者
            _exceptionConsumer = new PublishableExceptionConsumer().Initialize(setting: consumerSetting)
                                 .Subscribe(Topics.ShopExceptionTopic);

            return(enodeConfiguration);
        }
Пример #37
0
        public static ENodeConfiguration InitializeEQueue(this ENodeConfiguration enodeConfiguration)
        {
            if (_isEQueueInitialized)
            {
                return(enodeConfiguration);
            }

            _commandService = new CommandService();
            _eventPublisher = new DomainEventPublisher();

            _isEQueueInitialized = true;

            return(enodeConfiguration);
        }
Пример #38
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            _domainEventPublisher = new DomainEventPublisher();
            configuration.SetDefault <IMessagePublisher <DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);

            _commandService = new CommandService();
            configuration.SetDefault <ICommandService, CommandService>(_commandService);

            return(enodeConfiguration);
        }
Пример #39
0
        public void CanPublicDomainEvent()
        {
            var result   = "";
            var expected = "test-message";

            using (DomainEventPublisher.Current()
                   .Register <MyDomainEvent>(eventArgs => result = eventArgs.Message))
            {
                DomainEventPublisher.Current()
                .Publish(new MyDomainEvent(expected));
            }

            Assert.That(result, Is.EqualTo(expected));
        }
Пример #40
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"d:\equeue-store";

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();
            _broker = BrokerController.Create(new BrokerSetting { NotifyWhenMessageArrived = false });
            _eventPublisher = new DomainEventPublisher();
            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);
            return enodeConfiguration;
        }
Пример #41
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            _domainEventPublisher = new DomainEventPublisher();

            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);

            _commandConsumer = new CommandConsumer();

            _commandConsumer.Subscribe("NoteCommandTopic1");
            _commandConsumer.Subscribe("NoteCommandTopic2");

            return enodeConfiguration;
        }
		public void Publish_ExecutesHandleForEvent_When_ThereIsOneGeneralSubscriber()
		{
			//arrange
			var generalHandlerExecuted = false;			
			var publisher = new DomainEventPublisher();
			var testDomainEvent = new TestDomainEvent();			
			Action<DomainEvent> domainEventHandle = domainEventParam =>
			{
				generalHandlerExecuted = true;
			};

			publisher.Subscribe<DomainEvent>(domainEventHandle);

			//act
			publisher.Publish<TestDomainEvent>(new TestDomainEvent());

			//assert
			Assert.AreEqual(true, generalHandlerExecuted);			
		}
		public void Publish_ExecutesHandleForEvent_When_ThereIsOneSpecificSubscriber()
		{
			//arrange			
			var specificHandlerExecuted = false;
			var publisher = new DomainEventPublisher();
			var testDomainEvent = new TestDomainEvent();
			
			Action<DomainEvent> testDomainEventHandle = testDomainEventParam => 
			{ 
				specificHandlerExecuted = true; 
			};
			
			publisher.Subscribe<TestDomainEvent>(testDomainEventHandle);
			
			//act
			publisher.Publish<TestDomainEvent>(new TestDomainEvent());
			
			//assert
			Assert.AreEqual(specificHandlerExecuted, true);			
		}
Пример #44
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();
            var brokerStorePath = @"d:\equeue-store-test";

            if (Directory.Exists(brokerStorePath))
            {
                Directory.Delete(brokerStorePath, true);
            }

            configuration.RegisterEQueueComponents();

            _broker = BrokerController.Create(new BrokerSetting(brokerStorePath));
            _commandResultProcessor = new CommandResultProcessor(new IPEndPoint(SocketUtils.GetLocalIPV4(), 9000));
            _commandService = new CommandService(_commandResultProcessor);
            _eventPublisher = new DomainEventPublisher();

            configuration.SetDefault<ICommandService, CommandService>(_commandService);
            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);

            _commandConsumer = new CommandConsumer();
            _eventConsumer = new DomainEventConsumer();

            _commandConsumer
                .Subscribe("AccountCommandTopic")
                .Subscribe("SectionCommandTopic")
                .Subscribe("PostCommandTopic")
                .Subscribe("ReplyCommandTopic");
            _eventConsumer
                .Subscribe("AccountEventTopic")
                .Subscribe("SectionEventTopic")
                .Subscribe("PostEventTopic")
                .Subscribe("ReplyEventTopic");

            return enodeConfiguration;
        }
		public void Publish_ExecutesOnlyGeneralHandlersForEvent_When_ThereIsAMixOfGeneralSubscribersAndSpecificSubscribersForOtherEvents()
		{
			//arrange
			var generalHandlerExecuted1 = false;
			var generalHandlerExecuted2 = false;
			var specificHandlerExecuted1 = false;
			var specificHandlerExecuted2 = false;
			var publisher = new DomainEventPublisher();
			var testDomainEvent = new TestDomainEvent();
			Action<DomainEvent> generalEventHandle1 = domainEventParam =>
			{
				generalHandlerExecuted1 = true;
			};
			Action<DomainEvent> generalEventHandle2 = domainEventParam =>
			{
				generalHandlerExecuted2 = true;
			};
			Action<DomainEvent> specificEventHandle1 = domainEventParam =>
			{
				specificHandlerExecuted1 = true;
			};
			Action<DomainEvent> specificEventHandle2 = domainEventParam =>
			{
				specificHandlerExecuted2 = true;
			};

			publisher.Subscribe<DomainEvent>(generalEventHandle1);
			publisher.Subscribe<DomainEvent>(generalEventHandle2);
			publisher.Subscribe<TestDomainEvent2>(specificEventHandle1);
			publisher.Subscribe<TestDomainEvent2>(specificEventHandle2);
			
			//act			
			publisher.Publish<TestDomainEvent>(new TestDomainEvent());			

			//assert
			Assert.AreEqual(true, generalHandlerExecuted1);
			Assert.AreEqual(true, generalHandlerExecuted2);
			Assert.AreEqual(false, specificHandlerExecuted1);
			Assert.AreEqual(false, specificHandlerExecuted2);
		}
		public DomainEvents(DomainEventPublisher publisher)
		{
			_publisher = publisher;
		}
		public void Publish_DoesNotExecuteHandlersForASpecificEvent_When_ThereAreNoGeneralSubscribersAndNoSpecificSubscribersForThatEvent()
		{
			//arrange			
			var specificHandlerExecuted1 = false;
			var specificHandlerExecuted2 = false;
			var publisher = new DomainEventPublisher();			

			Action<DomainEvent> specificEventHandle1 = domainEventParam =>
			{
				specificHandlerExecuted1 = true;
			};

			Action<DomainEvent> specificEventHandle2 = domainEventParam =>
			{
				specificHandlerExecuted2 = true;
			};
			
			publisher.Subscribe<TestDomainEvent2>(specificEventHandle1);
			publisher.Subscribe<TestDomainEvent2>(specificEventHandle2);

			//act
			publisher.Publish<TestDomainEvent>(new TestDomainEvent());

			//assert			
			Assert.AreEqual(false, specificHandlerExecuted1);
			Assert.AreEqual(false, specificHandlerExecuted2);
		}
Пример #48
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            _broker = new BrokerController();
            _commandResultProcessor = new CommandResultProcessor();
            _commandService = new CommandService(_commandResultProcessor);
            _eventPublisher = new DomainEventPublisher();

            configuration.SetDefault<ICommandService, CommandService>(_commandService);
            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_eventPublisher);

            _commandConsumer = new CommandConsumer();
            _eventConsumer = new DomainEventConsumer();

            _commandConsumer
                .Subscribe("AccountCommandTopic")
                .Subscribe("SectionCommandTopic")
                .Subscribe("PostCommandTopic")
                .Subscribe("ReplyCommandTopic");
            _eventConsumer
                .Subscribe("AccountEventTopic")
                .Subscribe("SectionEventTopic")
                .Subscribe("PostEventTopic")
                .Subscribe("ReplyEventTopic");

            return enodeConfiguration;
        }
Пример #49
0
        public static ENodeConfiguration UseEQueue(this ENodeConfiguration enodeConfiguration)
        {
            var configuration = enodeConfiguration.GetCommonConfiguration();

            configuration.RegisterEQueueComponents();

            var producerSetting = new ProducerSetting { BrokerProducerIPEndPoint = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerProducerPort) };
            var consumerSetting = new ConsumerSetting { BrokerConsumerIPEndPoint = new IPEndPoint(SocketUtils.GetLocalIPV4(), ConfigSettings.BrokerConsumerPort) };

            _applicationMessagePublisher = new ApplicationMessagePublisher("ConferenceApplicationMessagePublisher", producerSetting);
            _domainEventPublisher = new DomainEventPublisher("ConferenceDomainEventPublisher", producerSetting);
            _exceptionPublisher = new PublishableExceptionPublisher("ConferencePublishableExceptionPublisher", producerSetting);

            configuration.SetDefault<IMessagePublisher<IApplicationMessage>, ApplicationMessagePublisher>(_applicationMessagePublisher);
            configuration.SetDefault<IMessagePublisher<DomainEventStreamMessage>, DomainEventPublisher>(_domainEventPublisher);
            configuration.SetDefault<IMessagePublisher<IPublishableException>, PublishableExceptionPublisher>(_exceptionPublisher);

            _commandConsumer = new CommandConsumer(
                "ConferenceCommandConsumer",
                "ConferenceCommandConsumerGroup",
                consumerSetting)
            .Subscribe(Topics.ConferenceCommandTopic);

            _eventConsumer = new DomainEventConsumer(
                "ConferenceEventConsumer",
                "ConferenceEventConsumerGroup",
                consumerSetting)
            .Subscribe(Topics.ConferenceDomainEventTopic);

            _exceptionConsumer = new PublishableExceptionConsumer(
                "ConferenceExceptionConsumer",
                "ConferenceExceptionConsumerGroup",
                consumerSetting)
            .Subscribe(Topics.ConferenceExceptionTopic);

            return enodeConfiguration;
        }