常規的 spring 云流函式如下所示(取自檔案):
@Bean
public Function<String, String> toUpperCase() {
return s -> s.toUpperCase();
}
考慮不使用反應式方法,我想知道是否可以根據自定義邏輯進行不同的轉換和/或將結果發送到不同的“輸出”系結?像這樣的東西:
@Bean
public Function<String, String> transform() {
return s -> {
if (s.equals("A")) {
return s.toUpperCase(); //this wants to be sent to toUpperCase-out-0
} else if (s.equals("B")) {
return s.toLowerCase(); //this wants to be sent to toLowerCase-out-0
} else {
return "unsupported"; //this wants to be sent to unsupported-out-0
}
};
}
此外,這里我們有相同的回傳型別(字串),但可能需要從每個分支回傳不同類的物件(通過使用Object/astract 類/等作為整個函式的回傳型別)。
我可以想象一個使用 aConsumer而不是Function我們進行不同StreamBridge呼叫的解決方案,但也許可以對 a 做同樣的事情Function?
uj5u.com熱心網友回復:
不要使用 a Function,Consumer而是使用 a 并使用 . 發送輸出StreamBridge。
https://docs.spring.io/spring-cloud-stream/docs/current/reference/html/spring-cloud-stream.html#_sending_arbitrary_data_to_an_output_e_g_foreign_event_driven_sources
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/491619.html
下一篇:春季事件生命周期
