Search in sources :

Example 6 with ProducerProperties

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

the class BindingService method bindProducer.

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> Binding<T> bindProducer(T output, String outputName) {
    String bindingTarget = this.bindingServiceProperties.getBindingDestination(outputName);
    Binder<T, ?, ProducerProperties> binder = (Binder<T, ?, ProducerProperties>) getBinder(outputName, output.getClass());
    ProducerProperties producerProperties = this.bindingServiceProperties.getProducerProperties(outputName);
    if (binder instanceof ExtendedPropertiesBinder) {
        Object extension = ((ExtendedPropertiesBinder) binder).getExtendedProducerProperties(outputName);
        ExtendedProducerProperties extendedProducerProperties = new ExtendedProducerProperties<>(extension);
        BeanUtils.copyProperties(producerProperties, extendedProducerProperties);
        producerProperties = extendedProducerProperties;
    }
    validate(producerProperties);
    Binding<T> binding = doBindProducer(output, bindingTarget, binder, producerProperties);
    this.producerBindings.put(outputName, binding);
    return binding;
}
Also used : PollableConsumerBinder(org.springframework.cloud.stream.binder.PollableConsumerBinder) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) DataBinder(org.springframework.validation.DataBinder) Binder(org.springframework.cloud.stream.binder.Binder) ExtendedProducerProperties(org.springframework.cloud.stream.binder.ExtendedProducerProperties) ProducerProperties(org.springframework.cloud.stream.binder.ProducerProperties) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder) ExtendedProducerProperties(org.springframework.cloud.stream.binder.ExtendedProducerProperties)

Example 7 with ProducerProperties

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

the class BindingServiceTests method testProducerPropertiesValidation.

@Test
public void testProducerPropertiesValidation() {
    BindingServiceProperties serviceProperties = new BindingServiceProperties();
    Map<String, BindingProperties> bindingProperties = new HashMap<>();
    BindingProperties props = new BindingProperties();
    ProducerProperties producerProperties = new ProducerProperties();
    producerProperties.setPartitionCount(0);
    props.setDestination("foo");
    props.setProducer(producerProperties);
    final String outputChannelName = "output";
    bindingProperties.put(outputChannelName, props);
    serviceProperties.setBindings(bindingProperties);
    DefaultBinderFactory binderFactory = createMockBinderFactory();
    BindingService service = new BindingService(serviceProperties, binderFactory);
    MessageChannel outputChannel = new DirectChannel();
    try {
        service.bindProducer(outputChannel, outputChannelName);
        fail("Producer properties should be validated.");
    } catch (IllegalStateException e) {
        assertThat(e).hasMessageContaining("Partition count should be greater than zero.");
    }
}
Also used : ProducerProperties(org.springframework.cloud.stream.binder.ProducerProperties) ExtendedProducerProperties(org.springframework.cloud.stream.binder.ExtendedProducerProperties) MessageChannel(org.springframework.messaging.MessageChannel) HashMap(java.util.HashMap) DirectChannel(org.springframework.integration.channel.DirectChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DefaultBinderFactory(org.springframework.cloud.stream.binder.DefaultBinderFactory) Test(org.junit.Test)

Aggregations

ProducerProperties (org.springframework.cloud.stream.binder.ProducerProperties)7 ExtendedProducerProperties (org.springframework.cloud.stream.binder.ExtendedProducerProperties)3 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)3 BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)3 MessageChannel (org.springframework.messaging.MessageChannel)3 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 ConsumerProperties (org.springframework.cloud.stream.binder.ConsumerProperties)2 DefaultBinderFactory (org.springframework.cloud.stream.binder.DefaultBinderFactory)2 ExtendedPropertiesBinder (org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)2 DirectChannel (org.springframework.integration.channel.DirectChannel)2 DestinationResolutionException (org.springframework.messaging.core.DestinationResolutionException)2 HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 NoSuchBeanDefinitionException (org.springframework.beans.factory.NoSuchBeanDefinitionException)1 ConfigurableListableBeanFactory (org.springframework.beans.factory.config.ConfigurableListableBeanFactory)1 Binder (org.springframework.cloud.stream.binder.Binder)1