Example usage for org.springframework.amqp.support.postprocessor GUnzipPostProcessor GUnzipPostProcessor

List of usage examples for org.springframework.amqp.support.postprocessor GUnzipPostProcessor GUnzipPostProcessor

Introduction

In this page you can find the example usage for org.springframework.amqp.support.postprocessor GUnzipPostProcessor GUnzipPostProcessor.

Prototype

public GUnzipPostProcessor() 

Source Link

Usage

From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java

@Test
public void testSimpleBatchGZipped() throws Exception {
    BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000);
    BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler);
    template.setConnectionFactory(this.connectionFactory);
    GZipPostProcessor gZipPostProcessor = new GZipPostProcessor();
    assertEquals(Deflater.BEST_SPEED, getStreamLevel(gZipPostProcessor));
    template.setBeforePublishPostProcessors(gZipPostProcessor);
    MessageProperties props = new MessageProperties();
    Message message = new Message("foo".getBytes(), props);
    template.send("", ROUTE, message);
    message = new Message("bar".getBytes(), props);
    template.send("", ROUTE, message);
    message = receive(template);//from  ww  w . j  a  va 2s. co m
    assertEquals("gzip", message.getMessageProperties().getContentEncoding());
    GUnzipPostProcessor unzipper = new GUnzipPostProcessor();
    message = unzipper.postProcessMessage(message);
    assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(message.getBody()));
}

From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java

@Test
public void testSimpleBatchGZippedConfiguredUnzipper() throws Exception {
    BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000);
    BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler);
    template.setConnectionFactory(this.connectionFactory);
    GZipPostProcessor gZipPostProcessor = new GZipPostProcessor();
    gZipPostProcessor.setLevel(Deflater.BEST_COMPRESSION);
    assertEquals(Deflater.BEST_COMPRESSION, getStreamLevel(gZipPostProcessor));
    template.setBeforePublishPostProcessors(gZipPostProcessor);
    template.setAfterReceivePostProcessors(new GUnzipPostProcessor());
    MessageProperties props = new MessageProperties();
    Message message = new Message("foo".getBytes(), props);
    template.send("", ROUTE, message);
    message = new Message("bar".getBytes(), props);
    template.send("", ROUTE, message);
    message = receive(template);//  www. j  a  va 2s. c  o m
    assertNull(message.getMessageProperties().getContentEncoding());
    assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(message.getBody()));
}

From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java

@Test
public void testSimpleBatchGZippedWithEncoding() throws Exception {
    BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000);
    BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler);
    template.setConnectionFactory(this.connectionFactory);
    template.setBeforePublishPostProcessors(new GZipPostProcessor());
    MessageProperties props = new MessageProperties();
    props.setContentEncoding("foo");
    Message message = new Message("foo".getBytes(), props);
    template.send("", ROUTE, message);
    message = new Message("bar".getBytes(), props);
    template.send("", ROUTE, message);
    message = receive(template);/*  ww w.j  a v a 2s  .  c  o  m*/
    assertEquals("gzip:foo", message.getMessageProperties().getContentEncoding());
    GUnzipPostProcessor unzipper = new GUnzipPostProcessor();
    message = unzipper.postProcessMessage(message);
    assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(message.getBody()));
}