Class TestChannelBinder

java.lang.Object
org.springframework.cloud.stream.binder.AbstractBinder<org.springframework.messaging.MessageChannel, org.springframework.cloud.stream.binder.ConsumerProperties, org.springframework.cloud.stream.binder.ProducerProperties>
org.springframework.cloud.stream.binder.AbstractMessageChannelBinder<org.springframework.cloud.stream.binder.ConsumerProperties, org.springframework.cloud.stream.binder.ProducerProperties, TestChannelBinderProvisioner>
org.springframework.cloud.stream.binder.test.TestChannelBinder
All Implemented Interfaces:
org.springframework.beans.factory.Aware, org.springframework.beans.factory.InitializingBean, org.springframework.cloud.stream.binder.Binder<org.springframework.messaging.MessageChannel, org.springframework.cloud.stream.binder.ConsumerProperties, org.springframework.cloud.stream.binder.ProducerProperties>, org.springframework.cloud.stream.binder.PollableConsumerBinder<org.springframework.messaging.MessageHandler, org.springframework.cloud.stream.binder.ConsumerProperties>, org.springframework.context.ApplicationContextAware, org.springframework.context.ApplicationEventPublisherAware

public class TestChannelBinder extends org.springframework.cloud.stream.binder.AbstractMessageChannelBinder<org.springframework.cloud.stream.binder.ConsumerProperties, org.springframework.cloud.stream.binder.ProducerProperties, TestChannelBinderProvisioner>
Implementation of Binder backed by the Spring Integration framework. It is useful for localized demos and testing.

This binder extends from the same base class (AbstractMessageChannelBinder) as other binders (i.e., Rabbit, Kafka etc.). Interaction with this binder is done via source and target destination which emulate real binder's destinations (i.e., Kafka topic)
The destination classes are

Simply autowire them in your application and send/receive messages.

You must also add TestChannelBinderConfiguration to your configuration. Below is the example using Spring Boot test.

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(classes = {SpringIntegrationBinderConfiguration.class, TestWithSIBinder.MyProcessor.class})
public class TestWithSIBinder {
    @Autowired
    private SourceDestination sourceDestination;

    @Autowired
    private TargetDestination targetDestination;

    @Test
    public void testWiring() {
        sourceDestination.send(new GenericMessage<String>("Hello"));
        assertEquals("Hello world",
            new String((byte[])targetDestination.receive().getPayload(), StandardCharsets.UTF_8));
    }

    @SpringBootApplication
    @EnableBinding(Processor.class)
    public static class MyProcessor {
        @StreamListener(Processor.INPUT)
        @SendTo(Processor.OUTPUT)
        public String transform(String in) {
            return in + " world";
        }
    }
}
Author:
Oleg Zhurakousky, Gary Russell, Artem Bilan
  • Nested Class Summary

    Nested classes/interfaces inherited from class org.springframework.cloud.stream.binder.AbstractMessageChannelBinder

    org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.ErrorInfrastructure, org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.PolledConsumerResources
  • Field Summary

    Fields inherited from class org.springframework.cloud.stream.binder.AbstractMessageChannelBinder

    provisioningProvider

    Fields inherited from class org.springframework.cloud.stream.binder.AbstractBinder

    logger
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.springframework.integration.core.MessageProducer
    createConsumerEndpoint(org.springframework.cloud.stream.provisioning.ConsumerDestination destination, String group, org.springframework.cloud.stream.binder.ConsumerProperties properties)
     
    protected org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.PolledConsumerResources
    createPolledConsumerResources(String name, String group, org.springframework.cloud.stream.provisioning.ConsumerDestination destination, org.springframework.cloud.stream.binder.ConsumerProperties consumerProperties)
     
    protected org.springframework.messaging.MessageHandler
    createProducerMessageHandler(org.springframework.cloud.stream.provisioning.ProducerDestination destination, org.springframework.cloud.stream.binder.ProducerProperties producerProperties, org.springframework.messaging.MessageChannel errorChannel)
     
    protected org.springframework.messaging.MessageHandler
    getErrorMessageHandler(org.springframework.cloud.stream.provisioning.ConsumerDestination destination, String group, org.springframework.cloud.stream.binder.ConsumerProperties consumerProperties)
     
    org.springframework.messaging.Message<?>
     
    void
     
    void
    setMessageSourceDelegate(org.springframework.integration.core.MessageSource<byte[]> messageSourceDelegate)
    Set a delegate MessageSource for pollable consumers.

    Methods inherited from class org.springframework.cloud.stream.binder.AbstractMessageChannelBinder

    afterUnbindConsumer, afterUnbindProducer, bindPollableConsumer, createProducerMessageHandler, customizeProducerMessageHandler, doBindConsumer, doBindProducer, doGetAdditionalConfigurationProperties, errorsBaseName, errorsBaseName, getApplicationEventPublisher, getContainerCustomizer, getDefaultErrorMessageHandler, getErrorBridgeName, getErrorBridgeName, getErrorMessageHandlerName, getErrorMessageStrategy, getErrorRecovererName, getMessageSourceCustomizer, getPolledConsumerErrorMessageHandler, getPolledConsumerRecoveryCallback, onInit, postProcessOutputChannel, postProcessPollableSource, registerErrorInfrastructure, registerErrorInfrastructure, setApplicationEventPublisher, setConsumerEndpointCustomizer, setContainerCustomizer, setProducerMessageHandlerCustomizer, useNativeEncoding

    Methods inherited from class org.springframework.cloud.stream.binder.AbstractBinder

    afterPropertiesSet, applyPrefix, bindConsumer, bindProducer, buildRetryTemplate, constructDLQName, getApplicationContext, getBeanFactory, getBindingServiceProperties, getEvaluationContext, groupedName, setApplicationContext

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.springframework.cloud.stream.binder.Binder

    getBinderIdentity
  • Constructor Details

  • Method Details

    • setMessageSourceDelegate

      @Autowired(required=false) public void setMessageSourceDelegate(org.springframework.integration.core.MessageSource<byte[]> messageSourceDelegate)
      Set a delegate MessageSource for pollable consumers.
      Parameters:
      messageSourceDelegate - the delegate.
    • getLastError

      public org.springframework.messaging.Message<?> getLastError()
    • resetLastError

      public void resetLastError()
    • createProducerMessageHandler

      protected org.springframework.messaging.MessageHandler createProducerMessageHandler(org.springframework.cloud.stream.provisioning.ProducerDestination destination, org.springframework.cloud.stream.binder.ProducerProperties producerProperties, org.springframework.messaging.MessageChannel errorChannel) throws Exception
      Specified by:
      createProducerMessageHandler in class org.springframework.cloud.stream.binder.AbstractMessageChannelBinder<org.springframework.cloud.stream.binder.ConsumerProperties, org.springframework.cloud.stream.binder.ProducerProperties, TestChannelBinderProvisioner>
      Throws:
      Exception
    • createConsumerEndpoint

      protected org.springframework.integration.core.MessageProducer createConsumerEndpoint(org.springframework.cloud.stream.provisioning.ConsumerDestination destination, String group, org.springframework.cloud.stream.binder.ConsumerProperties properties) throws Exception
      Specified by:
      createConsumerEndpoint in class org.springframework.cloud.stream.binder.AbstractMessageChannelBinder<org.springframework.cloud.stream.binder.ConsumerProperties, org.springframework.cloud.stream.binder.ProducerProperties, TestChannelBinderProvisioner>
      Throws:
      Exception
    • createPolledConsumerResources

      protected org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.PolledConsumerResources createPolledConsumerResources(String name, String group, org.springframework.cloud.stream.provisioning.ConsumerDestination destination, org.springframework.cloud.stream.binder.ConsumerProperties consumerProperties)
      Overrides:
      createPolledConsumerResources in class org.springframework.cloud.stream.binder.AbstractMessageChannelBinder<org.springframework.cloud.stream.binder.ConsumerProperties, org.springframework.cloud.stream.binder.ProducerProperties, TestChannelBinderProvisioner>
    • getErrorMessageHandler

      protected org.springframework.messaging.MessageHandler getErrorMessageHandler(org.springframework.cloud.stream.provisioning.ConsumerDestination destination, String group, org.springframework.cloud.stream.binder.ConsumerProperties consumerProperties)
      Overrides:
      getErrorMessageHandler in class org.springframework.cloud.stream.binder.AbstractMessageChannelBinder<org.springframework.cloud.stream.binder.ConsumerProperties, org.springframework.cloud.stream.binder.ProducerProperties, TestChannelBinderProvisioner>