示例#1
0
        public async Task PublishManyAsync()
        {
            var options = new RabbitOptions();

            options.FactoryOptions.Uri = new Uri("amqp://*****:*****@localhost:5672/");
            const int letterCount = 10_000;
            const int byteCount   = 500;

            var pub = new Publisher(
                _fixture.ChannelPool,
                _fixture.SerializationProvider,
                _fixture.EncryptionProvider,
                _fixture.CompressionProvider);

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

            var queueNames = new List <string>
            {
                "TestQueue0",
                "TestQueue1",
                "TestQueue2",
                "TestQueue3",
                "TestQueue4",
                "TestQueue5",
                "TestQueue6",
                "TestQueue7",
                "TestQueue8",
                "TestQueue9",
            };

            var letters = MessageExtensions.CreateManySimpleRandomLetters(queueNames, letterCount, byteCount);

            var sw = Stopwatch.StartNew();
            await pub
            .PublishManyAsync(letters, false)
            .ConfigureAwait(false);

            sw.Stop();

            const double kiloByteCount = byteCount / 1000.0;

            _fixture.Output.WriteLine($"Published {letterCount} letters, {kiloByteCount} KB each, in {sw.ElapsedMilliseconds} ms.");

            var rate     = letterCount / (sw.ElapsedMilliseconds / 1000.0);
            var dataRate = rate * kiloByteCount;

            _fixture.Output.WriteLine($"Message Rate: {rate.ToString("0.###")} letters / sec, or {(dataRate / 1000.0).ToString("0.###")} MB/s");
        }