public void TestSimpleBatchGZippedUsingAddAndRemove() { var batchingStrategy = new SimpleBatchingStrategy(2, int.MaxValue, 30000); var template = new BatchingRabbitTemplate(batchingStrategy) { ConnectionFactory = connectionFactory }; var gZipPostProcessor = new GZipPostProcessor(); Assert.Equal(CompressionLevel.Fastest, gZipPostProcessor.Level); template.AddBeforePublishPostProcessors(gZipPostProcessor); var headerPostProcessor = new HeaderPostProcessor(); template.AddBeforePublishPostProcessors(headerPostProcessor); template.RemoveBeforePublishPostProcessor(headerPostProcessor); 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.Equal("gzip", result.Headers.ContentEncoding()); var unzipper = new GUnzipPostProcessor(); var unzip = unzipper.PostProcessMessage(result); Assert.Equal("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", Encoding.UTF8.GetString((byte[])unzip.Payload)); Assert.Null(unzip.Headers.Get <string>("someHeader")); }
public void TestSimpleBatchGZippedConfiguredUnzipperUsingAdd() { 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.AddBeforePublishPostProcessors(gZipPostProcessor); template.AddAfterReceivePostProcessors(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)); }