簡體   English   中英

如何在 Spring 集成中使用臨時通道?

[英]How to use temporary Channel in Spring Integration?

我是 Spring 集成的新手,我正在嘗試從臨時頻道獲取消息。

閱讀文檔,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");
    }
    
}
}

它不工作。 我不確定一切是否連接良好

NullChannel類似於 Unix 中的/dev/null 它只是丟棄了該值。

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

會自動做你想做的。

如果沒有outputChannel ,框架將結果發送到replyChannel header。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM