public void TestEventJournalPublisherForCategory()
        {
            var eventJournal     = Journal.Open("test-ej-cat");
            var messageBus       = MessageBus.Start("test-bus-cat");
            var topic            = messageBus.OpenTopic("cat-test");
            var journalPublisher = JournalPublisher.From(eventJournal.Name, messageBus.Name, topic.Name);

            var subscriber = new JournalPublisherTestSubscriber();

            topic.Subscribe(subscriber);

            var batch1 = new EntryBatch();

            for (var idx = 0; idx < 3; ++idx)
            {
                batch1.AddEntry("test1type", $"test1instance{idx}");
            }
            eventJournal.Write($"test_1", EntryValue.NoStreamVersion, batch1);

            var batch2 = new EntryBatch();

            for (var idx = 0; idx < 3; ++idx)
            {
                batch2.AddEntry("test2type", $"test2instance{idx}");
            }
            eventJournal.Write("test_2", EntryValue.NoStreamVersion, batch2);

            subscriber.WaitForExpectedMessages(6);
            topic.Close();
            journalPublisher.Close();

            Assert.AreEqual(6, subscriber.HandledMessages.Count);
        }
コード例 #2
0
        public void FromRepositoryToProjection()
        {
            var messageBus       = MessageBus.Start("test-bus-product");
            var topic            = messageBus.OpenTopic("cat-product");
            var journalName      = "product-journal";
            var journalPublisher = JournalPublisher.From(journalName, messageBus.Name, topic.Name);
            var subscriber       = new JournalPublisherTestSubscriber();

            topic.Subscribe(subscriber);

            var repository = new ProductRepository(journalName);

            var product1 = new Product(Guid.NewGuid().ToString(), "dice-fuz-1", "Fuzzy dice.", 999);

            product1.ChangeName("dice-fuzzy-1");
            product1.ChangeDescription("Fuzzy dice, and all.");
            product1.ChangePrice(995);

            repository.Save <Product>(product1);

            var product2 = new Product(Guid.NewGuid().ToString(), "dice-fuz-2", "Fuzzy dice.", 999);

            product2.ChangeName("dice-fuzzy-2");
            product2.ChangeDescription("Fuzzy dice, and all 2.");
            product2.ChangePrice(1000);

            repository.Save <Product>(product2);

            subscriber.WaitForExpectedMessages(8);
            topic.Close();
            journalPublisher.Close();

            Assert.AreEqual(8, subscriber.HandledMessages.Count);
        }
        public void TestEventJournalPublisher()
        {
            var eventJournal      = Journal.Open("test-ej");
            var messageBus        = MessageBus.Start("test-bus");
            var topic1            = messageBus.OpenTopic("test1");
            var topic2            = messageBus.OpenTopic("test2");
            var journalPublisher1 = JournalPublisher.From(eventJournal.Name, messageBus.Name, topic1.Name);
            var journalPublisher2 = JournalPublisher.From(eventJournal.Name, messageBus.Name, topic2.Name);

            var subscriber1 = new JournalPublisherTestSubscriber();

            topic1.Subscribe(subscriber1);

            var batch1 = new EntryBatch();

            for (var idx = 0; idx < 3; ++idx)
            {
                batch1.AddEntry("test1type", $"test1instance{idx}");
            }
            eventJournal.Write("test1", EntryValue.NoStreamVersion, batch1);

            subscriber1.WaitForExpectedMessages(3);
            topic1.Close();
            journalPublisher1.Close();

            Assert.AreEqual(3, subscriber1.HandledMessages.Count);

            var subscriber2 = new JournalPublisherTestSubscriber();

            topic2.Subscribe(subscriber2);

            var batch2 = new EntryBatch();

            for (var idx = 0; idx < 3; ++idx)
            {
                batch2.AddEntry("test2type", $"test2instance{idx}");
            }
            eventJournal.Write("test2", EntryValue.NoStreamVersion, batch2);

            subscriber2.WaitForExpectedMessages(3);
            topic2.Close();
            journalPublisher2.Close();

            Assert.AreEqual(3, subscriber2.HandledMessages.Count);
        }
コード例 #4
0
        public void TestEventJournalPublisher()
        {
            Journal          eventJournal     = Journal.Open("test-ej");
            MessageBus       messageBus       = MessageBus.Start("test-bus");
            Topic            topic            = messageBus.OpenTopic("test-topic");
            JournalPublisher journalPublisher =
                JournalPublisher.From(eventJournal.Name, messageBus.Name, topic.Name);

            JournalPublisherTestSubscriber subscriber = new JournalPublisherTestSubscriber();

            topic.Subscribe(subscriber);

            EntryBatch batch1 = new EntryBatch();

            for (int idx = 0; idx < 3; ++idx)
            {
                batch1.AddEntry("test1type", "test1instance" + idx);
            }
            eventJournal.Write("test1", 0, batch1);

            EntryBatch batch2 = new EntryBatch();

            for (int idx = 0; idx < 3; ++idx)
            {
                batch2.AddEntry("test2type", "test2instance" + idx);
            }
            eventJournal.Write("test2", 0, batch2);

            subscriber.WaitForExpectedMessages(6);

            topic.Close();

            journalPublisher.Close();

            Assert.AreEqual(6, subscriber.handledMessages.Count);
        }