コード例 #1
0
        async Task <(IMessageStore, ICheckpointStore)> GetMessageStore(int ttlSecs = 300)
        {
            var              dbStoreProvider = new InMemoryDbStoreProvider();
            IStoreProvider   storeProvider   = new StoreProvider(dbStoreProvider);
            ICheckpointStore checkpointStore = CheckpointStore.Create(storeProvider);
            IMessageStore    messageStore    = new MessageStore(storeProvider, checkpointStore, TimeSpan.FromSeconds(ttlSecs));
            await messageStore.AddEndpoint("module1");

            await messageStore.AddEndpoint("module2");

            return(messageStore, checkpointStore);
        }
コード例 #2
0
        async Task <(IMessageStore, ICheckpointStore, InMemoryDbStore)> GetMessageStore(bool checkEntireQueueOnCleanup, int ttlSecs = 300, int messageCleanupIntervalSecs = 30)
        {
            var              dbStoreProvider = new InMemoryDbStoreProvider();
            IStoreProvider   storeProvider   = new StoreProvider(dbStoreProvider);
            InMemoryDbStore  inMemoryDbStore = dbStoreProvider.GetDbStore("messages") as InMemoryDbStore;
            ICheckpointStore checkpointStore = CheckpointStore.Create(storeProvider);
            IMessageStore    messageStore    = new MessageStore(storeProvider, checkpointStore, TimeSpan.FromSeconds(ttlSecs), checkEntireQueueOnCleanup, messageCleanupIntervalSecs);
            await messageStore.AddEndpoint("module1");

            await messageStore.AddEndpoint("module2");

            return(messageStore, checkpointStore, inMemoryDbStore);
        }
コード例 #3
0
        async Task <(IMessageStore, ICheckpointStore)> GetMessageStore(long initialCheckpointOffset, bool checkEntireQueueOnCleanup, int ttlSecs = 300)
        {
            var            dbStoreProvider = new InMemoryDbStoreProvider();
            IStoreProvider storeProvider   = new StoreProvider(dbStoreProvider);

            IEntityStore <string, CheckpointStore.CheckpointEntity> checkpointUnderlyingStore = storeProvider.GetEntityStore <string, CheckpointStore.CheckpointEntity>($"Checkpoint{Guid.NewGuid().ToString()}");

            if (initialCheckpointOffset >= 0)
            {
                await checkpointUnderlyingStore.Put("module1", new CheckpointStore.CheckpointEntity(initialCheckpointOffset, null, null));

                await checkpointUnderlyingStore.Put("module2", new CheckpointStore.CheckpointEntity(initialCheckpointOffset, null, null));
            }

            ICheckpointStore checkpointStore = new CheckpointStore(checkpointUnderlyingStore);
            IMessageStore    messageStore    = new MessageStore(storeProvider, checkpointStore, TimeSpan.FromSeconds(ttlSecs), checkEntireQueueOnCleanup, 1800);
            await messageStore.AddEndpoint("module1");

            await messageStore.AddEndpoint("module2");

            return(messageStore, checkpointStore);
        }
コード例 #4
0
        public async Task MessageStoreAddRemoveEndpointTest(bool checkEntireQueueOnCleanup)
        {
            // Arrange
            var              dbStoreProvider = new InMemoryDbStoreProvider();
            IStoreProvider   storeProvider   = new StoreProvider(dbStoreProvider);
            ICheckpointStore checkpointStore = CheckpointStore.Create(storeProvider);
            IMessageStore    messageStore    = new MessageStore(storeProvider, checkpointStore, TimeSpan.FromHours(1), checkEntireQueueOnCleanup, 1800);

            // Act
            await messageStore.AddEndpoint("module1");

            for (int i = 0; i < 10; i++)
            {
                await messageStore.Add("module1", this.GetMessage(i), 0);
            }

            // Assert
            IMessageIterator module1Iterator = messageStore.GetMessageIterator("module1");

            Assert.NotNull(module1Iterator);

            IEnumerable <IMessage> batch = await module1Iterator.GetNext(1000);

            List <IMessage> batchItemsAsList = batch.ToList();

            Assert.Equal(10, batchItemsAsList.Count);

            for (int i = 0; i < 10; i++)
            {
                Assert.Equal($"{i}", batchItemsAsList.ElementAt(i).SystemProperties[SystemProperties.MessageId]);
            }

            // Remove
            await messageStore.RemoveEndpoint("module1");

            // Assert
            await Assert.ThrowsAsync <InvalidOperationException>(() => messageStore.Add("module1", this.GetMessage(0), 0));

            Assert.Throws <InvalidOperationException>(() => messageStore.GetMessageIterator("module1"));

            // Act
            await messageStore.AddEndpoint("module1");

            for (int i = 20; i < 30; i++)
            {
                await messageStore.Add("module1", this.GetMessage(i), 0);
            }

            // Assert
            module1Iterator = messageStore.GetMessageIterator("module1");
            Assert.NotNull(module1Iterator);

            batch = await module1Iterator.GetNext(1000);

            batchItemsAsList = batch.ToList();
            Assert.Equal(10, batchItemsAsList.Count);

            for (int i = 20; i < 30; i++)
            {
                Assert.Equal($"{i}", batchItemsAsList.ElementAt(i - 20).SystemProperties[SystemProperties.MessageId]);
            }
        }