/** * Populate the {@link MethodInvokingRouter} for the method * of the provided service and its method with default options. * @param service the service to use. * @param methodName the method to invoke. * @return the current {@link IntegrationFlowDefinition}. * @see MethodInvokingRouter */ public B route(Object service, String methodName) { return route(service, methodName, null); }
/** * Populate the provided {@link AbstractMessageRouter} implementation to the * current integration flow position. * @param router the {@link AbstractMessageRouter} to populate. * @return the current {@link IntegrationFlowDefinition}. */ public B route(AbstractMessageRouter router) { return route(router, (Consumer<GenericEndpointSpec<AbstractMessageRouter>>) null); }
/** * Populate the {@link ExpressionEvaluatingRouter} for provided SpEL expression * with default options. * @param expression the expression to use. * @return the current {@link IntegrationFlowDefinition}. */ public B route(String expression) { return route(expression, (Consumer<RouterSpec<Object, ExpressionEvaluatingRouter>>) null); }
/** * Populate the {@link MethodInvokingRouter} for provided bean and its method * with default options. * @param beanName the bean to use. * @param method the method to invoke at runtime. * @return the current {@link IntegrationFlowDefinition}. */ public B route(String beanName, String method) { return route(beanName, method, null); }
/** * Populate the {@link MethodInvokingRouter} for the discovered method * of the provided service and its method with default options. * @param service the bean to use. * @return the current {@link IntegrationFlowDefinition}. * @see MethodInvokingRouter */ public B route(Object service) { return route(service, null); }
/** * Populate the {@link MethodInvokingRouter} for the {@link org.springframework.integration.handler.MessageProcessor} * from the provided {@link MessageProcessorSpec} with default options. * <pre class="code"> * {@code * .route(Scripts.script(myScriptResource).lang("groovy").refreshCheckDelay(1000)) * } * </pre> * @param messageProcessorSpec the {@link MessageProcessorSpec} to use. * @return the current {@link IntegrationFlowDefinition}. */ public B route(MessageProcessorSpec<?> messageProcessorSpec) { return route(messageProcessorSpec, (Consumer<RouterSpec<Object, MethodInvokingRouter>>) null); }
/** * Populate the {@link MethodInvokingRouter} for provided {@link Function} * with default options. * Typically used with a Java 8 Lambda expression: * <pre class="code"> * {@code * .route(p -> p.equals("foo") || p.equals("bar") ? new String[] {"foo", "bar"} : null) * } * </pre> * Use {@link #route(Class, Function)} if you need to access the entire message. * @param router the {@link Function} to use. * @param <S> the source payload type. * @param <T> the target result type. * @return the current {@link IntegrationFlowDefinition}. */ public <S, T> B route(Function<S, T> router) { return route(null, router); }
/** * Populate the {@link MethodInvokingRouter} for provided {@link Function} * and payload type with default options. * Typically used with a Java 8 Lambda expression: * <pre class="code"> * {@code * .route(Integer.class, p -> p % 2 == 0) * } * </pre> * @param payloadType the {@link Class} for expected payload type. It can also be * {@code Message.class} if you wish to access the entire message in the splitter. * Conversion to this type will be attempted, if necessary. * @param router the {@link Function} to use. * @param <S> the source payload type or {@code Message.class}. * @param <T> the target result type. * @return the current {@link IntegrationFlowDefinition}. * @see LambdaMessageProcessor */ public <S, T> B route(Class<S> payloadType, Function<S, T> router) { return route(payloadType, router, null); }
/** * Populate the {@link RecipientListRouter} with options from the {@link RecipientListRouterSpec}. * Typically used with a Java 8 Lambda expression: * <pre class="code"> * {@code * .routeToRecipients(r -> r * .recipient("bar-channel", m -> * m.getHeaders().containsKey("recipient") && (boolean) m.getHeaders().get("recipient")) * .recipientFlow("'foo' == payload or 'bar' == payload or 'baz' == payload", * f -> f.transform(String.class, p -> p.toUpperCase()) * .channel(c -> c.queue("recipientListSubFlow1Result")))) * } * </pre> * @param routerConfigurer the {@link Consumer} to provide {@link RecipientListRouter} options. * @return the current {@link IntegrationFlowDefinition}. */ public B routeToRecipients(Consumer<RecipientListRouterSpec> routerConfigurer) { return route(new RecipientListRouterSpec(), routerConfigurer); }
/** * Populate the {@link MethodInvokingRouter} for the method * of the provided service and its method with provided options from {@link RouterSpec}. * @param service the service to use. * @param methodName the method to invoke. * @param routerConfigurer the {@link Consumer} to provide {@link MethodInvokingRouter} options. * @return the current {@link IntegrationFlowDefinition}. * @see MethodInvokingRouter */ public B route(Object service, String methodName, Consumer<RouterSpec<Object, MethodInvokingRouter>> routerConfigurer) { MethodInvokingRouter router; if (StringUtils.hasText(methodName)) { router = new MethodInvokingRouter(service, methodName); } else { router = new MethodInvokingRouter(service); } return route(new RouterSpec<>(router), routerConfigurer); }
@Bean public IntegrationFlow scriptRouter() { return f -> f.route(Scripts.processor("scripts/TestRouterScript.js")); }
/** * Populate the {@link ErrorMessageExceptionTypeRouter} with options from the {@link RouterSpec}. * Typically used with a Java 8 Lambda expression: * <pre class="code"> * {@code * .routeByException(r -> r * .channelMapping(IllegalArgumentException.class, "illegalArgumentChannel") * .subFlowMapping(MessageHandlingException.class, sf -> * sf.handle(...)) * ) * } * </pre> * @param routerConfigurer the {@link Consumer} to provide {@link ErrorMessageExceptionTypeRouter} options. * @return the current {@link IntegrationFlowDefinition}. * @see ErrorMessageExceptionTypeRouter */ public B routeByException( Consumer<RouterSpec<Class<? extends Throwable>, ErrorMessageExceptionTypeRouter>> routerConfigurer) { return route(new RouterSpec<>(new ErrorMessageExceptionTypeRouter()), routerConfigurer); }
/** * Populate the {@link ExpressionEvaluatingRouter} for provided SpEL expression * with provided options from {@link RouterSpec}. * @param expression the expression to use. * @param routerConfigurer the {@link Consumer} to provide {@link ExpressionEvaluatingRouter} options. * @param <T> the target result type. * @return the current {@link IntegrationFlowDefinition}. */ public <T> B route(String expression, Consumer<RouterSpec<T, ExpressionEvaluatingRouter>> routerConfigurer) { return route(new RouterSpec<>(new ExpressionEvaluatingRouter(PARSER.parseExpression(expression))), routerConfigurer); }
@Bean public IntegrationFlow routeSubflowToReplyChannelFlow() { return f -> f .<Boolean>route("true", m -> m .subFlowMapping(true, upperCase()) ); }
@Bean public IntegrationFlow payloadTypeRouteFlow() { return f -> f .<Object, Class<?>>route(Object::getClass, m -> m .channelMapping(String.class, "stringsChannel") .channelMapping(Integer.class, "integersChannel")); }
/** * Populate the {@link MethodInvokingRouter} for provided bean and its method * with provided options from {@link RouterSpec}. * @param beanName the bean to use. * @param method the method to invoke at runtime. * @param routerConfigurer the {@link Consumer} to provide {@link MethodInvokingRouter} options. * @return the current {@link IntegrationFlowDefinition}. */ public B route(String beanName, String method, Consumer<RouterSpec<Object, MethodInvokingRouter>> routerConfigurer) { MethodInvokingRouter methodInvokingRouter = new MethodInvokingRouter(new BeanNameMessageProcessor<>(beanName, method)); return route(new RouterSpec<>(methodInvokingRouter), routerConfigurer); }
@Bean public IntegrationFlow routeMethodInvocationFlow3() { return f -> f.route((String p) -> routingTestBean().routePayload(p)); }
@Bean public IntegrationFlow routerAsNonLastFlow() { return f -> f .<String, String>route(p -> p, r -> r.resolutionRequired(false) .defaultOutputToParentFlow()) .channel(MessageChannels.queue("routerAsNonLastDefaultOutputChannel")); }
@Bean public IntegrationFlow routeSubflowWithoutReplyToMainFlow() { return f -> f .<String, Boolean>route("BOO"::equals, m -> m .resolutionRequired(false) .subFlowMapping(true, sf -> sf .transform(String.class, String::toLowerCase) .channel(MessageChannels.queue("routerSubflowResult"))) .defaultSubFlowMapping(sf -> sf.channel("defaultOutputChannel"))); }
@Bean public IntegrationFlow routerTwoSubFlows() { return f -> f .split() .<Integer, Boolean>route(p -> p % 2 == 0, m -> m .subFlowMapping(true, sf -> sf.<Integer>handle((p, h) -> p * 2)) .subFlowMapping(false, sf -> sf.<Integer>handle((p, h) -> p * 3))) .aggregate() .channel(MessageChannels.queue("routerTwoSubFlowsOutput")); }