Add integration test for message post processor in RabbitTemplate

This commit is contained in:
Dave Syer
2011-07-28 09:12:11 +01:00
parent 9e710f9fa8
commit 10a556b314
2 changed files with 17 additions and 1 deletions

View File

@@ -365,7 +365,7 @@ public class RabbitTemplate extends RabbitAccessor implements RabbitOperations {
channel.basicPublish(exchange, routingKey, false, false,
this.messagePropertiesConverter.fromMessageProperties(message.getMessageProperties(), encoding),
message.getBody());
// Check commit - avoid commit call within a JTA transaction.
// Check if commit needed
if (isChannelLocallyTransacted(channel)) {
// Transacted channel created by this template -> commit.
RabbitUtils.commitIfNecessary(channel);

View File

@@ -30,6 +30,7 @@ import org.junit.Test;
import org.springframework.amqp.AmqpException;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessagePostProcessor;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.SingleConnectionFactory;
@@ -83,6 +84,21 @@ public class RabbitTemplateIntegrationTests {
assertEquals(null, result);
}
@Test
public void testSendAndReceiveWithPostProcessor() throws Exception {
template.convertAndSend(ROUTE, (Object)"message", new MessagePostProcessor() {
public Message postProcessMessage(Message message) throws AmqpException {
message.getMessageProperties().setContentType("text/other");
// message.getMessageProperties().setUserId("foo");
return message;
}
});
String result = (String) template.receiveAndConvert(ROUTE);
assertEquals("message", result);
result = (String) template.receiveAndConvert(ROUTE);
assertEquals(null, result);
}
@Test
public void testSendAndReceive() throws Exception {
template.convertAndSend(ROUTE, "message");