已编辑 我是 Spring 集成的新手,我正在尝试将数据从服务激活器(通过 handle 方法)传递到 channel 。
@Bean
public IntegrationFlow processFileFlow() {
return IntegrationFlows
.from("fileInputChannel")
.transform(fileToStringTransformer())
.handle("fileProcessor", "process")
.channel("xmlChannel")
.get();
}
@Bean
public DirectChannel fileInputChannel(){
return new DirectChannel();
}
@Bean
public DirectChannel xmlChannel(){
return new DirectChannel();
}
@Bean
public FileProcessor fileProcessor() {
return new FileProcessor();
}
@Bean
public IntegrationFlow enrichDataFlow() {
return IntegrationFlows
.from("xmlChannel")
.handle("enricher", "enrichProduct")
.channel("bvChannel")
.get();
}
@Bean
public Enricher enricher() {
return new Enricher();
}
这是文件处理器类
public class FileProcessor {
@ServiceActivator(outputChannel = "xmlChannel")
public String process(Message<String> msg) {
String content = msg.getPayload();
return content;
}
}
这是 Enricher 类: 公共(public)课丰富剂{
public void enrichProduct(Message<String> msg) {
System.out.println("Enriching product " + msg);
}
}
消息“Enriching product ..”没有打印出来,我不确定哪里出了问题。
最佳答案
.channel("xmlChannel")
不适合你吗?
这绝对是组成 IntegrationFlow
的正确方法 - 从一个端点通过消息 channel 到另一个端点。
我会说 @ServiceActivator
中的 outputChannel = "xmlChannel"
不会工作只是因为没有 inputChannel
. .handle()
将忽略所有这些属性,直接处理 fileProcessor.process()
方法。
关于java - 通过 .handle() 配置服务激活器的输出 channel ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47689028/