【发布时间】:2019-09-30 08:58:13
【问题描述】:
我有一个简单的应用程序,它使用 spring cloud stream 和 kafka 接收消息并写入另一个主题。我正在尝试根据一些教程编写单元测试,但在发送消息时出现错误。根据消息,它无法读取 JSON。
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class ApplicationTests {
@Autowired
private Processor processor;
@Autowired
private MessageCollector messageCollector;
@Test
@SuppressWarnings("unchecked")
public void testWriting() {
MyRecord myRecord= getDummyRecord(); // getting dummy MyRecord object
Message<MyRecord> message = MessageBuilder.withPayload(myRecord).setHeader(KafkaHeaders.MESSAGE_KEY, getDummyKey()).build();
processor.input().send(message);
Message<MyRecord> receivedMessage = (Message<MyRecord>) messageCollector.forChannel(processor.output()).poll();
}
}
我得到的错误是:
无法读取 JSON:无法识别的令牌“WeatherRecordRaw”:期待(“true”、“false”或“null”) 在 [Source: (String)"MyRecord(....)
我该如何解决这个问题,我在应用中没有问题,只有在测试中。
【问题讨论】:
-
你需要展示
myRecord的样子。 -
你到底是什么意思?这是一个简单的 POJO 类。
标签: apache-kafka apache-kafka-streams spring-cloud-stream