Exemplo n.º 1
0
        public void TestDelayHeader()
        {
            var properties = new RabbitHeaderAccessor();
            var delay      = 100;

            properties.Delay = delay;
            var headers = properties.ToMessageHeaders();

            Assert.Equal(delay, headers.Get <int>(RabbitHeaderAccessor.X_DELAY));
            properties.Delay = null;
            headers          = properties.ToMessageHeaders();
            Assert.False(headers.ContainsKey(RabbitHeaderAccessor.X_DELAY));
        }
        public void TestSimpleBatchDeflaterWithEncoding()
        {
            var batchingStrategy = new SimpleBatchingStrategy(2, int.MaxValue, 30000);
            var template         = new BatchingRabbitTemplate(batchingStrategy)
            {
                ConnectionFactory = connectionFactory
            };
            var deflatorPostProcessor = new DeflaterPostProcessor
            {
                Level = CompressionLevel.Fastest
            };

            template.SetBeforePublishPostProcessors(deflatorPostProcessor);
            var accessor = new RabbitHeaderAccessor(new MessageHeaders())
            {
                ContentEncoding = "foo"
            };
            var props   = accessor.ToMessageHeaders();
            var message = Message.Create(Encoding.UTF8.GetBytes("foo"), props);

            template.Send(string.Empty, ROUTE, message);
            message = Message.Create(Encoding.UTF8.GetBytes("bar"), props);
            template.Send(string.Empty, ROUTE, message);
            var result = Receive(template);

            Assert.Equal("deflate:foo", result.Headers.ContentEncoding());
            var unzipper = new InflaterPostProcessor();
            var unzip    = unzipper.PostProcessMessage(result);

            Assert.Equal("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", Encoding.UTF8.GetString((byte[])unzip.Payload));
        }
        public void TestSimpleBatchGZippedWithEncodingInflated()
        {
            var batchingStrategy = new SimpleBatchingStrategy(2, int.MaxValue, 30000);
            var template         = new BatchingRabbitTemplate(batchingStrategy)
            {
                ConnectionFactory = connectionFactory
            };
            var gZipPostProcessor = new GZipPostProcessor();

            template.SetBeforePublishPostProcessors(gZipPostProcessor);
            template.SetAfterReceivePostProcessors(new DelegatingDecompressingPostProcessor());
            var accessor = new RabbitHeaderAccessor(new MessageHeaders())
            {
                ContentEncoding = "foo"
            };
            var props   = accessor.ToMessageHeaders();
            var message = Message.Create(Encoding.UTF8.GetBytes("foo"), props);

            template.Send(string.Empty, ROUTE, message);
            message = Message.Create(Encoding.UTF8.GetBytes("bar"), props);
            template.Send(string.Empty, ROUTE, message);
            Thread.Sleep(100);
            var output = template.ReceiveAndConvert <byte[]>(ROUTE);

            Assert.NotNull(output);
            Assert.Equal("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", Encoding.UTF8.GetString(output));
        }