Example usage for org.springframework.integration.channel DirectChannel DirectChannel

List of usage examples for org.springframework.integration.channel DirectChannel DirectChannel

Introduction

In this page you can find the example usage for org.springframework.integration.channel DirectChannel DirectChannel.

Prototype

public DirectChannel() 

Source Link

Document

Create a channel with default RoundRobinLoadBalancingStrategy

Usage

From source file:com.netflix.spring.sample.membership.Membership.java

@Bean
public DirectChannel inputChannel() {
    return new DirectChannel();
}

From source file:com.devnexus.ting.config.MailNotificationConfig.java

@Bean
@Profile({ SpringProfile.MAIL_ENABLED })
public MessageChannel sendMailChannel() {
    return new DirectChannel();
}

From source file:ru.jts_dev.authserver.config.AuthIntegrationConfig.java

/**
 * Channel for raw object messages, unwrited and unencrypted
 *
 * @return - channel// w w  w  . j  a  va2  s.  co  m
 */
@Bean
public MessageChannel packetChannel() {
    return new DirectChannel();
}

From source file:org.createnet.raptor.auth.service.Application.java

@Bean
public MessageChannel mqttInputChannel() {
    return new DirectChannel();
}

From source file:xolpoc.plugins.StreamPlugin.java

/**
 * Creates a wiretap on the output channel of the {@link Module} and binds the tap channel to {@link MessageBus}'s
 * message target./*  w w  w.  j av a 2s .com*/
 *
 * @param tapChannelName the name of the tap channel
 * @param outputChannel the channel to tap
 */
private void createAndBindTapChannel(String tapChannelName, MessageChannel outputChannel) {
    logger.info("creating and binding tap channel for {}", tapChannelName);
    if (outputChannel instanceof ChannelInterceptorAware) {
        DirectChannel tapChannel = new DirectChannel();
        tapChannel.setBeanName(tapChannelName + ".tap.bridge");
        messageBus.bindPubSubProducer(tapChannelName, tapChannel, null); // TODO tap producer props
        tapOutputChannel(tapChannel, (ChannelInterceptorAware) outputChannel);
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("output channel is not interceptor aware. Tap will not be created.");
        }
    }
}

From source file:com.acmemotors.batch.LoaderJobConfiguration.java

@Bean
public MessageChannel requestChannel() {
    return new DirectChannel();
}

From source file:org.springframework.cloud.stream.binder.AbstractBinderTests.java

@Test
public void testClean() throws Exception {
    Binder binder = getBinder();// w w w. j a  v  a 2  s . com
    Binding<MessageChannel> foo0ProducerBinding = binder.bindProducer("foo.0", new DirectChannel(),
            createProducerProperties());
    Binding<MessageChannel> foo0ConsumerBinding = binder.bindConsumer("foo.0", "test", new DirectChannel(),
            createConsumerProperties());
    Binding<MessageChannel> foo1ProducerBinding = binder.bindProducer("foo.1", new DirectChannel(),
            createProducerProperties());
    Binding<MessageChannel> foo1ConsumerBinding = binder.bindConsumer("foo.1", "test", new DirectChannel(),
            createConsumerProperties());
    Binding<MessageChannel> foo2ProducerBinding = binder.bindProducer("foo.2", new DirectChannel(),
            createProducerProperties());
    foo0ProducerBinding.unbind();
    assertThat(TestUtils.getPropertyValue(foo0ProducerBinding, "lifecycle", Lifecycle.class).isRunning())
            .isFalse();
    foo0ConsumerBinding.unbind();
    foo1ProducerBinding.unbind();
    assertThat(TestUtils.getPropertyValue(foo0ConsumerBinding, "lifecycle", Lifecycle.class).isRunning())
            .isFalse();
    assertThat(TestUtils.getPropertyValue(foo1ProducerBinding, "lifecycle", Lifecycle.class).isRunning())
            .isFalse();
    foo1ConsumerBinding.unbind();
    foo2ProducerBinding.unbind();
    assertThat(TestUtils.getPropertyValue(foo1ConsumerBinding, "lifecycle", Lifecycle.class).isRunning())
            .isFalse();
    assertThat(TestUtils.getPropertyValue(foo2ProducerBinding, "lifecycle", Lifecycle.class).isRunning())
            .isFalse();
}

From source file:org.springframework.cloud.stream.binder.AbstractBinderTests.java

protected DirectChannel createBindableChannel(String channelName, BindingProperties bindingProperties)
        throws Exception {
    BindingServiceProperties bindingServiceProperties = new BindingServiceProperties();
    bindingServiceProperties.getBindings().put(channelName, bindingProperties);
    ConfigurableApplicationContext applicationContext = new GenericApplicationContext();
    applicationContext.refresh();/*from   www . j  a  va2 s .c o m*/
    bindingServiceProperties.setApplicationContext(applicationContext);
    bindingServiceProperties.setConversionService(new DefaultConversionService());
    bindingServiceProperties.afterPropertiesSet();
    DirectChannel channel = new DirectChannel();
    channel.setBeanName(channelName);
    MessageConverterConfigurer messageConverterConfigurer = new MessageConverterConfigurer(
            bindingServiceProperties, new CompositeMessageConverterFactory(null, null));
    messageConverterConfigurer.setBeanFactory(applicationContext.getBeanFactory());
    messageConverterConfigurer.afterPropertiesSet();
    messageConverterConfigurer.configureOutputChannel(channel, channelName);
    return channel;
}

From source file:org.springframework.integration.aggregator.AggregatorTests.java

@Test
public void testAggPerf() throws InterruptedException, ExecutionException, TimeoutException {
    AggregatingMessageHandler handler = new AggregatingMessageHandler(
            new DefaultAggregatingMessageGroupProcessor());
    handler.setCorrelationStrategy(message -> "foo");
    handler.setReleaseStrategy(new MessageCountReleaseStrategy(60000));
    handler.setExpireGroupsUponCompletion(true);
    handler.setSendPartialResultOnExpiry(true);
    DirectChannel outputChannel = new DirectChannel();
    handler.setOutputChannel(outputChannel);

    final CompletableFuture<Collection<?>> resultFuture = new CompletableFuture<>();
    outputChannel.subscribe(message -> {
        Collection<?> payload = (Collection<?>) message.getPayload();
        logger.warn("Received " + payload.size());
        resultFuture.complete(payload);/* www  .  j a v  a2  s .  co m*/
    });

    SimpleMessageStore store = new SimpleMessageStore();

    SimpleMessageGroupFactory messageGroupFactory = new SimpleMessageGroupFactory(
            SimpleMessageGroupFactory.GroupType.BLOCKING_QUEUE);

    store.setMessageGroupFactory(messageGroupFactory);

    handler.setMessageStore(store);

    Message<?> message = new GenericMessage<String>("foo");
    StopWatch stopwatch = new StopWatch();
    stopwatch.start();
    for (int i = 0; i < 120000; i++) {
        if (i % 10000 == 0) {
            stopwatch.stop();
            logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() + " (10k in "
                    + stopwatch.getLastTaskTimeMillis() + "ms)");
            stopwatch.start();
        }
        handler.handleMessage(message);
    }
    stopwatch.stop();
    logger.warn("Sent " + 120000 + " in " + stopwatch.getTotalTimeSeconds() + " (10k in "
            + stopwatch.getLastTaskTimeMillis() + "ms)");

    Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS);
    assertNotNull(result);
    assertEquals(60000, result.size());
}

From source file:org.springframework.integration.aggregator.AggregatorTests.java

@Test
public void testAggPerfDefaultPartial() throws InterruptedException, ExecutionException, TimeoutException {
    AggregatingMessageHandler handler = new AggregatingMessageHandler(
            new DefaultAggregatingMessageGroupProcessor());
    handler.setCorrelationStrategy(message -> "foo");
    handler.setReleasePartialSequences(true);
    DirectChannel outputChannel = new DirectChannel();
    handler.setOutputChannel(outputChannel);

    final CompletableFuture<Collection<?>> resultFuture = new CompletableFuture<>();
    outputChannel.subscribe(message -> {
        Collection<?> payload = (Collection<?>) message.getPayload();
        logger.warn("Received " + payload.size());
        resultFuture.complete(payload);//from  w w  w  .  ja v  a  2 s .  c om
    });

    SimpleMessageStore store = new SimpleMessageStore();

    SimpleMessageGroupFactory messageGroupFactory = new SimpleMessageGroupFactory(
            SimpleMessageGroupFactory.GroupType.BLOCKING_QUEUE);

    store.setMessageGroupFactory(messageGroupFactory);

    handler.setMessageStore(store);

    StopWatch stopwatch = new StopWatch();
    stopwatch.start();
    for (int i = 0; i < 120000; i++) {
        if (i % 10000 == 0) {
            stopwatch.stop();
            logger.warn("Sent " + i + " in " + stopwatch.getTotalTimeSeconds() + " (10k in "
                    + stopwatch.getLastTaskTimeMillis() + "ms)");
            stopwatch.start();
        }
        handler.handleMessage(
                MessageBuilder.withPayload("foo").setSequenceSize(120000).setSequenceNumber(i + 1).build());
    }
    stopwatch.stop();
    logger.warn("Sent " + 120000 + " in " + stopwatch.getTotalTimeSeconds() + " (10k in "
            + stopwatch.getLastTaskTimeMillis() + "ms)");

    Collection<?> result = resultFuture.get(10, TimeUnit.SECONDS);
    assertNotNull(result);
    assertEquals(120000, result.size());
    assertThat(stopwatch.getTotalTimeSeconds(), lessThan(60.0)); // actually < 2.0, was many minutes
}