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