List of usage examples for org.springframework.amqp.core Message getBody
public byte[] getBody()
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testSimpleBatch() throws Exception { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); 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);// ww w . j a v a2s . com 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 testSimpleBatchTimeout() throws Exception { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 50); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); MessageProperties props = new MessageProperties(); Message message = new Message("foo".getBytes(), props); template.send("", ROUTE, message); message = receive(template);//from ww w. j a v a2 s . com assertEquals("foo", new String(message.getBody())); }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testSimpleBatchTimeoutMultiple() throws Exception { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 50); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); MessageProperties props = new MessageProperties(); Message message = new Message("foo".getBytes(), props); template.send("", ROUTE, message); template.send("", ROUTE, message); message = receive(template);/*from www . j a v a 2 s. co m*/ assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003foo", new String(message.getBody())); }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testSimpleBatchBufferLimit() throws Exception { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, 8, 50); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); 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);// w ww . ja v a 2 s . co m assertEquals("foo", new String(message.getBody())); message = receive(template); assertEquals("bar", new String(message.getBody())); }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testSimpleBatchBufferLimitMultiple() throws Exception { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, 15, 30000); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); MessageProperties props = new MessageProperties(); Message message = new Message("foo".getBytes(), props); template.send("", ROUTE, message); template.send("", ROUTE, message); message = new Message("bar".getBytes(), props); template.send("", ROUTE, message); template.send("", ROUTE, message); message = receive(template);/*from w w w . j av a 2 s . co m*/ assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003foo", new String(message.getBody())); message = receive(template); assertEquals("\u0000\u0000\u0000\u0003bar\u0000\u0000\u0000\u0003bar", new String(message.getBody())); }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testSimpleBatchBiggerThanBufferLimit() throws Exception { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, 2, 30000); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); 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 w w w .ja v a 2 s . c o m assertEquals("foo", new String(message.getBody())); message = receive(template); assertEquals("bar", new String(message.getBody())); }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test // existing buffered; new message bigger than bufferLimit; released immediately public void testSimpleBatchBiggerThanBufferLimitMultiple() throws Exception { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, 6, 30000); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); MessageProperties props = new MessageProperties(); Message message = new Message("f".getBytes(), props); template.send("", ROUTE, message); message = new Message("bar".getBytes(), props); template.send("", ROUTE, message); message = receive(template);/*from ww w .j av a 2 s . c om*/ assertEquals("f", new String(message.getBody())); message = receive(template); assertEquals("bar", new String(message.getBody())); }
From source file:org.springframework.amqp.rabbit.core.BatchingRabbitTemplateTests.java
@Test public void testSimpleBatchTwoEqualBufferLimit() throws Exception { BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(10, 14, 30000); BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); template.setConnectionFactory(this.connectionFactory); 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);//w w w . java 2 s. c o m 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 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);// w w w. j a v a2 s .c o 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);/*from ww w .j a v a 2s .co m*/ assertNull(message.getMessageProperties().getContentEncoding()); assertEquals("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar", new String(message.getBody())); }