2

I wrote my first spring integration application which reads data from spring RSS and logs it into console:

@Configuration
@EnableIntegration
@IntegrationComponentScan
public class DslConfig {

    @Bean
    public IntegrationFlow feedFlow() throws MalformedURLException {
        return IntegrationFlows.from(inBoundFeedDataAdapter(), configurer -> configurer.poller(Pollers.fixedDelay(1000)))
                .channel(newsChannel())
                .transform(source -> {
                    SyndEntry e = ((SyndEntry) source);
                    return e.getTitle() + " " + e.getLink();
                })
                .handle(messageHandler())
                .get();
    }

    @Bean
    public FeedEntryMessageSourceSpec inBoundFeedDataAdapter() throws MalformedURLException {
        return Feed.inboundAdapter(new URL("https://spring.io/blog.atom"), "some_key");
    }

    @Bean
    public MessageChannel newsChannel() {
        return new DirectChannel();
    }

    @Bean
    public MessageHandler messageHandler() {
        return System.out::println;
    }
}

But I have no idea how can I add one additional handler for writing result into file.

How can I achieve it ?

Additional questions:

What is the meaning of metadata key ?

gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

1 Answers1

4

There is a publishSubscribeChannel() to place in the flow and there you can add subscribe() for several sub-flows. Each of them is going to get the same message to process. If you also add an Executor to the configuration, the process is going to happen in parallel:

.publishSubscribeChannel(s -> s
                        .applySequence(true)
                        .subscribe(f -> f
                                .handle((p, h) -> "Hello"))
                        .subscribe(f -> f
                                .handle((p, h) -> "World!"))
                );

See more info in Docs: https://docs.spring.io/spring-integration/docs/5.2.0.BUILD-SNAPSHOT/reference/html/dsl.html#java-dsl-subflows

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • It helps. Is it correct that there are 3 options for pipelines confihuration: xml, annotations and java config ? Are there any comparisons? – gstackoverflow Aug 22 '19 at 16:21
  • They are equivalent in terms of the final runtime model. Just a choice for you! We recommend to use Java DSL because we do a lot of work underneath to avoid some boilerplate code and there is a lot of syntax sugar for IDE experience. – Artem Bilan Aug 22 '19 at 16:32
  • Thank you, Artem. I would like to start my learning to get through the basic examples https://github.com/spring-projects/spring-integration-samples/tree/master/basic but it contains only xml configuration(I checked several examples). I really don't like xml. Do you have the same samples using java DSL config? – gstackoverflow Aug 22 '19 at 16:58
  • Not all of them, of course, but you can find something in the: https://github.com/spring-projects/spring-integration-samples/tree/master/dsl – Artem Bilan Aug 22 '19 at 17:02
  • github.com/spring-projects/spring-integration-samples/blob/… looks like it is annotaion example but it resides under the DSL. For me it is some kind of mess or I just don't understand smth – gstackoverflow Aug 23 '19 at 09:24
  • I read introduction from https://docs.spring.io/spring-integration/reference/html/#spring-integration-introduction but I don't see such endpoint as message handler. But in my Example it exist) – gstackoverflow Aug 23 '19 at 09:59