Search in sources :

Example 11 with NullChannel

use of org.springframework.integration.channel.NullChannel in project spring-integration by spring-projects.

the class OutboundEndpointTests method testAsyncDelayExpression.

@Test
public void testAsyncDelayExpression() {
    ConnectionFactory connectionFactory = mock(ConnectionFactory.class);
    AsyncRabbitTemplate amqpTemplate = spy(new AsyncRabbitTemplate(new RabbitTemplate(connectionFactory), new SimpleMessageListenerContainer(connectionFactory), "replyTo"));
    amqpTemplate.setTaskScheduler(mock(TaskScheduler.class));
    AsyncAmqpOutboundGateway gateway = new AsyncAmqpOutboundGateway(amqpTemplate);
    willAnswer(invocation -> amqpTemplate.new RabbitMessageFuture("foo", invocation.getArgument(2))).given(amqpTemplate).sendAndReceive(anyString(), anyString(), any(Message.class));
    gateway.setExchangeName("foo");
    gateway.setRoutingKey("bar");
    gateway.setDelayExpressionString("42");
    gateway.setBeanFactory(mock(BeanFactory.class));
    gateway.setOutputChannel(new NullChannel());
    gateway.afterPropertiesSet();
    gateway.start();
    ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
    gateway.handleMessage(new GenericMessage<>("foo"));
    verify(amqpTemplate).sendAndReceive(eq("foo"), eq("bar"), captor.capture());
    assertThat(captor.getValue().getMessageProperties().getDelay(), equalTo(42));
}
Also used : AsyncRabbitTemplate(org.springframework.amqp.rabbit.AsyncRabbitTemplate) RabbitTemplate(org.springframework.amqp.rabbit.core.RabbitTemplate) AsyncRabbitTemplate(org.springframework.amqp.rabbit.AsyncRabbitTemplate) ConnectionFactory(org.springframework.amqp.rabbit.connection.ConnectionFactory) Message(org.springframework.amqp.core.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) SimpleMessageListenerContainer(org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer) BeanFactory(org.springframework.beans.factory.BeanFactory) TaskScheduler(org.springframework.scheduling.TaskScheduler) NullChannel(org.springframework.integration.channel.NullChannel) Test(org.junit.Test)

Example 12 with NullChannel

use of org.springframework.integration.channel.NullChannel in project spring-integration by spring-projects.

the class AbstractCorrelatingMessageHandler method onInit.

@Override
protected void onInit() throws Exception {
    super.onInit();
    Assert.state(!(this.discardChannelName != null && this.discardChannel != null), "'discardChannelName' and 'discardChannel' are mutually exclusive.");
    BeanFactory beanFactory = this.getBeanFactory();
    if (beanFactory != null) {
        if (this.outputProcessor instanceof BeanFactoryAware) {
            ((BeanFactoryAware) this.outputProcessor).setBeanFactory(beanFactory);
        }
        if (this.correlationStrategy instanceof BeanFactoryAware) {
            ((BeanFactoryAware) this.correlationStrategy).setBeanFactory(beanFactory);
        }
        if (this.releaseStrategy instanceof BeanFactoryAware) {
            ((BeanFactoryAware) this.releaseStrategy).setBeanFactory(beanFactory);
        }
    }
    if (this.discardChannel == null) {
        this.discardChannel = new NullChannel();
    }
    if (this.releasePartialSequences) {
        Assert.isInstanceOf(SequenceSizeReleaseStrategy.class, this.releaseStrategy, "Release strategy of type [" + this.releaseStrategy.getClass().getSimpleName() + "] cannot release partial sequences. Use a SequenceSizeReleaseStrategy instead.");
        ((SequenceSizeReleaseStrategy) this.releaseStrategy).setReleasePartialSequences(this.releasePartialSequences);
    }
    if (this.evaluationContext == null) {
        this.evaluationContext = ExpressionUtils.createStandardEvaluationContext(getBeanFactory());
    }
    if (this.sequenceAware) {
        this.logger.warn("Using a SequenceSizeReleaseStrategy with large groups may not perform well, consider " + "using a SimpleSequenceSizeReleaseStrategy");
    }
    /*
		 * Disallow any further changes to the lock registry
		 * (checked in the setter).
		 */
    this.lockRegistrySet = true;
    this.forceReleaseProcessor = createGroupTimeoutProcessor();
}
Also used : BeanFactoryAware(org.springframework.beans.factory.BeanFactoryAware) BeanFactory(org.springframework.beans.factory.BeanFactory) NullChannel(org.springframework.integration.channel.NullChannel)

Example 13 with NullChannel

use of org.springframework.integration.channel.NullChannel in project spring-integration by spring-projects.

the class ResequencerParserTests method testDefaultResequencerProperties.

@Test
public void testDefaultResequencerProperties() {
    EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("defaultResequencer");
    ResequencingMessageHandler resequencer = TestUtils.getPropertyValue(endpoint, "handler", ResequencingMessageHandler.class);
    assertNull(getPropertyValue(resequencer, "outputChannel"));
    assertTrue(getPropertyValue(resequencer, "discardChannel") instanceof NullChannel);
    assertEquals("The ResequencerEndpoint is not set with the appropriate timeout value", -1L, getPropertyValue(resequencer, "messagingTemplate.sendTimeout"));
    assertEquals("The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' flag", false, getPropertyValue(resequencer, "sendPartialResultOnExpiry"));
    assertEquals("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag", false, getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"));
}
Also used : EventDrivenConsumer(org.springframework.integration.endpoint.EventDrivenConsumer) ResequencingMessageHandler(org.springframework.integration.aggregator.ResequencingMessageHandler) NullChannel(org.springframework.integration.channel.NullChannel) Test(org.junit.Test)

Example 14 with NullChannel

use of org.springframework.integration.channel.NullChannel in project spring-integration by spring-projects.

the class TailAdapterSpec method doGet.

@Override
protected FileTailingMessageProducerSupport doGet() {
    if (this.outputChannel == null) {
        this.factoryBean.setOutputChannel(new NullChannel());
    }
    FileTailingMessageProducerSupport tailingMessageProducerSupport = null;
    try {
        this.factoryBean.afterPropertiesSet();
        tailingMessageProducerSupport = this.factoryBean.getObject();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
    if (this.errorChannel != null) {
        tailingMessageProducerSupport.setErrorChannel(this.errorChannel);
    }
    tailingMessageProducerSupport.setOutputChannel(this.outputChannel);
    return tailingMessageProducerSupport;
}
Also used : FileTailingMessageProducerSupport(org.springframework.integration.file.tail.FileTailingMessageProducerSupport) NullChannel(org.springframework.integration.channel.NullChannel)

Example 15 with NullChannel

use of org.springframework.integration.channel.NullChannel in project spring-integration by spring-projects.

the class PollingLifecycleTests method testAdapterLifecycleIsPropagatedToMessageSource.

@Test
public void testAdapterLifecycleIsPropagatedToMessageSource() throws Exception {
    SourcePollingChannelAdapterFactoryBean adapterFactory = new SourcePollingChannelAdapterFactoryBean();
    adapterFactory.setOutputChannel(new NullChannel());
    adapterFactory.setBeanFactory(mock(ConfigurableBeanFactory.class));
    PollerMetadata pollerMetadata = new PollerMetadata();
    pollerMetadata.setTrigger(new PeriodicTrigger(2000));
    adapterFactory.setPollerMetadata(pollerMetadata);
    final AtomicBoolean startInvoked = new AtomicBoolean();
    final AtomicBoolean stopInvoked = new AtomicBoolean();
    MethodInvokingMessageSource source = new MethodInvokingMessageSource();
    source.setObject(new Lifecycle() {

        @Override
        public void start() {
            startInvoked.set(true);
        }

        @Override
        public void stop() {
            stopInvoked.set(true);
        }

        @Override
        public boolean isRunning() {
            return false;
        }
    });
    source.setMethodName("isRunning");
    adapterFactory.setSource(source);
    SourcePollingChannelAdapter adapter = adapterFactory.getObject();
    adapter.setTaskScheduler(this.taskScheduler);
    adapter.start();
    adapter.stop();
    assertTrue(startInvoked.get());
    assertTrue(stopInvoked.get());
}
Also used : ConfigurableBeanFactory(org.springframework.beans.factory.config.ConfigurableBeanFactory) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SourcePollingChannelAdapterFactoryBean(org.springframework.integration.config.SourcePollingChannelAdapterFactoryBean) Lifecycle(org.springframework.context.Lifecycle) NullChannel(org.springframework.integration.channel.NullChannel) PollerMetadata(org.springframework.integration.scheduling.PollerMetadata) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Test(org.junit.Test)

Aggregations

NullChannel (org.springframework.integration.channel.NullChannel)19 Test (org.junit.Test)12 BeanFactory (org.springframework.beans.factory.BeanFactory)10 ThreadPoolTaskScheduler (org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler)7 File (java.io.File)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 Log (org.apache.commons.logging.Log)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 Message (org.springframework.amqp.core.Message)2 AsyncRabbitTemplate (org.springframework.amqp.rabbit.AsyncRabbitTemplate)2 ConnectionFactory (org.springframework.amqp.rabbit.connection.ConnectionFactory)2 RabbitTemplate (org.springframework.amqp.rabbit.core.RabbitTemplate)2 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)2 ApplicationEventPublisher (org.springframework.context.ApplicationEventPublisher)2 TaskScheduler (org.springframework.scheduling.TaskScheduler)2 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)2 BufferedOutputStream (java.io.BufferedOutputStream)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileInputStream (java.io.FileInputStream)1