Search in sources :

Example 1 with RecipientListRouter

use of org.springframework.integration.router.RecipientListRouter in project spring-integration by spring-projects.

the class IntegrationManagementConfigurerTests method testDefaults.

@Test
public void testDefaults() {
    DirectChannel channel = new DirectChannel();
    AbstractMessageHandler handler = new RecipientListRouter();
    AbstractMessageSource<?> source = new AbstractMessageSource<Object>() {

        @Override
        public String getComponentType() {
            return null;
        }

        @Override
        protected Object doReceive() {
            return null;
        }
    };
    assertTrue(channel.isLoggingEnabled());
    assertTrue(handler.isLoggingEnabled());
    assertTrue(source.isLoggingEnabled());
    channel.setCountsEnabled(true);
    channel.setStatsEnabled(true);
    ApplicationContext ctx = mock(ApplicationContext.class);
    Map<String, IntegrationManagement> beans = new HashMap<String, IntegrationManagement>();
    beans.put("foo", channel);
    beans.put("bar", handler);
    beans.put("baz", source);
    when(ctx.getBeansOfType(IntegrationManagement.class)).thenReturn(beans);
    IntegrationManagementConfigurer configurer = new IntegrationManagementConfigurer();
    configurer.setBeanName(IntegrationManagementConfigurer.MANAGEMENT_CONFIGURER_NAME);
    configurer.setApplicationContext(ctx);
    configurer.setDefaultLoggingEnabled(false);
    configurer.afterSingletonsInstantiated();
    assertFalse(channel.isLoggingEnabled());
    assertFalse(handler.isLoggingEnabled());
    assertFalse(source.isLoggingEnabled());
    assertTrue(channel.isCountsEnabled());
    assertTrue(channel.isStatsEnabled());
}
Also used : IntegrationManagementConfigurer(org.springframework.integration.config.IntegrationManagementConfigurer) ApplicationContext(org.springframework.context.ApplicationContext) AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) DirectChannel(org.springframework.integration.channel.DirectChannel) HashMap(java.util.HashMap) EnableIntegrationManagement(org.springframework.integration.config.EnableIntegrationManagement) RecipientListRouter(org.springframework.integration.router.RecipientListRouter) AbstractMessageSource(org.springframework.integration.endpoint.AbstractMessageSource) AbstractMessageHandler(org.springframework.integration.handler.AbstractMessageHandler) Test(org.junit.Test)

Example 2 with RecipientListRouter

use of org.springframework.integration.router.RecipientListRouter in project spring-integration by spring-projects.

the class RecipientListRouterParserTests method customRouter.

@Test
public void customRouter() {
    Object endpoint = context.getBean("customRouter");
    Object handler = TestUtils.getPropertyValue(endpoint, "handler");
    assertEquals(RecipientListRouter.class, handler.getClass());
    RecipientListRouter router = (RecipientListRouter) handler;
    DirectFieldAccessor accessor = new DirectFieldAccessor(router);
    assertEquals(new Long(1234), new DirectFieldAccessor(accessor.getPropertyValue("messagingTemplate")).getPropertyValue("sendTimeout"));
    assertEquals(Boolean.TRUE, accessor.getPropertyValue("applySequence"));
    assertEquals(Boolean.TRUE, accessor.getPropertyValue("ignoreSendFailures"));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RecipientListRouter(org.springframework.integration.router.RecipientListRouter) Test(org.junit.Test)

Example 3 with RecipientListRouter

use of org.springframework.integration.router.RecipientListRouter in project spring-integration by spring-projects.

the class RecipientListRouterParserTests method simpleRouter.

@Test
public void simpleRouter() {
    Object endpoint = context.getBean("simpleRouter");
    Object handler = TestUtils.getPropertyValue(endpoint, "handler");
    assertEquals(RecipientListRouter.class, handler.getClass());
    RecipientListRouter router = (RecipientListRouter) handler;
    DirectFieldAccessor accessor = new DirectFieldAccessor(router);
    assertEquals(new Long(-1), new DirectFieldAccessor(accessor.getPropertyValue("messagingTemplate")).getPropertyValue("sendTimeout"));
    assertEquals(Boolean.FALSE, accessor.getPropertyValue("applySequence"));
    assertEquals(Boolean.FALSE, accessor.getPropertyValue("ignoreSendFailures"));
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RecipientListRouter(org.springframework.integration.router.RecipientListRouter) Test(org.junit.Test)

Example 4 with RecipientListRouter

use of org.springframework.integration.router.RecipientListRouter in project spring-integration by spring-projects.

the class IntegrationFlowDefinition method scatterGather.

/**
 * Populate a {@link ScatterGatherHandler} to the current integration flow position
 * based on the provided {@link RecipientListRouterSpec} for scattering function
 * and {@link AggregatorSpec} for gathering function.
 * @param scatterer the {@link Consumer} for {@link RecipientListRouterSpec} to configure scatterer.
 * @param gatherer the {@link Consumer} for {@link AggregatorSpec} to configure gatherer.
 * @param scatterGather the {@link Consumer} for {@link ScatterGatherSpec} to configure
 * {@link ScatterGatherHandler} and its endpoint. Can be {@code null}.
 * @return the current {@link IntegrationFlowDefinition}.
 */
public B scatterGather(Consumer<RecipientListRouterSpec> scatterer, Consumer<AggregatorSpec> gatherer, Consumer<ScatterGatherSpec> scatterGather) {
    Assert.notNull(scatterer, "'scatterer' must not be null");
    RecipientListRouterSpec recipientListRouterSpec = new RecipientListRouterSpec();
    scatterer.accept(recipientListRouterSpec);
    AggregatorSpec aggregatorSpec = new AggregatorSpec();
    if (gatherer != null) {
        gatherer.accept(aggregatorSpec);
    }
    RecipientListRouter recipientListRouter = recipientListRouterSpec.get().getT2();
    addComponent(recipientListRouter).addComponents(recipientListRouterSpec.getComponentsToRegister());
    AggregatingMessageHandler aggregatingMessageHandler = aggregatorSpec.get().getT2();
    addComponent(aggregatingMessageHandler);
    ScatterGatherHandler messageHandler = new ScatterGatherHandler(recipientListRouter, aggregatingMessageHandler);
    return register(new ScatterGatherSpec(messageHandler), scatterGather);
}
Also used : AggregatingMessageHandler(org.springframework.integration.aggregator.AggregatingMessageHandler) RecipientListRouter(org.springframework.integration.router.RecipientListRouter) ScatterGatherHandler(org.springframework.integration.scattergather.ScatterGatherHandler)

Aggregations

RecipientListRouter (org.springframework.integration.router.RecipientListRouter)4 Test (org.junit.Test)3 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 HashMap (java.util.HashMap)1 ApplicationContext (org.springframework.context.ApplicationContext)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 AggregatingMessageHandler (org.springframework.integration.aggregator.AggregatingMessageHandler)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 EnableIntegrationManagement (org.springframework.integration.config.EnableIntegrationManagement)1 IntegrationManagementConfigurer (org.springframework.integration.config.IntegrationManagementConfigurer)1 AbstractMessageSource (org.springframework.integration.endpoint.AbstractMessageSource)1 AbstractMessageHandler (org.springframework.integration.handler.AbstractMessageHandler)1 ScatterGatherHandler (org.springframework.integration.scattergather.ScatterGatherHandler)1