Example #1
0
        private static async Task PublishLettersAsync(Publisher apub, string queueName, ulong count)
        {
            var sw = Stopwatch.StartNew();

            for (ulong i = 0; i < count; i++)
            {
                var letter = RandomData.CreateSimpleRandomLetter(queueName, MessageSize);
                letter.Envelope.RoutingOptions.DeliveryMode = 1;
                letter.LetterId = i;

                await apub.QueueLetterAsync(letter).ConfigureAwait(false);

                if (letter.LetterId % 10_000 == 0)
                {
                    await Console
                    .Out
                    .WriteLineAsync($"- QueueName ({queueName}) is publishing letter {letter.LetterId}")
                    .ConfigureAwait(false);
                }
            }
            sw.Stop();

            await Console
            .Out
            .WriteLineAsync($"- Finished queueing all letters in {sw.ElapsedMilliseconds / 60_000.0} minutes.")
            .ConfigureAwait(false);
        }
Example #2
0
        public async Task CreateAutoPublisherByConfigQueueAndConcurrentPublish()
        {
            var pub = new Publisher(
                _fixture.Options,
                _fixture.SerializationProvider,
                _fixture.EncryptionProvider,
                _fixture.CompressionProvider);

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

            var         finished = false;
            const ulong count    = 10000;

            await Task.Run(async() =>
            {
                for (ulong i = 0; i < count; i++)
                {
                    var letter      = RandomData.CreateSimpleRandomLetter("AutoPublisherTestQueue");
                    letter.LetterId = i;

                    await pub.QueueLetterAsync(letter).ConfigureAwait(false);
                }

                finished = true;
            }).ConfigureAwait(false);

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

            await pub.StopAutoPublishAsync().ConfigureAwait(false);
        }
Example #3
0
        public async Task CreateAutoPublisherByConfigQueueAndConcurrentPublish()
        {
            var config = new Config();

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

            var pub = new Publisher(config, new byte[] { });
            await pub.StartAutoPublishAsync().ConfigureAwait(false);

            var         finished = false;
            const ulong count    = 10000;

            await Task.Run(async() =>
            {
                for (ulong i = 0; i < count; i++)
                {
                    var letter      = RandomData.CreateSimpleRandomLetter("AutoPublisherTestQueue");
                    letter.LetterId = i;

                    await pub.QueueLetterAsync(letter).ConfigureAwait(false);
                }

                finished = true;
            }).ConfigureAwait(false);

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

            await pub.StopAutoPublishAsync().ConfigureAwait(false);
        }
Example #4
0
        public async Task CreateAutoPublisherAndPublish()
        {
            var pub = new Publisher(channelPool, new byte[] { });

            var letter = RandomData.CreateSimpleRandomLetter("AutoPublisherTestQueue");
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await pub.QueueLetterAsync(letter));
        }
Example #5
0
        public async Task CreateAutoPublisherAndPublish()
        {
            var pub = new Publisher(
                _fixture.ChannelPool,
                _fixture.SerializationProvider,
                _fixture.EncryptionProvider,
                _fixture.CompressionProvider);

            var letter = RandomData.CreateSimpleRandomLetter("AutoPublisherTestQueue");
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await pub.QueueLetterAsync(letter));
        }
Example #6
0
        public async Task CreateAutoPublisherByConfigAndPublish()
        {
            var config = new Config();

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

            var pub = new Publisher(config, new byte[] { });
            await pub.StartAutoPublishAsync().ConfigureAwait(false);

            var letter = RandomData.CreateSimpleRandomLetter("AutoPublisherTestQueue");
            await pub.QueueLetterAsync(letter).ConfigureAwait(false);
        }
Example #7
0
        public async Task CreateAutoPublisherByConfigAndPublish()
        {
            var pub = new Publisher(
                _fixture.Options,
                _fixture.SerializationProvider,
                _fixture.EncryptionProvider,
                _fixture.CompressionProvider);

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

            var letter = RandomData.CreateSimpleRandomLetter("AutoPublisherTestQueue");
            await pub.QueueLetterAsync(letter).ConfigureAwait(false);
        }
Example #8
0
        public async Task PublishWithoutInitializeToQueueAsync()
        {
            var config = new Config();

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

            var pub    = new Publisher(config, new byte[] { });
            var letter = RandomData.CreateSimpleRandomLetter("TestQueue", 2000);

            await Assert
            .ThrowsAsync <InvalidOperationException>(() => pub.PublishAsync(letter, false))
            .ConfigureAwait(false);
        }
Example #9
0
        private async Task PublishLettersAsync(Publisher pub, ulong count)
        {
            var sw = Stopwatch.StartNew();

            for (ulong i = 0; i < count; i++)
            {
                var letter = RandomData.CreateSimpleRandomLetter("AutoPublisherTestQueue");
                letter.LetterId = i;

                await pub.QueueLetterAsync(letter).ConfigureAwait(false);
            }
            sw.Stop();

            output.WriteLine($"Finished queueing all letters in {sw.ElapsedMilliseconds} ms.");
        }
Example #10
0
        public async Task PublishAsync()
        {
            var options = new Options();

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

            var pub = new Publisher(options, new byte[] { });
            await pub
            .StartAutoPublishAsync()
            .ConfigureAwait(false);

            var letter = RandomData.CreateSimpleRandomLetter("TestQueue", 2000);
            await pub
            .PublishAsync(letter, false)
            .ConfigureAwait(false);
        }
Example #11
0
        public async Task PublishWithoutInitializeToQueueAsync()
        {
            var options = new Options();

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

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

            var letter = RandomData.CreateSimpleRandomLetter("TestQueue", 2000);

            await Assert
            .ThrowsAsync <InvalidOperationException>(() => pub.PublishAsync(letter, false))
            .ConfigureAwait(false);
        }
Example #12
0
        public async Task PublishAsync()
        {
            var options = new Options();

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

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

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

            var letter = RandomData.CreateSimpleRandomLetter("TestQueue", 2000);
            await pub
            .PublishAsync(letter, false)
            .ConfigureAwait(false);
        }