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));
        }
        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 TestSimpleBatchGZippedConfiguredUnzipper()
        {
            var batchingStrategy = new SimpleBatchingStrategy(2, int.MaxValue, 30000);
            var template         = new BatchingRabbitTemplate(batchingStrategy)
            {
                ConnectionFactory = connectionFactory
            };
            var gZipPostProcessor = new GZipPostProcessor
            {
                Level = CompressionLevel.Optimal
            };

            Assert.Equal(CompressionLevel.Optimal, gZipPostProcessor.Level);
            template.SetBeforePublishPostProcessors(gZipPostProcessor);
            template.SetAfterReceivePostProcessors(new GUnzipPostProcessor());
            var props   = new MessageHeaders();
            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.Null(result.Headers.ContentEncoding());
            Assert.Equal("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", Encoding.UTF8.GetString((byte[])result.Payload));
        }