|
106 | 106 | ReplyingKafkaTemplateTests.D_REPLY, ReplyingKafkaTemplateTests.D_REQUEST, |
107 | 107 | ReplyingKafkaTemplateTests.E_REPLY, ReplyingKafkaTemplateTests.E_REQUEST, |
108 | 108 | ReplyingKafkaTemplateTests.F_REPLY, ReplyingKafkaTemplateTests.F_REQUEST, |
109 | | - ReplyingKafkaTemplateTests.J_REPLY, ReplyingKafkaTemplateTests.J_REQUEST }) |
| 109 | + ReplyingKafkaTemplateTests.J_REPLY, ReplyingKafkaTemplateTests.J_REQUEST, |
| 110 | + ReplyingKafkaTemplateTests.K_REPLY, ReplyingKafkaTemplateTests.K_REQUEST }) |
110 | 111 | public class ReplyingKafkaTemplateTests { |
111 | 112 |
|
112 | 113 | public static final String A_REPLY = "aReply"; |
@@ -141,6 +142,10 @@ public class ReplyingKafkaTemplateTests { |
141 | 142 |
|
142 | 143 | public static final String J_REQUEST = "jRequest"; |
143 | 144 |
|
| 145 | + public static final String K_REPLY = "kReply"; |
| 146 | + |
| 147 | + public static final String K_REQUEST = "kRequest"; |
| 148 | + |
144 | 149 | @Autowired |
145 | 150 | private EmbeddedKafkaBroker embeddedKafka; |
146 | 151 |
|
@@ -187,6 +192,24 @@ public void testGood() throws Exception { |
187 | 192 | } |
188 | 193 | } |
189 | 194 |
|
| 195 | + @Test |
| 196 | + void testConsumerRecord() throws Exception { |
| 197 | + ReplyingKafkaTemplate<Integer, String, String> template = createTemplate(K_REPLY); |
| 198 | + try { |
| 199 | + template.setDefaultReplyTimeout(Duration.ofSeconds(30)); |
| 200 | + Headers headers = new RecordHeaders(); |
| 201 | + ProducerRecord<Integer, String> record = new ProducerRecord<>(K_REQUEST, null, null, null, "foo", headers); |
| 202 | + RequestReplyFuture<Integer, String, String> future = template.sendAndReceive(record); |
| 203 | + future.getSendFuture().get(10, TimeUnit.SECONDS); // send ok |
| 204 | + ConsumerRecord<Integer, String> consumerRecord = future.get(30, TimeUnit.SECONDS); |
| 205 | + assertThat(consumerRecord.value()).isEqualTo("FOO"); |
| 206 | + } |
| 207 | + finally { |
| 208 | + template.stop(); |
| 209 | + template.destroy(); |
| 210 | + } |
| 211 | + } |
| 212 | + |
190 | 213 | @Test |
191 | 214 | public void testBadDeserialize() throws Exception { |
192 | 215 | ReplyingKafkaTemplate<Integer, String, String> template = createTemplate(J_REPLY, true); |
@@ -669,6 +692,12 @@ public void gListener(Message<String> in) { |
669 | 692 | public String handleJ(String in) throws InterruptedException { |
670 | 693 | return in.toUpperCase(); |
671 | 694 | } |
| 695 | + @KafkaListener(id = K_REQUEST, topics = { K_REQUEST }) |
| 696 | + |
| 697 | + @SendTo |
| 698 | + public String handleK(ConsumerRecord<String, String> in) { |
| 699 | + return in.value().toUpperCase(); |
| 700 | + } |
672 | 701 |
|
673 | 702 | } |
674 | 703 |
|
|
0 commit comments