我有一个接受字符串输入的流程
@Bean
public IntegrationFlow myFlow() {
// @formatter:off
return IntegrationFlows.from("some.input.channel")
.handle(someService)
.get();
我如何从我的集成测试中调用它,如何在“some.input.channel”上放置一个字符串消息
最佳答案
阅读您使用的 API 的 Javadocs:
/**
* Populate the {@link MessageChannel} name to the new {@link IntegrationFlowBuilder} chain.
* The {@link org.springframework.integration.dsl.IntegrationFlow} {@code inputChannel}.
* @param messageChannelName the name of existing {@link MessageChannel} bean.
* The new {@link DirectChannel} bean will be created on context startup
* if there is no bean with this name.
* @return new {@link IntegrationFlowBuilder}.
*/
public static IntegrationFlowBuilder from(String messageChannelName) {
然后打开您使用的框架的引用手册:
因此,Java DSL 创建的 channel 成为应用程序上下文中的一个 bean。
只需将其 Autowiring 到测试类中并从测试方法中调用其send()
即可:
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = MyFlowConfiguration.class)
public class IntegrationFlowTests {
@Autowired
@Qualifier("some.input.channel")
private MessageChannel someInputChannel;
@Test
public void myTest() {
this.someInputChannel.send(new GenericMessage<>("foo"));
}
}
关于spring-integration - 如何在 Spring 集成测试中调用 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51615055/