|
109 | 109 | ReplyingKafkaTemplateTests.G_REPLY, ReplyingKafkaTemplateTests.G_REQUEST, |
110 | 110 | ReplyingKafkaTemplateTests.H_REPLY, ReplyingKafkaTemplateTests.H_REQUEST, |
111 | 111 | ReplyingKafkaTemplateTests.I_REPLY, ReplyingKafkaTemplateTests.I_REQUEST, |
112 | | - ReplyingKafkaTemplateTests.J_REPLY, ReplyingKafkaTemplateTests.J_REQUEST }) |
| 112 | + ReplyingKafkaTemplateTests.J_REPLY, ReplyingKafkaTemplateTests.J_REQUEST, |
| 113 | + ReplyingKafkaTemplateTests.K_REPLY, ReplyingKafkaTemplateTests.K_REQUEST }) |
113 | 114 | public class ReplyingKafkaTemplateTests { |
114 | 115 |
|
115 | 116 | public static final String A_REPLY = "aReply"; |
@@ -152,6 +153,10 @@ public class ReplyingKafkaTemplateTests { |
152 | 153 |
|
153 | 154 | public static final String J_REQUEST = "jRequest"; |
154 | 155 |
|
| 156 | + public static final String K_REPLY = "kReply"; |
| 157 | + |
| 158 | + public static final String K_REQUEST = "kRequest"; |
| 159 | + |
155 | 160 | @Autowired |
156 | 161 | private EmbeddedKafkaBroker embeddedKafka; |
157 | 162 |
|
@@ -198,6 +203,24 @@ public void testGood() throws Exception { |
198 | 203 | } |
199 | 204 | } |
200 | 205 |
|
| 206 | + @Test |
| 207 | + void testConsumerRecord() throws Exception { |
| 208 | + ReplyingKafkaTemplate<Integer, String, String> template = createTemplate(K_REPLY); |
| 209 | + try { |
| 210 | + template.setDefaultReplyTimeout(Duration.ofSeconds(30)); |
| 211 | + Headers headers = new RecordHeaders(); |
| 212 | + ProducerRecord<Integer, String> record = new ProducerRecord<>(K_REQUEST, null, null, null, "foo", headers); |
| 213 | + RequestReplyFuture<Integer, String, String> future = template.sendAndReceive(record); |
| 214 | + future.getSendFuture().get(10, TimeUnit.SECONDS); // send ok |
| 215 | + ConsumerRecord<Integer, String> consumerRecord = future.get(30, TimeUnit.SECONDS); |
| 216 | + assertThat(consumerRecord.value()).isEqualTo("FOO"); |
| 217 | + } |
| 218 | + finally { |
| 219 | + template.stop(); |
| 220 | + template.destroy(); |
| 221 | + } |
| 222 | + } |
| 223 | + |
201 | 224 | @Test |
202 | 225 | public void testBadDeserialize() throws Exception { |
203 | 226 | ReplyingKafkaTemplate<Integer, String, String> template = createTemplate(J_REPLY, true); |
@@ -730,6 +753,12 @@ public String handleJ(String in) throws InterruptedException { |
730 | 753 | return in.toUpperCase(); |
731 | 754 | } |
732 | 755 |
|
| 756 | + @KafkaListener(id = K_REQUEST, topics = { K_REQUEST }) |
| 757 | + @SendTo |
| 758 | + public String handleK(ConsumerRecord<String, String> in) { |
| 759 | + return in.value().toUpperCase(); |
| 760 | + } |
| 761 | + |
733 | 762 | } |
734 | 763 |
|
735 | 764 | @KafkaListener(topics = C_REQUEST, groupId = C_REQUEST) |
|
0 commit comments