Esempio n. 1
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       = MessageExtensions.CreateSimpleRandomLetter("AutoPublisherTestQueue");
                    letter.MessageId = Guid.NewGuid().ToString();
                    await pub.QueueMessageAsync(letter).ConfigureAwait(false);
                }

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

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

            await pub.StopAutoPublishAsync().ConfigureAwait(false);
        }
Esempio n. 2
0
        private static async Task PublishLettersAsync(Publisher apub, string queueName, int count)
        {
            var sw = Stopwatch.StartNew();

            for (int i = 0; i < count; i++)
            {
                var letter = MessageExtensions.CreateSimpleRandomLetter(queueName, MessageSize);
                letter.Envelope.RoutingOptions.DeliveryMode = 1;
                letter.MessageId = Guid.NewGuid().ToString();

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

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

            await Console
            .Out
            .WriteLineAsync($"- Finished queueing all letters in {sw.ElapsedMilliseconds / 60_000.0} minutes.")
            .ConfigureAwait(false);
        }
Esempio n. 3
0
        public async Task PublishToNonExistentQueueAsync()
        {
            var options = new RabbitOptions();

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

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

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

            await pub.PublishAsync(letter, false);

            var tokenSource = new CancellationTokenSource(delay: TimeSpan.FromSeconds(1));

            async Task ReadReceiptAsync(CancellationToken cancellationToken)
            {
                var receiptBuffer = pub.GetReceiptBufferReader();
                await receiptBuffer.WaitToReadAsync(cancellationToken);

                var receipt = receiptBuffer.ReadAsync(cancellationToken);
            }

            await Assert
            .ThrowsAnyAsync <OperationCanceledException>(() => ReadReceiptAsync(tokenSource.Token));
        }
Esempio n. 4
0
        public async Task CreateAutoPublisherAndPublish()
        {
            var pub = new Publisher(
                _fixture.ChannelPool,
                _fixture.SerializationProvider,
                _fixture.EncryptionProvider,
                _fixture.CompressionProvider);

            var letter = MessageExtensions.CreateSimpleRandomLetter("AutoPublisherTestQueue");
            await Assert.ThrowsAsync <InvalidOperationException>(async() => await pub.QueueMessageAsync(letter));
        }
Esempio n. 5
0
        public async Task CreateAutoPublisherByConfigAndPublish()
        {
            var pub = new Publisher(
                _fixture.Options,
                _fixture.SerializationProvider,
                _fixture.EncryptionProvider,
                _fixture.CompressionProvider);

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

            var letter = MessageExtensions.CreateSimpleRandomLetter("AutoPublisherTestQueue");
            await pub.QueueMessageAsync(letter).ConfigureAwait(false);
        }
Esempio n. 6
0
        private async Task PublishLettersAsync(Publisher pub, ulong count)
        {
            var sw = Stopwatch.StartNew();

            for (ulong i = 0; i < count; i++)
            {
                var letter = MessageExtensions.CreateSimpleRandomLetter("AutoPublisherTestQueue");
                letter.MessageId = Guid.NewGuid().ToString();
                await pub.QueueMessageAsync(letter).ConfigureAwait(false);
            }
            sw.Stop();

            _fixture.Output.WriteLine($"Finished queueing all letters in {sw.ElapsedMilliseconds} ms.");
        }
Esempio n. 7
0
        public async Task PublishAsync()
        {
            var options = new RabbitOptions();

            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 = MessageExtensions.CreateSimpleRandomLetter("TestQueue", 2000);
            await pub
            .PublishAsync(letter, false)
            .ConfigureAwait(false);
        }