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

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

Introduction

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

Prototype

public DelegatingDecompressingPostProcessor() 

Source Link

Usage

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

@Test
public void testSimpleBatchGZippedWithEncodingInflated() 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());
    template.setAfterReceivePostProcessors(new DelegatingDecompressingPostProcessor());
    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);
    Thread.sleep(100);/* w  w w  .  j  a v  a  2 s . com*/
    byte[] out = (byte[]) template.receiveAndConvert(ROUTE);
    assertNotNull(out);
    assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(out));
}

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

@Test
public void testCompressionWithContainer() throws Exception {
    final List<Message> received = new ArrayList<Message>();
    final CountDownLatch latch = new CountDownLatch(2);
    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer(this.connectionFactory);
    container.setQueueNames(ROUTE);/*from  w w w  .  ja v  a 2 s .  c o  m*/
    container.setMessageListener((MessageListener) message -> {
        received.add(message);
        latch.countDown();
    });
    container.setReceiveTimeout(100);
    container.setAfterReceivePostProcessors(new DelegatingDecompressingPostProcessor());
    container.afterPropertiesSet();
    container.start();
    try {
        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();
        Message message = new Message("foo".getBytes(), props);
        template.send("", ROUTE, message);
        message = new Message("bar".getBytes(), props);
        template.send("", ROUTE, message);
        assertTrue(latch.await(10, TimeUnit.SECONDS));
        assertEquals(2, received.size());
        assertEquals("foo", new String(received.get(0).getBody()));
        assertEquals(3, received.get(0).getMessageProperties().getContentLength());
        assertEquals("bar", new String(received.get(1).getBody()));
        assertEquals(3, received.get(0).getMessageProperties().getContentLength());
    } finally {
        container.stop();
    }
}

From source file:org.springframework.cloud.stream.binder.rabbit.RabbitBinderTests.java

@Override
public Spy spyOn(final String queue) {
    final RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
    template.setAfterReceivePostProcessors(new DelegatingDecompressingPostProcessor());
    return new Spy() {

        @Override//w w w. j a  va 2 s  . c o m
        public Object receive(boolean expectNull) throws Exception {
            if (expectNull) {
                Thread.sleep(50);
                return template.receiveAndConvert(new RabbitConsumerProperties().getPrefix() + queue);
            }
            Object bar = null;
            int n = 0;
            while (n++ < 100 && bar == null) {
                bar = template.receiveAndConvert(new RabbitConsumerProperties().getPrefix() + queue);
                Thread.sleep(100);
            }
            assertThat(n).isLessThan(100).withFailMessage("Message did not arrive in RabbitMQ");
            return bar;
        }

    };
}

From source file:org.springframework.xd.dirt.integration.bus.rabbit.RabbitMessageBusTests.java

@Override
public Spy spyOn(final String queue) {
    final RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
    template.setAfterReceivePostProcessors(new DelegatingDecompressingPostProcessor());
    return new Spy() {

        @Override/*from  w  w  w.j  a v  a 2  s . c  om*/
        public Object receive(boolean expectNull) throws Exception {
            if (expectNull) {
                Thread.sleep(50);
                return template.receiveAndConvert("xdbus." + queue);
            }
            Object bar = null;
            int n = 0;
            while (n++ < 100 && bar == null) {
                bar = template.receiveAndConvert("xdbus." + queue);
                Thread.sleep(100);
            }
            assertTrue("Message did not arrive in RabbitMQ", n < 100);
            return bar;
        }

    };
}

From source file:org.springframework.xd.dirt.integration.rabbit.RabbitMessageBusTests.java

@Override
public Spy spyOn(final String queue) {
    final RabbitTemplate template = new RabbitTemplate(this.rabbitAvailableRule.getResource());
    template.setAfterReceivePostProcessor(new DelegatingDecompressingPostProcessor());
    return new Spy() {

        @Override//from  ww w.  ja  v  a 2 s.  c o  m
        public Object receive(boolean expectNull) throws Exception {
            if (expectNull) {
                Thread.sleep(50);
                return template.receiveAndConvert("xdbus." + queue);
            }
            Object bar = null;
            int n = 0;
            while (n++ < 100 && bar == null) {
                bar = template.receiveAndConvert("xdbus." + queue);
                Thread.sleep(100);
            }
            assertTrue("Message did not arrive in RabbitMQ", n < 100);
            return bar;
        }

    };
}