Add integration test for message post processor in RabbitTemplate
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user