Reputation: 1892
The last element in the code for the following DSL flow is Service Activator (.handle
method).
Is there a default output direct channel to which I can subscribe here? If I understand things correctly, the output channel must be present
I know I can add .channel("name")
at the end but the question is what if it's not written explicitly.
Here is the code:
@SpringBootApplication
@IntegrationComponentScan
public class QueueChannelResearch {
@Bean
public IntegrationFlow lambdaFlow() {
return f -> f.channel(c -> c.queue(50))
.handle(System.out::println);
}
public static void main(String[] args) {
ConfigurableApplicationContext ctx = SpringApplication.run(QueueChannelResearch.class, args);
MessageChannel inputChannel = ctx.getBean("lambdaFlow.input", MessageChannel.class);
for (int i = 0; i < 1000; i++) {
inputChannel.send(MessageBuilder.withPayload("w" + i)
.build());
}
ctx.close();
}
Another question is about QueueChannel
. The program hangs if comment handle()
and completes if uncomment it. Does that mean that handle()
add a default Poller before it?
return f -> f.channel(c -> c.queue(50));
// .handle(System.out::println);
Upvotes: 1
Views: 269
Reputation: 121542
No, that doesn't work that way.
Just recall that integration flow is a filter-pipes
architecture and result of the current step is going to be sent to next one. Since you use .handle(System.out::println)
there is no output from that println()
method call therefore nothing is returned to build a Message to sent to the next channel if any. So, the flow stops here. The void
return type or null
returned value is a signal for service activator to stop the flow. Consider your .handle(System.out::println)
as an <outbound-channel-adapter>
in the XML configuration.
And yes: there is no any default channels, unless you define one via replyChannel
header in advance. But again: your service method must return something valuable.
The output from service activator is optional, that's why we didn't introduce extra operator for the Outbound Channel Adapter.
The question about QueueChannel
would be better to handle in the separate SO thread. There is no default poller unless you declare one as a PollerMetadata.DEFAULT_POLLER
. You might use some library which delcares that one for you.
Upvotes: 1