我想对两个也使用 Spring Integration 流的 Spring Boot 应用程序进行集成测试。为了测试我的应用程序,我想检查通过 myMessageChannel
路由的消息。它是在其中一个应用程序的 XML 流中定义的。
如何窃听我的直接消息 channel 并将消息重定向到 PollableChannel,以便我可以一一阅读它们? 我在网上找到的方法都不适合我。
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {App1.class, App2.class}, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
@TestPropertySource("classpath:integration.properties")
public class MyWireTapTest {
@Autowired
MessageChannel myMessageChannel;
@Test
public void test() {
// This is basically what I want to do
// But it does not work, since it is a direct channel
myMessageChannel.recieve();
}
}
最佳答案
将其 Autowiring 为AbstractMessageChannel
并使用
myMessageChannel.addInterceptor(new WireTap(tapChannel));
关于java - Spring Integration 窃听直接 MessageChannel 进行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48096733/