2
votes

Edited I am new to Spring integration, and I am trying to pass data from a service activator(via handle method) to a 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();
}

This is the FileProcessor class

public class FileProcessor {

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

This is the Enricher class: public class Enricher {

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

The message "Enriching product .." isn't getting printed, and I'm not really sure of what has gone wrong.

1

1 Answers

1
votes

Doesn't that .channel("xmlChannel") work for you?

That's definitely the proper way to compose IntegrationFlow - from one endpoint over a message channel to another endpoint.

And I would say that outputChannel = "xmlChannel" in the @ServiceActivator isn't going to work just because there is no inputChannel. More over the .handle() will just ignore all those attributes and just will deal with the fileProcessor.process() method directly.