Chris
Chris

Reputation: 4648

Spring Integration DSL reference documentation code example doesn't compile

The official Spring Integration DSL reference documentation provides the following code example in the first section of https://docs.spring.io/spring-integration/reference/html/dsl.html#java-dsl

@Configuration
@EnableIntegration
public class MyConfiguration {

    @Bean
    public AtomicInteger integerSource() {
        return new AtomicInteger();
    }

    @Bean
    public IntegrationFlow myFlow() {
        return IntegrationFlows.from(integerSource::getAndIncrement,
                c -> c.poller(Pollers.fixedRate(100)))
                .channel("inputChannel")
                .filter((Integer p) -> p > 0)
                .transform(Object::toString)
                .channel(MessageChannels.queue())
                .get();
    }
}

When I copy paste this code into my IDE (IntelliJ), I get the following error at this line

        return IntegrationFlows.from(integerSource::getAndIncrement,

error message:

Cannot resolve symbol 'integerSource'

I have tried various alternative ways of defining getAndIncrement as the messageSource, but all of them prodoced some kind of error so far.

Is there a way to get this example to compile and run ?

Upvotes: 1

Views: 481

Answers (2)

Vladimir Shevchenko
Vladimir Shevchenko

Reputation: 11

You can change your code by replacing from() to fromSupplier()

Upvotes: 1

Artem Bilan
Artem Bilan

Reputation: 121177

We spotted the same problem recently. See the fixed doc in the latest snapshot: https://docs.spring.io/spring-integration/docs/5.5.2-SNAPSHOT/reference/html/dsl.html#java-dsl. The fixed code is like this:

  @Bean
public IntegrationFlow myFlow() {
    return IntegrationFlows.fromSupplier(integerSource()::getAndIncrement,
                                     c -> c.poller(Pollers.fixedRate(100)))
                .channel("inputChannel")
                .filter((Integer p) -> p > 0)
                .transform(Object::toString)
                .channel(MessageChannels.queue())
                .get();
}

The release is due the next week.

Upvotes: 1

Related Questions