|
18 | 18 |
|
19 | 19 | import static org.hamcrest.Matchers.contains;
|
20 | 20 | import static org.hamcrest.Matchers.containsString;
|
| 21 | +import static org.hamcrest.Matchers.equalTo; |
21 | 22 | import static org.hamcrest.Matchers.instanceOf;
|
| 23 | +import static org.hamcrest.Matchers.is; |
| 24 | +import static org.hamcrest.Matchers.notNullValue; |
22 | 25 | import static org.hamcrest.Matchers.startsWith;
|
23 | 26 | import static org.junit.Assert.assertEquals;
|
24 | 27 | import static org.junit.Assert.assertFalse;
|
|
36 | 39 | import java.util.ArrayList;
|
37 | 40 | import java.util.Arrays;
|
38 | 41 | import java.util.Collection;
|
| 42 | +import java.util.Collections; |
39 | 43 | import java.util.Date;
|
40 | 44 | import java.util.HashMap;
|
41 | 45 | import java.util.List;
|
|
65 | 69 | import org.springframework.amqp.core.Message;
|
66 | 70 | import org.springframework.amqp.core.MessagePostProcessor;
|
67 | 71 | import org.springframework.amqp.core.MessageProperties;
|
| 72 | +import org.springframework.amqp.core.MessagePropertiesBuilder; |
68 | 73 | import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
|
69 | 74 | import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
70 | 75 | import org.springframework.amqp.rabbit.connection.ConnectionFactory;
|
|
111 | 116 | import org.springframework.messaging.handler.annotation.Payload;
|
112 | 117 | import org.springframework.messaging.handler.annotation.SendTo;
|
113 | 118 | import org.springframework.messaging.handler.annotation.support.DefaultMessageHandlerMethodFactory;
|
| 119 | +import org.springframework.messaging.support.GenericMessage; |
114 | 120 | import org.springframework.messaging.support.MessageBuilder;
|
115 | 121 | import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
116 | 122 | import org.springframework.test.annotation.DirtiesContext;
|
@@ -153,7 +159,8 @@ public class EnableRabbitIntegrationTests {
|
153 | 159 | "test.converted", "test.converted.list", "test.converted.array", "test.converted.args1",
|
154 | 160 | "test.converted.args2", "test.converted.message", "test.notconverted.message",
|
155 | 161 | "test.notconverted.channel", "test.notconverted.messagechannel", "test.notconverted.messagingmessage",
|
156 |
| - "test.converted.foomessage", "test.notconverted.messagingmessagenotgeneric", "amqp656dlq"); |
| 162 | + "test.converted.foomessage", "test.notconverted.messagingmessagenotgeneric", "amqp656dlq", |
| 163 | + "test.messaging.message", "test.amqp.message"); |
157 | 164 |
|
158 | 165 | @Autowired
|
159 | 166 | private RabbitTemplate rabbitTemplate;
|
@@ -577,6 +584,26 @@ public void testPrototypeCache() {
|
577 | 584 | assertSame(value, typeCache.get(Foo1.class));
|
578 | 585 | }
|
579 | 586 |
|
| 587 | + @Test |
| 588 | + public void messagingMessageReturned() { |
| 589 | + Message message = org.springframework.amqp.core.MessageBuilder.withBody("\"messaging\"".getBytes()) |
| 590 | + .andProperties(MessagePropertiesBuilder.newInstance().setContentType("application/json").build()).build(); |
| 591 | + message = this.rabbitTemplate.sendAndReceive("test.messaging.message", message); |
| 592 | + assertThat(message, is(notNullValue())); |
| 593 | + assertThat(new String(message.getBody()), equalTo("{\"field\":\"MESSAGING\"}")); |
| 594 | + assertThat(message.getMessageProperties().getHeaders().get("foo"), equalTo("bar")); |
| 595 | + } |
| 596 | + |
| 597 | + @Test |
| 598 | + public void amqpMessageReturned() { |
| 599 | + Message message = org.springframework.amqp.core.MessageBuilder.withBody("amqp".getBytes()) |
| 600 | + .andProperties(MessagePropertiesBuilder.newInstance().setContentType("text/plain").build()).build(); |
| 601 | + message = this.rabbitTemplate.sendAndReceive("test.amqp.message", message); |
| 602 | + assertThat(message, is(notNullValue())); |
| 603 | + assertThat(new String(message.getBody()), equalTo("AMQP")); |
| 604 | + assertThat(message.getMessageProperties().getHeaders().get("foo"), equalTo("bar")); |
| 605 | + } |
| 606 | + |
580 | 607 | interface TxService {
|
581 | 608 |
|
582 | 609 | @Transactional
|
@@ -811,6 +838,22 @@ public String handleWithInternalExchangeIgnore(String foo) {
|
811 | 838 | public String handleWithDeadLetterDefaultExchange(String foo) {
|
812 | 839 | throw new AmqpRejectAndDontRequeueException("dlq");
|
813 | 840 | }
|
| 841 | + @RabbitListener(queues = "test.messaging.message", containerFactory = "simpleJsonListenerContainerFactory") |
| 842 | + public org.springframework.messaging.Message<Bar> messagingMessage(String in) { |
| 843 | + Bar bar = new Bar(); |
| 844 | + bar.field = in.toUpperCase(); |
| 845 | + return new GenericMessage<>(bar, Collections.singletonMap("foo", "bar")); |
| 846 | + } |
| 847 | + |
| 848 | + @RabbitListener(queues = "test.amqp.message") |
| 849 | + public Message amqpMessage(String in) { |
| 850 | + return org.springframework.amqp.core.MessageBuilder.withBody(in.toUpperCase().getBytes()) |
| 851 | + .andProperties(MessagePropertiesBuilder.newInstance().setContentType("text/plain") |
| 852 | + .setHeader("foo", "bar") |
| 853 | + .build()) |
| 854 | + .build(); |
| 855 | + } |
| 856 | + |
814 | 857 | }
|
815 | 858 |
|
816 | 859 | public static class Foo1 {
|
|
0 commit comments