コード例 #1
0
        public ConsumerTests(ITestOutputHelper output)
        {
            this.output = output;
            options     = JsonFileReader.ReadFileAsync <Options>("TestConfig.json").GetAwaiter().GetResult();

            channelPool   = new ChannelPool(options);
            topologer     = new Topologer(options);
            rabbitService = new RabbitService("Config.json", null, null, null, null);
        }
コード例 #2
0
        public async Task CreateTopologyFromPartialFileAsync()
        {
            var options = await JsonFileReader.ReadFileAsync <RabbitOptions>("TestConfig.json");

            var top = new Topologer(options);
            await top
            .CreateTopologyFromFileAsync("TestPartialTopologyConfig.json")
            .ConfigureAwait(false);
        }
コード例 #3
0
        public async Task CreateConsumerAndInitializeChannelPool()
        {
            var options = await JsonFileReader.ReadFileAsync <Options>("TestConfig.json");

            Assert.NotNull(options);

            var con = new Consumer(options, "TestMessageConsumer");

            Assert.NotNull(con);
        }
コード例 #4
0
ファイル: ConsumerTests.cs プロジェクト: houseofcat/Tesseract
        public async Task CreateConsumer()
        {
            var options = await JsonFileReader.ReadFileAsync <RabbitOptions>("TestConfig.json");

            Assert.NotNull(options);

            var con = new Consumer(options, "TestMessageConsumer");

            Assert.NotNull(con);
        }
コード例 #5
0
        public PublisherConsumerTests(ITestOutputHelper output)
        {
            this.output = output;
            options     = JsonFileReader.ReadFileAsync <Options>("TestConfig.json").GetAwaiter().GetResult();

            var channelPool = new ChannelPool(options);

            topologer = new Topologer(channelPool);

            publisher = new Publisher(channelPool, new byte[] { });
            consumer  = new Consumer(channelPool, "TestAutoPublisherConsumerName");
        }
コード例 #6
0
 /// <summary>
 /// Reads config from a provided file name path. Builds out a RabbitService with instantiated dependencies based on config settings.
 /// </summary>
 /// <param name="fileNamePath"></param>
 /// <param name="passphrase"></param>
 /// <param name="salt"></param>
 /// <param name="loggerFactory"></param>
 /// <param name="processReceiptAsync"></param>
 public RabbitService(string fileNamePath, string passphrase, string salt, ILoggerFactory loggerFactory = null, Func <PublishReceipt, ValueTask> processReceiptAsync = null)
     : this(
         JsonFileReader
         .ReadFileAsync <Options>(fileNamePath)
         .GetAwaiter()
         .GetResult(),
         passphrase,
         salt,
         loggerFactory,
         processReceiptAsync)
 {
 }
コード例 #7
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, 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 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);
        }
コード例 #8
0
 public RabbitService(
     string fileNamePath,
     ISerializationProvider serializationProvider,
     IEncryptionProvider encryptionProvider   = null,
     ICompressionProvider compressionProvider = null,
     ILoggerFactory loggerFactory             = null, Func <PublishReceipt, ValueTask> processReceiptAsync = null)
     : this(
         JsonFileReader
         .ReadFileAsync <Options>(fileNamePath)
         .GetAwaiter()
         .GetResult(),
         serializationProvider,
         encryptionProvider,
         compressionProvider,
         loggerFactory,
         processReceiptAsync)
 {
 }
コード例 #9
0
ファイル: RabbitFixture.cs プロジェクト: houseofcat/Tesseract
        public RabbitFixture()
        {
            CompressionProvider   = new GzipProvider();
            HashingProvider       = new Argon2ID_HashingProvider();
            HashKey               = HashingProvider.GetHashKey(Passphrase, Salt, 32);
            EncryptionProvider    = new AesGcmEncryptionProvider(HashKey);
            SerializationProvider = new Utf8JsonProvider();

            Options = JsonFileReader.ReadFileAsync <RabbitOptions>("RabbitMQ\\TestConfig.json").GetAwaiter().GetResult();

            RabbitService = new RabbitService(
                Options,
                SerializationProvider,
                EncryptionProvider,
                CompressionProvider,
                LoggerFactory
                .Create(
                    builder => builder.AddConsole().SetMinimumLevel(LogLevel.Information)));

            ChannelPool = RabbitService.ChannelPool;
            Topologer   = RabbitService.Topologer;
            Publisher   = RabbitService.Publisher;
        }
コード例 #10
0
ファイル: Topologer.cs プロジェクト: lsfera/Tesseract
        public async Task CreateTopologyFromFileAsync(string fileNamePath)
        {
            if (string.IsNullOrWhiteSpace(fileNamePath))
            {
                throw new ArgumentNullException(nameof(fileNamePath));
            }
            if (!File.Exists(fileNamePath))
            {
                throw new FileNotFoundException(fileNamePath);
            }

            var config = await JsonFileReader
                         .ReadFileAsync <TopologyConfig>(fileNamePath)
                         .ConfigureAwait(false);

            if (config.Exchanges != null)
            {
                for (int i = 0; i < config.Exchanges.Length; i++)
                {
                    try
                    {
                        await CreateExchangeAsync(
                            config.Exchanges[i].Name,
                            config.Exchanges[i].Type,
                            config.Exchanges[i].Durable,
                            config.Exchanges[i].AutoDelete,
                            config.Exchanges[i].Args).ConfigureAwait(false);
                    }
                    catch { }
                }
            }

            if (config.Queues != null)
            {
                for (int i = 0; i < config.Queues.Length; i++)
                {
                    try
                    {
                        await CreateQueueAsync(
                            config.Queues[i].Name,
                            config.Queues[i].Durable,
                            config.Queues[i].Exclusive,
                            config.Queues[i].AutoDelete,
                            config.Queues[i].Args).ConfigureAwait(false);
                    }
                    catch { }
                }
            }

            if (config.ExchangeBindings != null)
            {
                for (int i = 0; i < config.ExchangeBindings.Length; i++)
                {
                    try
                    {
                        await BindExchangeToExchangeAsync(
                            config.ExchangeBindings[i].ChildExchange,
                            config.ExchangeBindings[i].ParentExchange,
                            config.ExchangeBindings[i].RoutingKey,
                            config.ExchangeBindings[i].Args).ConfigureAwait(false);
                    }
                    catch { }
                }
            }

            if (config.QueueBindings != null)
            {
                for (int i = 0; i < config.QueueBindings.Length; i++)
                {
                    try
                    {
                        await BindQueueToExchangeAsync(
                            config.QueueBindings[i].QueueName,
                            config.QueueBindings[i].ExchangeName,
                            config.QueueBindings[i].RoutingKey,
                            config.QueueBindings[i].Args).ConfigureAwait(false);
                    }
                    catch { }
                }
            }
        }