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
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
provisioningProviderFields inherited from class org.springframework.cloud.stream.binder.AbstractBinder
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected org.springframework.integration.core.MessageProducercreateConsumerEndpoint(org.springframework.cloud.stream.provisioning.ConsumerDestination destination, String group, org.springframework.cloud.stream.binder.ConsumerProperties properties) protected org.springframework.cloud.stream.binder.AbstractMessageChannelBinder.PolledConsumerResourcescreatePolledConsumerResources(String name, String group, org.springframework.cloud.stream.provisioning.ConsumerDestination destination, org.springframework.cloud.stream.binder.ConsumerProperties consumerProperties) protected org.springframework.messaging.MessageHandlercreateProducerMessageHandler(org.springframework.cloud.stream.provisioning.ProducerDestination destination, org.springframework.cloud.stream.binder.ProducerProperties producerProperties, org.springframework.messaging.MessageChannel errorChannel) protected org.springframework.messaging.MessageHandlergetErrorMessageHandler(org.springframework.cloud.stream.provisioning.ConsumerDestination destination, String group, org.springframework.cloud.stream.binder.ConsumerProperties consumerProperties) org.springframework.messaging.Message<?> voidvoidsetMessageSourceDelegate(org.springframework.integration.core.MessageSource<byte[]> messageSourceDelegate) Set a delegateMessageSourcefor 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, useNativeEncodingMethods inherited from class org.springframework.cloud.stream.binder.AbstractBinder
afterPropertiesSet, applyPrefix, bindConsumer, bindProducer, buildRetryTemplate, constructDLQName, getApplicationContext, getBeanFactory, getBindingServiceProperties, getEvaluationContext, groupedName, setApplicationContextMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.cloud.stream.binder.Binder
getBinderIdentity
-
Constructor Details
-
TestChannelBinder
-
-
Method Details
-
setMessageSourceDelegate
@Autowired(required=false) public void setMessageSourceDelegate(org.springframework.integration.core.MessageSource<byte[]> messageSourceDelegate) Set a delegateMessageSourcefor 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:
createProducerMessageHandlerin classorg.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:
createConsumerEndpointin classorg.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:
createPolledConsumerResourcesin classorg.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:
getErrorMessageHandlerin classorg.springframework.cloud.stream.binder.AbstractMessageChannelBinder<org.springframework.cloud.stream.binder.ConsumerProperties, org.springframework.cloud.stream.binder.ProducerProperties, TestChannelBinderProvisioner>
-