diff --git a/spring-integration/src/main/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscibeChannelExample.java b/spring-integration/src/main/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscibeChannelExample.java index ad1535da6f..e26f938632 100644 --- a/spring-integration/src/main/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscibeChannelExample.java +++ b/spring-integration/src/main/java/com/baeldung/subflows/publishsubscribechannel/PublishSubscibeChannelExample.java @@ -16,13 +16,10 @@ import org.springframework.integration.dsl.IntegrationFlow; @EnableIntegration @IntegrationComponentScan public class PublishSubscibeChannelExample { - @MessagingGateway - public interface I { - + public interface NumbersClassifier { @Gateway(requestChannel = "flow.input") - void flow(Collection is); - + void flow(Collection numbers); } @Bean @@ -43,30 +40,24 @@ public class PublishSubscibeChannelExample { @Bean public IntegrationFlow flow() { return flow -> flow.split() - .publishSubscribeChannel(s -> - s.subscribe(f -> f. filter(p -> p % 3 == 0).channel("multipleof3Channel")) - .subscribe(f -> f. filter(p -> p % 3 == 1).channel("remainderIs1Channel")) - .subscribe(f -> f. filter(p -> p % 3 == 2).channel("remainderIs2Channel")) - ); + .publishSubscribeChannel(s -> s.subscribe(f -> f. filter(p -> p % 3 == 0) + .channel("multipleof3Channel")) + .subscribe(f -> f. filter(p -> p % 3 == 1) + .channel("remainderIs1Channel")) + .subscribe(f -> f. filter(p -> p % 3 == 2) + .channel("remainderIs2Channel"))); } public static void main(String[] args) { final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(PublishSubscibeChannelExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - - ctx.getBean(I.class) + ctx.getBean(NumbersClassifier.class) .flow(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } - } diff --git a/spring-integration/src/main/java/com/baeldung/subflows/routeToRecipients/RouteToRecipientsExample.java b/spring-integration/src/main/java/com/baeldung/subflows/routeToRecipients/RouteToRecipientsExample.java index c22072b1ff..04fdb87dfa 100644 --- a/spring-integration/src/main/java/com/baeldung/subflows/routeToRecipients/RouteToRecipientsExample.java +++ b/spring-integration/src/main/java/com/baeldung/subflows/routeToRecipients/RouteToRecipientsExample.java @@ -16,13 +16,10 @@ import org.springframework.integration.dsl.IntegrationFlow; @EnableIntegration @IntegrationComponentScan public class RouteToRecipientsExample { - @MessagingGateway - public interface I { - + public interface NumbersClassifier { @Gateway(requestChannel = "flow.input") - void flow(Collection is); - + void flow(Collection numbers); } @Bean @@ -43,7 +40,6 @@ public class RouteToRecipientsExample { @Bean public IntegrationFlow flow() { return flow -> flow.split() - .routeToRecipients(r -> r. recipient("multipleof3Channel", p -> p % 3 == 0)// filter . recipient("remainderIs1Channel", p -> p % 3 == 1) .recipientFlow(sf -> sf. filter(p -> p % 3 == 2) @@ -52,20 +48,14 @@ public class RouteToRecipientsExample { public static void main(String[] args) { final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(RouteToRecipientsExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - - ctx.getBean(I.class) + ctx.getBean(NumbersClassifier.class) .flow(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } } \ No newline at end of file diff --git a/spring-integration/src/main/java/com/baeldung/subflows/separateflows/SeparateFlowsExample.java b/spring-integration/src/main/java/com/baeldung/subflows/separateflows/SeparateFlowsExample.java index ccd49affd0..8ed46ead87 100644 --- a/spring-integration/src/main/java/com/baeldung/subflows/separateflows/SeparateFlowsExample.java +++ b/spring-integration/src/main/java/com/baeldung/subflows/separateflows/SeparateFlowsExample.java @@ -16,10 +16,8 @@ import org.springframework.integration.dsl.IntegrationFlow; @EnableIntegration @IntegrationComponentScan public class SeparateFlowsExample { - @MessagingGateway - public interface I { - + public interface NumbersClassifier { @Gateway(requestChannel = "multipleof3Flow.input") void multipleof3(Collection is); @@ -27,8 +25,7 @@ public class SeparateFlowsExample { void remainderIs1(Collection is); @Gateway(requestChannel = "remainderIs2Flow.input") - void remainderIs2(Collection is); - + void remainderIs2(Collection numbers); } @Bean @@ -51,7 +48,6 @@ public class SeparateFlowsExample { return f -> f.split() . filter(p -> p % 3 == 0) .channel("multipleof3Channel"); - } @Bean @@ -59,7 +55,6 @@ public class SeparateFlowsExample { return f -> f.split() . filter(p -> p % 3 == 1) .channel("remainderIs1Channel"); - } @Bean @@ -67,33 +62,22 @@ public class SeparateFlowsExample { return f -> f.split() . filter(p -> p % 3 == 2) .channel("remainderIs2Channel"); - } public static void main(String[] args) { - final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(SeparateFlowsExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - - ctx.getBean(I.class) + ctx.getBean(NumbersClassifier.class) .multipleof3(Arrays.asList(1, 2, 3, 4, 5, 6)); - - ctx.getBean(I.class) + ctx.getBean(NumbersClassifier.class) .remainderIs1(Arrays.asList(1, 2, 3, 4, 5, 6)); - - ctx.getBean(I.class) + ctx.getBean(NumbersClassifier.class) .remainderIs2(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } - -} +} \ No newline at end of file diff --git a/spring-integration/src/main/java/com/baeldung/subflows/subflowchannel/FilterExample.java b/spring-integration/src/main/java/com/baeldung/subflows/subflowchannel/FilterExample.java index f8034ab5bd..6db3741523 100644 --- a/spring-integration/src/main/java/com/baeldung/subflows/subflowchannel/FilterExample.java +++ b/spring-integration/src/main/java/com/baeldung/subflows/subflowchannel/FilterExample.java @@ -16,13 +16,10 @@ import org.springframework.integration.dsl.IntegrationFlow; @EnableIntegration @IntegrationComponentScan public class FilterExample { - @MessagingGateway - public interface I { - + public interface NumbersClassifier { @Gateway(requestChannel = "flow.input") - void flow(Collection is); - + void flow(Collection numbers); } @Bean @@ -43,33 +40,21 @@ public class FilterExample { @Bean public IntegrationFlow flow() { return flow -> flow.split() - - . filter(x -> x % 3 == 0, sf -> sf.discardFlow(subf -> subf - - . filter(x -> x % 3 == 1, ssf -> ssf.discardChannel("remainderIs2Channel")) - .channel("remainderIs1Channel") - - )) - + . filter(x -> x % 3 == 0, sf -> sf.discardFlow(subf -> subf. filter(x -> x % 3 == 1, ssf -> ssf.discardChannel("remainderIs2Channel")) + .channel("remainderIs1Channel"))) .channel("multipleof3Channel"); } public static void main(String[] args) { final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(FilterExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - - ctx.getBean(I.class) + ctx.getBean(NumbersClassifier.class) .flow(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } } \ No newline at end of file diff --git a/spring-integration/src/main/java/com/baeldung/subflows/subflowmapping/RouterExample.java b/spring-integration/src/main/java/com/baeldung/subflows/subflowmapping/RouterExample.java index cbef3ca219..de1f11cf70 100644 --- a/spring-integration/src/main/java/com/baeldung/subflows/subflowmapping/RouterExample.java +++ b/spring-integration/src/main/java/com/baeldung/subflows/subflowmapping/RouterExample.java @@ -17,11 +17,9 @@ import org.springframework.integration.dsl.IntegrationFlow; @IntegrationComponentScan public class RouterExample { @MessagingGateway - public interface I { - + public interface NumbersClassifier { @Gateway(requestChannel = "flow.input") - void flow(Collection is); - + void flow(Collection numbers); } @Bean @@ -43,28 +41,21 @@ public class RouterExample { public IntegrationFlow flow() { return f -> f.split() . route(p -> p % 3, m -> m.channelMapping(0, "multipleof3Channel") - .subFlowMapping(1, sf -> sf .channel("remainderIs1Channel")) - .subFlowMapping(2, sf -> sf. handle((p,h)->p))) + .subFlowMapping(1, sf -> sf.channel("remainderIs1Channel")) + .subFlowMapping(2, sf -> sf. handle((p, h) -> p))) .channel("remainderIs2Channel"); } public static void main(String[] args) { final ConfigurableApplicationContext ctx = new AnnotationConfigApplicationContext(RouterExample.class); - DirectChannel multipleof3Channel = ctx.getBean("multipleof3Channel", DirectChannel.class); multipleof3Channel.subscribe(x -> System.out.println("multipleof3Channel: " + x)); - DirectChannel remainderIs1Channel = ctx.getBean("remainderIs1Channel", DirectChannel.class); remainderIs1Channel.subscribe(x -> System.out.println("remainderIs1Channel: " + x)); - DirectChannel remainderIs2Channel = ctx.getBean("remainderIs2Channel", DirectChannel.class); remainderIs2Channel.subscribe(x -> System.out.println("remainderIs2Channel: " + x)); - - ctx.getBean(I.class) + ctx.getBean(NumbersClassifier.class) .flow(Arrays.asList(1, 2, 3, 4, 5, 6)); - ctx.close(); - } - -} +} \ No newline at end of file