public async Task CreateConsumerAndStart()
        {
            await topologer.CreateQueueAsync("TestConsumerQueue").ConfigureAwait(false);

            var con = new Consumer(channelPool, "TestMessageConsumer");
            await con.StartConsumerAsync().ConfigureAwait(false);
        }
Exemple #2
0
        private async Task BuildConsumerTopology()
        {
            foreach (var consumer in Consumers)
            {
                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.QueueName))
                {
                    await Topologer.CreateQueueAsync(consumer.Value.ConsumerOptions.QueueName).ConfigureAwait(false);
                }

                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.TargetQueueName))
                {
                    await Topologer.CreateQueueAsync(consumer.Value.ConsumerOptions.TargetQueueName).ConfigureAwait(false);
                }

                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.ErrorSuffix) && !string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.ErrorQueueName))
                {
                    await Topologer.CreateQueueAsync(consumer.Value.ConsumerOptions.ErrorQueueName).ConfigureAwait(false);
                }

                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.AltSuffix) && !string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.AltQueueName))
                {
                    await Topologer.CreateQueueAsync(consumer.Value.ConsumerOptions.AltQueueName).ConfigureAwait(false);
                }
            }
        }
        public async Task CreateAndBindQueueAsync()
        {
            var options = new RabbitOptions();

            options.FactoryOptions.Uri = new Uri("amqp://*****:*****@localhost:5672/");

            var top   = new Topologer(options);
            var error = await top.CreateExchangeAsync("TestExchangeTest", "direct", false, false, null).ConfigureAwait(false);

            Assert.False(error);

            error = await top.CreateQueueAsync("TestQueueTest", false, false, false, null).ConfigureAwait(false);

            Assert.False(error);

            error = await top.BindQueueToExchangeAsync("TestQueueTest", "TestExchangeTest", "TestRoutingKeyTest", null).ConfigureAwait(false);

            Assert.False(error);

            error = await top.DeleteExchangeAsync("TestExchangeTest").ConfigureAwait(false);

            Assert.False(error);

            error = await top.DeleteQueueAsync("TestQueueTest").ConfigureAwait(false);

            Assert.False(error);
        }
        public async Task CreateQueueAsync()
        {
            var options = new RabbitOptions();

            options.FactoryOptions.Uri = new Uri("amqp://*****:*****@localhost:5672/");

            var top   = new Topologer(options);
            var error = await top.CreateQueueAsync("TestQueueTest", false, false, false, null).ConfigureAwait(false);

            Assert.False(error);
        }
Exemple #5
0
        public async Task CreateQueueAsync()
        {
            var config = new Config();

            config.FactorySettings.Uri = new Uri("amqp://*****:*****@localhost:5672/");

            var top   = new Topologer(config);
            var error = await top.CreateQueueAsync("TestQueueTest", false, false, false, null).ConfigureAwait(false);

            Assert.False(error);
        }
Exemple #6
0
        public async Task CreateQueueWithoutInitializeAsync()
        {
            var config = new Config();

            config.FactorySettings.Uri = new Uri("amqp://*****:*****@localhost:5672/");

            var top = new Topologer(config);

            await Assert
            .ThrowsAsync <InvalidOperationException>(() => top.CreateQueueAsync("TestQueue", false, false, false, null))
            .ConfigureAwait(false);
        }
Exemple #7
0
        private static async Task SetupAsync()
        {
            var sw = Stopwatch.StartNew();

            config = await ConfigReader.ConfigFileReadAsync("Config.json");

            channelPool = new ChannelPool(config);

            topologer = new Topologer(channelPool);

            apub1 = new Publisher(channelPool, new byte[] { });
            apub2 = new Publisher(channelPool, new byte[] { });
            apub3 = new Publisher(channelPool, new byte[] { });
            apub4 = new Publisher(channelPool, new byte[] { });

            await Console.Out.WriteLineAsync("- Creating stress test queues!").ConfigureAwait(false);

            foreach (var kvp in config.ConsumerSettings)
            {
                await topologer
                .DeleteQueueAsync(kvp.Value.QueueName)
                .ConfigureAwait(false);
            }

            foreach (var kvp in config.ConsumerSettings)
            {
                await topologer
                .CreateQueueAsync(kvp.Value.QueueName, true)
                .ConfigureAwait(false);
            }

            await apub1.StartAutoPublishAsync().ConfigureAwait(false);

            await apub2.StartAutoPublishAsync().ConfigureAwait(false);

            await apub3.StartAutoPublishAsync().ConfigureAwait(false);

            await apub4.StartAutoPublishAsync().ConfigureAwait(false);

            con1 = new Consumer(channelPool, "Consumer1");
            con2 = new Consumer(channelPool, "Consumer2");
            con3 = new Consumer(channelPool, "Consumer3");
            con4 = new Consumer(channelPool, "Consumer4");
            sw.Stop();

            await Console
            .Out
            .WriteLineAsync($"- Setup has finished in {sw.ElapsedMilliseconds} ms.")
            .ConfigureAwait(false);
        }
Exemple #8
0
        public async Task CreateQueueWithArgsAsync()
        {
            var config = new Config();

            config.FactorySettings.Uri = new Uri("amqp://*****:*****@localhost:5672/");

            var top = new Topologer(config);
            await top.InitializeAsync().ConfigureAwait(false);


            var args = new Dictionary <string, object>()
            {
                { "Test", "Value" }
            };
            var error = await top
                        .CreateQueueAsync("TestQueueTest", false, false, false, args)
                        .ConfigureAwait(false);

            Assert.False(error);
        }
Exemple #9
0
        public async Task AutoPublishAndConsume()
        {
            await topologer.CreateQueueAsync("TestAutoPublisherConsumerQueue").ConfigureAwait(false);

            await publisher.StartAutoPublishAsync().ConfigureAwait(false);

            const ulong count = 10000;

            var processReceiptsTask = ProcessReceiptsAsync(publisher, count);
            var publishLettersTask  = PublishLettersAsync(publisher, count);
            var consumeMessagesTask = ConsumeMessagesAsync(consumer, count);

            while (!publishLettersTask.IsCompleted)
            {
                await Task.Delay(1).ConfigureAwait(false);
            }

            while (!processReceiptsTask.IsCompleted)
            {
                await Task.Delay(1).ConfigureAwait(false);
            }

            await publisher.StopAutoPublishAsync().ConfigureAwait(false);

            while (!consumeMessagesTask.IsCompleted)
            {
                await Task.Delay(1).ConfigureAwait(false);
            }

            Assert.True(publishLettersTask.IsCompletedSuccessfully);
            Assert.True(processReceiptsTask.IsCompletedSuccessfully);
            Assert.True(consumeMessagesTask.IsCompletedSuccessfully);
            Assert.False(processReceiptsTask.Result);
            Assert.False(consumeMessagesTask.Result);

            await topologer.DeleteQueueAsync("TestAutoPublisherConsumerQueue").ConfigureAwait(false);
        }
Exemple #10
0
        private static async Task SetupAsync()
        {
            var sw = Stopwatch.StartNew();

            options = await JsonFileReader.ReadFileAsync <Options>("Config.json");

            channelPool = new ChannelPool(options);

            topologer = new Topologer(channelPool);

            apub1 = new Publisher(
                channelPool,
                _serializationProvider,
                _encryptionProvider,
                _compressionProvider);

            apub2 = new Publisher(
                channelPool,
                _serializationProvider,
                _encryptionProvider,
                _compressionProvider);

            apub3 = new Publisher(
                channelPool,
                _serializationProvider,
                _encryptionProvider,
                _compressionProvider);

            apub4 = new Publisher(
                channelPool,
                _serializationProvider,
                _encryptionProvider,
                _compressionProvider);

            await Console.Out.WriteLineAsync("- Creating stress test queues!").ConfigureAwait(false);

            foreach (var kvp in options.ConsumerOptions)
            {
                await topologer
                .DeleteQueueAsync(kvp.Value.QueueName)
                .ConfigureAwait(false);
            }

            foreach (var kvp in options.ConsumerOptions)
            {
                await topologer
                .CreateQueueAsync(kvp.Value.QueueName, true)
                .ConfigureAwait(false);
            }

            await apub1.StartAutoPublishAsync().ConfigureAwait(false);

            await apub2.StartAutoPublishAsync().ConfigureAwait(false);

            await apub3.StartAutoPublishAsync().ConfigureAwait(false);

            await apub4.StartAutoPublishAsync().ConfigureAwait(false);

            con1 = new Consumer(channelPool, "Consumer1");
            con2 = new Consumer(channelPool, "Consumer2");
            con3 = new Consumer(channelPool, "Consumer3");
            con4 = new Consumer(channelPool, "Consumer4");
            sw.Stop();

            await Console
            .Out
            .WriteLineAsync($"- Setup has finished in {sw.ElapsedMilliseconds} ms.")
            .ConfigureAwait(false);
        }
Exemple #11
0
        private async Task BuildConsumerTopologyAsync()
        {
            foreach (var consumer in Consumers)
            {
                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.QueueName))
                {
                    if (consumer.Value.ConsumerOptions.QueueArgs == null ||
                        consumer.Value.ConsumerOptions.QueueArgs.Count == 0)
                    {
                        await Topologer
                        .CreateQueueAsync(consumer.Value.ConsumerOptions.QueueName)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await Topologer
                        .CreateQueueAsync(
                            consumer.Value.ConsumerOptions.QueueName,
                            true,
                            false,
                            false,
                            consumer.Value.ConsumerOptions.QueueArgs)
                        .ConfigureAwait(false);
                    }
                }

                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.TargetQueueName))
                {
                    if (consumer.Value.ConsumerOptions.TargetQueueArgs == null ||
                        consumer.Value.ConsumerOptions.TargetQueueArgs.Count == 0)
                    {
                        await Topologer
                        .CreateQueueAsync(consumer.Value.ConsumerOptions.TargetQueueName)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await Topologer
                        .CreateQueueAsync(
                            consumer.Value.ConsumerOptions.TargetQueueName,
                            true,
                            false,
                            false,
                            consumer.Value.ConsumerOptions.TargetQueueArgs)
                        .ConfigureAwait(false);
                    }
                }

                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.ErrorSuffix) &&
                    !string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.ErrorQueueName))
                {
                    if (consumer.Value.ConsumerOptions.ErrorQueueArgs == null ||
                        consumer.Value.ConsumerOptions.ErrorQueueArgs.Count == 0)
                    {
                        await Topologer
                        .CreateQueueAsync(consumer.Value.ConsumerOptions.ErrorQueueName)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await Topologer
                        .CreateQueueAsync(
                            consumer.Value.ConsumerOptions.ErrorQueueName,
                            true,
                            false,
                            false,
                            consumer.Value.ConsumerOptions.ErrorQueueArgs)
                        .ConfigureAwait(false);
                    }
                }

                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.AltSuffix) &&
                    !string.IsNullOrWhiteSpace(consumer.Value.ConsumerOptions.AltQueueName))
                {
                    if (consumer.Value.ConsumerOptions.AltQueueArgs == null ||
                        consumer.Value.ConsumerOptions.AltQueueArgs.Count == 0)
                    {
                        await Topologer
                        .CreateQueueAsync(consumer.Value.ConsumerOptions.AltQueueName)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await Topologer
                        .CreateQueueAsync(
                            consumer.Value.ConsumerOptions.AltQueueName,
                            true,
                            false,
                            false,
                            consumer.Value.ConsumerOptions.AltQueueArgs)
                        .ConfigureAwait(false);
                    }
                }
            }
        }
        private async Task FinishSettingUpConsumersAsync()
        {
            foreach (var consumer in Consumers)
            {
                consumer.Value.HashKey = _hashKey;
                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerSettings.QueueName))
                {
                    if (consumer.Value.ConsumerSettings.QueueArgs == null)
                    {
                        await Topologer
                        .CreateQueueAsync(consumer.Value.ConsumerSettings.QueueName)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await Topologer
                        .CreateQueueAsync(
                            consumer.Value.ConsumerSettings.QueueName,
                            true,
                            false,
                            false,
                            consumer.Value.ConsumerSettings.QueueArgs)
                        .ConfigureAwait(false);
                    }
                }

                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerSettings.TargetQueueName))
                {
                    if (consumer.Value.ConsumerSettings.TargetQueueArgs == null)
                    {
                        await Topologer
                        .CreateQueueAsync(consumer.Value.ConsumerSettings.TargetQueueName)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await Topologer
                        .CreateQueueAsync(
                            consumer.Value.ConsumerSettings.TargetQueueName,
                            true,
                            false,
                            false,
                            consumer.Value.ConsumerSettings.TargetQueueArgs)
                        .ConfigureAwait(false);
                    }
                }

                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerSettings.AltQueueName))
                {
                    if (consumer.Value.ConsumerSettings.AltQueueArgs == null)
                    {
                        await Topologer
                        .CreateQueueAsync(consumer.Value.ConsumerSettings.AltQueueName)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await Topologer
                        .CreateQueueAsync(
                            consumer.Value.ConsumerSettings.AltQueueName,
                            true,
                            false,
                            false,
                            consumer.Value.ConsumerSettings.AltQueueArgs)
                        .ConfigureAwait(false);
                    }
                }

                if (!string.IsNullOrWhiteSpace(consumer.Value.ConsumerSettings.ErrorSuffix) &&
                    !string.IsNullOrWhiteSpace(consumer.Value.ConsumerSettings.ErrorQueueName))
                {
                    if (consumer.Value.ConsumerSettings.ErrorQueueArgs == null)
                    {
                        await Topologer
                        .CreateQueueAsync(consumer.Value.ConsumerSettings.ErrorQueueName)
                        .ConfigureAwait(false);
                    }
                    else
                    {
                        await Topologer
                        .CreateQueueAsync(
                            consumer.Value.ConsumerSettings.ErrorQueueName,
                            true,
                            false,
                            false,
                            consumer.Value.ConsumerSettings.ErrorQueueArgs)
                        .ConfigureAwait(false);
                    }
                }
            }
        }