Search in sources :

Example 1 with BinderFactory

use of org.springframework.cloud.stream.binder.BinderFactory in project spring-cloud-gcp by spring-cloud.

the class PubSubExtendedBindingsPropertiesTests method testExtendedPropertiesOverrideDefaults.

@Test
public void testExtendedPropertiesOverrideDefaults() {
    BinderFactory binderFactory = this.context.getBeanFactory().getBean(BinderFactory.class);
    PubSubMessageChannelBinder binder = (PubSubMessageChannelBinder) binderFactory.getBinder("pubsub", MessageChannel.class);
    assertThat(binder.getExtendedConsumerProperties("custom-in").isAutoCreateResources()).isFalse();
    assertThat(binder.getExtendedConsumerProperties("input").isAutoCreateResources()).isTrue();
    assertThat(binder.getExtendedConsumerProperties("custom-in").getAckMode()).isEqualTo(AckMode.AUTO);
    assertThat(binder.getExtendedConsumerProperties("input").getAckMode()).isEqualTo(AckMode.AUTO_ACK);
}
Also used : PubSubMessageChannelBinder(org.springframework.cloud.gcp.stream.binder.pubsub.PubSubMessageChannelBinder) BinderFactory(org.springframework.cloud.stream.binder.BinderFactory) MessageChannel(org.springframework.messaging.MessageChannel) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with BinderFactory

use of org.springframework.cloud.stream.binder.BinderFactory in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method testUnrecognizedBinderAllowedIfNotUsed.

@SuppressWarnings("unchecked")
@Test
public void testUnrecognizedBinderAllowedIfNotUsed() {
    HashMap<String, String> properties = new HashMap<>();
    properties.put("spring.cloud.stream.bindings.input.destination", "fooInput");
    properties.put("spring.cloud.stream.bindings.output.destination", "fooOutput");
    properties.put("spring.cloud.stream.defaultBinder", "mock1");
    properties.put("spring.cloud.stream.binders.mock1.type", "mock");
    properties.put("spring.cloud.stream.binders.kafka1.type", "kafka");
    BindingServiceProperties bindingServiceProperties = createBindingServiceProperties(properties);
    BinderFactory binderFactory = new BindingServiceConfiguration().binderFactory(createMockBinderTypeRegistry(), bindingServiceProperties, Mockito.mock(ObjectProvider.class));
    BindingService bindingService = new BindingService(bindingServiceProperties, binderFactory, new ObjectMapper());
    bindingService.bindConsumer(new DirectChannel(), "input");
    bindingService.bindProducer(new DirectChannel(), "output");
}
Also used : BindingServiceConfiguration(org.springframework.cloud.stream.config.BindingServiceConfiguration) DefaultBinderFactory(org.springframework.cloud.stream.binder.DefaultBinderFactory) BinderFactory(org.springframework.cloud.stream.binder.BinderFactory) HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) ObjectProvider(org.springframework.beans.factory.ObjectProvider) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with BinderFactory

use of org.springframework.cloud.stream.binder.BinderFactory in project spring-cloud-stream by spring-cloud.

the class BindingServiceTests method testUnrecognizedBinderDisallowedIfUsed.

@SuppressWarnings("unchecked")
@Test
public void testUnrecognizedBinderDisallowedIfUsed() {
    HashMap<String, String> properties = new HashMap<>();
    properties.put("spring.cloud.stream.bindings.input.destination", "fooInput");
    properties.put("spring.cloud.stream.bindings.input.binder", "mock1");
    properties.put("spring.cloud.stream.bindings.output.destination", "fooOutput");
    properties.put("spring.cloud.stream.bindings.output.type", "kafka1");
    properties.put("spring.cloud.stream.binders.mock1.type", "mock");
    properties.put("spring.cloud.stream.binders.kafka1.type", "kafka");
    BindingServiceProperties bindingServiceProperties = createBindingServiceProperties(properties);
    BinderFactory binderFactory = new BindingServiceConfiguration().binderFactory(createMockBinderTypeRegistry(), bindingServiceProperties, Mockito.mock(ObjectProvider.class));
    BindingService bindingService = new BindingService(bindingServiceProperties, binderFactory, new ObjectMapper());
    bindingService.bindConsumer(new DirectChannel(), "input");
    try {
        bindingService.bindProducer(new DirectChannel(), "output");
        fail("Expected 'Unknown binder configuration'");
    } catch (IllegalArgumentException e) {
        assertThat(e).hasMessageContaining("Binder type kafka is not defined");
    }
}
Also used : BindingServiceConfiguration(org.springframework.cloud.stream.config.BindingServiceConfiguration) DefaultBinderFactory(org.springframework.cloud.stream.binder.DefaultBinderFactory) BinderFactory(org.springframework.cloud.stream.binder.BinderFactory) HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) ObjectProvider(org.springframework.beans.factory.ObjectProvider) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with BinderFactory

use of org.springframework.cloud.stream.binder.BinderFactory in project spring-cloud-stream by spring-cloud.

the class StreamBridge method resolveDestination.

@SuppressWarnings({ "unchecked" })
synchronized MessageChannel resolveDestination(String destinationName, ProducerProperties producerProperties, String binderName) {
    MessageChannel messageChannel = this.channelCache.get(destinationName);
    if (messageChannel == null && this.applicationContext.containsBean(destinationName)) {
        messageChannel = this.applicationContext.getBean(destinationName, MessageChannel.class);
    }
    if (messageChannel == null) {
        messageChannel = new DirectWithAttributesChannel();
        if (this.destinationBindingCallback != null) {
            Object extendedProducerProperties = this.bindingService.getExtendedProducerProperties(messageChannel, destinationName);
            this.destinationBindingCallback.configure(destinationName, messageChannel, producerProperties, extendedProducerProperties);
        }
        Binder binder = null;
        if (StringUtils.hasText(binderName)) {
            BinderFactory binderFactory = this.applicationContext.getBean(BinderFactory.class);
            binder = binderFactory.getBinder(binderName, messageChannel.getClass());
        }
        if (producerProperties != null && producerProperties.isPartitioned()) {
            BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(destinationName);
            ((AbstractMessageChannel) messageChannel).addInterceptor(new DefaultPartitioningInterceptor(bindingProperties, this.applicationContext.getBeanFactory()));
        }
        this.addInterceptors((AbstractMessageChannel) messageChannel, destinationName);
        this.bindingService.bindProducer(messageChannel, destinationName, false, binder);
        this.channelCache.put(destinationName, messageChannel);
    }
    return messageChannel;
}
Also used : Binder(org.springframework.cloud.stream.binder.Binder) BinderFactory(org.springframework.cloud.stream.binder.BinderFactory) DefaultPartitioningInterceptor(org.springframework.cloud.stream.binding.DefaultPartitioningInterceptor) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) MessageChannel(org.springframework.messaging.MessageChannel) AbstractMessageChannel(org.springframework.integration.channel.AbstractMessageChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) DirectWithAttributesChannel(org.springframework.cloud.stream.messaging.DirectWithAttributesChannel)

Aggregations

BinderFactory (org.springframework.cloud.stream.binder.BinderFactory)4 Test (org.junit.Test)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 HashMap (java.util.HashMap)2 ObjectProvider (org.springframework.beans.factory.ObjectProvider)2 DefaultBinderFactory (org.springframework.cloud.stream.binder.DefaultBinderFactory)2 BindingServiceConfiguration (org.springframework.cloud.stream.config.BindingServiceConfiguration)2 BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 MessageChannel (org.springframework.messaging.MessageChannel)2 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 PubSubMessageChannelBinder (org.springframework.cloud.gcp.stream.binder.pubsub.PubSubMessageChannelBinder)1 Binder (org.springframework.cloud.stream.binder.Binder)1 DefaultPartitioningInterceptor (org.springframework.cloud.stream.binding.DefaultPartitioningInterceptor)1 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)1 DirectWithAttributesChannel (org.springframework.cloud.stream.messaging.DirectWithAttributesChannel)1 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)1