1+ package com .baeldung .subflows .separateflows ;
2+
3+ import java .util .Arrays ;
4+ import java .util .Collection ;
5+
6+ import org .springframework .context .ConfigurableApplicationContext ;
7+ import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
8+ import org .springframework .context .annotation .Bean ;
9+ import org .springframework .integration .annotation .Gateway ;
10+ import org .springframework .integration .annotation .IntegrationComponentScan ;
11+ import org .springframework .integration .annotation .MessagingGateway ;
12+ import org .springframework .integration .channel .DirectChannel ;
13+ import org .springframework .integration .config .EnableIntegration ;
14+ import org .springframework .integration .dsl .IntegrationFlow ;
15+
16+ @ EnableIntegration
17+ @ IntegrationComponentScan
18+ public class SeparateFlowsExample {
19+ @ MessagingGateway
20+ public interface NumbersClassifier {
21+ @ Gateway (requestChannel = "multipleof3Flow.input" )
22+ void multipleof3 (Collection <Integer > is );
23+
24+ @ Gateway (requestChannel = "remainderIs1Flow.input" )
25+ void remainderIs1 (Collection <Integer > is );
26+
27+ @ Gateway (requestChannel = "remainderIs2Flow.input" )
28+ void remainderIs2 (Collection <Integer > numbers );
29+ }
30+
31+ @ Bean
32+ DirectChannel multipleof3Channel () {
33+ return new DirectChannel ();
34+ }
35+
36+ @ Bean
37+ DirectChannel remainderIs1Channel () {
38+ return new DirectChannel ();
39+ }
40+
41+ @ Bean
42+ DirectChannel remainderIs2Channel () {
43+ return new DirectChannel ();
44+ }
45+
46+ @ Bean
47+ public IntegrationFlow multipleof3Flow () {
48+ return f -> f .split ()
49+ .<Integer > filter (p -> p % 3 == 0 )
50+ .channel ("multipleof3Channel" );
51+ }
52+
53+ @ Bean
54+ public IntegrationFlow remainderIs1Flow () {
55+ return f -> f .split ()
56+ .<Integer > filter (p -> p % 3 == 1 )
57+ .channel ("remainderIs1Channel" );
58+ }
59+
60+ @ Bean
61+ public IntegrationFlow remainderIs2Flow () {
62+ return f -> f .split ()
63+ .<Integer > filter (p -> p % 3 == 2 )
64+ .channel ("remainderIs2Channel" );
65+ }
66+
67+ public static void main (String [] args ) {
68+ final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext (SeparateFlowsExample .class );
69+ DirectChannel multipleof3Channel = ctx .getBean ("multipleof3Channel" , DirectChannel .class );
70+ multipleof3Channel .subscribe (x -> System .out .println ("multipleof3Channel: " + x ));
71+ DirectChannel remainderIs1Channel = ctx .getBean ("remainderIs1Channel" , DirectChannel .class );
72+ remainderIs1Channel .subscribe (x -> System .out .println ("remainderIs1Channel: " + x ));
73+ DirectChannel remainderIs2Channel = ctx .getBean ("remainderIs2Channel" , DirectChannel .class );
74+ remainderIs2Channel .subscribe (x -> System .out .println ("remainderIs2Channel: " + x ));
75+ ctx .getBean (NumbersClassifier .class )
76+ .multipleof3 (Arrays .asList (1 , 2 , 3 , 4 , 5 , 6 ));
77+ ctx .getBean (NumbersClassifier .class )
78+ .remainderIs1 (Arrays .asList (1 , 2 , 3 , 4 , 5 , 6 ));
79+ ctx .getBean (NumbersClassifier .class )
80+ .remainderIs2 (Arrays .asList (1 , 2 , 3 , 4 , 5 , 6 ));
81+ ctx .close ();
82+ }
83+ }
0 commit comments