【问题标题】:Configure output channel for service activator via .handle()通过 .handle() 为服务激活器配置输出通道
【发布时间】:2018-05-21 04:54:11
【问题描述】:

已编辑 我是 Spring 集成的新手,我正在尝试将数据从服务激活器(通过句柄方法)传递到通道。

@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();
}

这是 FileProcessor 类

public class FileProcessor {

    @ServiceActivator(outputChannel = "xmlChannel")
    public String process(Message<String> msg) {
        String content = msg.getPayload();
        return content;
    }
}

这是 Enricher 类: 公共类丰富者{

    public void enrichProduct(Message<String> msg) {
        System.out.println("Enriching product " + msg);
    }
}

“正在丰富产品..”的消息没有打印出来,我不太确定出了什么问题。

【问题讨论】:

    标签: java spring spring-integration spring-integration-dsl


    【解决方案1】:

    .channel("xmlChannel") 不适合你吗?

    这绝对是编写 IntegrationFlow 的正确方法 - 从一个端点通过消息通道到另一个端点。

    我会说@ServiceActivator 中的outputChannel = "xmlChannel" 不会工作,因为没有inputChannel。更多 .handle() 将忽略所有这些属性,只会直接处理 fileProcessor.process() 方法。

    【讨论】:

    • 谢谢,我推断 .channel("xmlChannel") 不起作用,因为在同一个文件中定义了另一个集成流。我将相应地编辑问题中的详细信息。
    • fileOrocessor 是否仍然被调用?您可以为 org.springframework.integration 类别打开调试日志记录,以查看您的消息如何通过流程
    猜你喜欢
    • 1970-01-01
    • 2014-07-15
    • 1970-01-01
    • 1970-01-01
    • 2013-03-28
    • 2016-03-29
    • 2014-03-07
    • 1970-01-01
    相关资源
    最近更新 更多