spring-integration - 如何在 Spring 集成测试中调用 channel

标签 spring-integration spring-integration-dsl

我有一个接受字符串输入的流程

  @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) {

然后打开您使用的框架的引用手册:

https://docs.spring.io/spring-integration/docs/current/reference/html/messaging-channels-section.html#messaging-channels-section

https://docs.spring.io/spring/docs/current/spring-framework-reference/testing.html#integration-testing-annotations-standard

因此,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/

相关文章:

java - Spring Integration Java DSL - 流程中的可重用对象

java - 如何为 Spring Integration SFTP 入站适配器动态定义文件过滤器模式?

spring-integration - 使用客户端 ConnectionFactory 停止 TCP 适配器

java - 在 TCP 网关中发送响应后向 Spring Integration 中的 serviceActivator 发送消息

java - spring integration中如何并行同步处理?

java - Intellij Spring 集成图无法通过消息模板检测连接

java - Spring Integration DSL 中是否有任何工具可以处理消息抽象而不是 JMS、AMQP...?

java - 使用 Id Autowiring tcp-outbound-channel-adapter 不起作用

java - Spring 集成是否为其组件提供任何监控/时间性能实用程序?

spring-integration - Spring Integration 负载均衡到 JMS 队列