2

已编辑 我是 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 class Enricher {

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

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

4

1 回答 1

1

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

这绝对是正确的组合方式IntegrationFlow——从一个端点通过消息通道到另一个端点。

而且我会说outputChannel = "xmlChannel"in the @ServiceActivatoris not going to work 仅仅因为没有inputChannel. 更重要的是,.handle()将忽略所有这些属性,直接处理该fileProcessor.process()方法。

于 2017-12-07T08:18:10.750 回答