【问题标题】:How to use temporary Channel in Spring Integration?如何在 Spring Integration 中使用临时 Channel?
【发布时间】:2021-05-26 16:57:59
【问题描述】:

我是 Spring Integration 的新手,我正在尝试从临时渠道获取消息。

阅读documentation有一个临时频道被spring使用。 我猜它叫NullChannel

我需要我的gateway 从临时通道返回值。

http controller -> gateway -> direct channel -> activator 1 -> queue channel -> activator 2

所以我的activator 2 会将新值放入临时通道,所以gateway 将从临时通道中检索值

@MessageEndpoint
public class Activator2 {
    
@Autowired
private NullChannel nullChannel;

@ServiceActivator(inputChannel = "asyncChannel")
public void plus(Integer message){
    try {
        message++;
        Thread.sleep(2000);
        nullChannel.send(MessageBuilder.withPayload(message).build());
        log.info("Activator 2: " +message );

    } catch (InterruptedException e) {
        log.error("I don't want to sleep");
    }
    
}
}

它不工作。我不确定是否一切正常

【问题讨论】:

    标签: java spring spring-boot spring-integration


    【解决方案1】:

    NullChannel 类似于 Unix 中的 /dev/null;它只是丢弃该值。

    @ServiceActivator(inputChannel = "asyncChannel")
    public Integer plus(Integer message){
        return message;
    }
    

    会自动做你想做的。

    如果没有outputChannel,则框架将结果发送到replyChannel 标头。

    【讨论】:

      猜你喜欢
      • 2017-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多