Search in sources :

Example 6 with ConsumerProperties

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

the class BindingService method bindConsumer.

@SuppressWarnings({ "unchecked", "rawtypes" })
public <T> Collection<Binding<T>> bindConsumer(T input, String inputName) {
    String bindingTarget = this.bindingServiceProperties.getBindingDestination(inputName);
    String[] bindingTargets = StringUtils.commaDelimitedListToStringArray(bindingTarget);
    Collection<Binding<T>> bindings = new ArrayList<>();
    Binder<T, ConsumerProperties, ?> binder = (Binder<T, ConsumerProperties, ?>) getBinder(inputName, input.getClass());
    ConsumerProperties consumerProperties = this.bindingServiceProperties.getConsumerProperties(inputName);
    if (binder instanceof ExtendedPropertiesBinder) {
        Object extension = ((ExtendedPropertiesBinder) binder).getExtendedConsumerProperties(inputName);
        ExtendedConsumerProperties extendedConsumerProperties = new ExtendedConsumerProperties(extension);
        BeanUtils.copyProperties(consumerProperties, extendedConsumerProperties);
        consumerProperties = extendedConsumerProperties;
    }
    validate(consumerProperties);
    for (String target : bindingTargets) {
        Binding<T> binding;
        if (input instanceof PollableSource) {
            binding = doBindPollableConsumer(input, inputName, binder, consumerProperties, target);
        } else {
            binding = doBindConsumer(input, inputName, binder, consumerProperties, target);
        }
        bindings.add(binding);
    }
    bindings = Collections.unmodifiableCollection(bindings);
    this.consumerBindings.put(inputName, new ArrayList<Binding<?>>(bindings));
    return bindings;
}
Also used : Binding(org.springframework.cloud.stream.binder.Binding) ExtendedConsumerProperties(org.springframework.cloud.stream.binder.ExtendedConsumerProperties) ArrayList(java.util.ArrayList) ExtendedConsumerProperties(org.springframework.cloud.stream.binder.ExtendedConsumerProperties) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) PollableSource(org.springframework.cloud.stream.binder.PollableSource) 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) ExtendedPropertiesBinder(org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)

Example 7 with ConsumerProperties

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

the class PartitionedConsumerTest method testBindingPartitionedConsumer.

@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testBindingPartitionedConsumer() {
    Binder binder = this.binderFactory.getBinder(null, MessageChannel.class);
    ArgumentCaptor<ConsumerProperties> argumentCaptor = ArgumentCaptor.forClass(ConsumerProperties.class);
    verify(binder).bindConsumer(eq("partIn"), isNull(), eq(this.testSink.input()), argumentCaptor.capture());
    Assert.assertThat(argumentCaptor.getValue().getInstanceIndex(), equalTo(0));
    Assert.assertThat(argumentCaptor.getValue().getInstanceCount(), equalTo(2));
    verifyNoMoreInteractions(binder);
}
Also used : Binder(org.springframework.cloud.stream.binder.Binder) ConsumerProperties(org.springframework.cloud.stream.binder.ConsumerProperties) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ConsumerProperties (org.springframework.cloud.stream.binder.ConsumerProperties)7 BindingProperties (org.springframework.cloud.stream.config.BindingProperties)3 Test (org.junit.Test)2 Binder (org.springframework.cloud.stream.binder.Binder)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Binding (org.springframework.cloud.stream.binder.Binding)1 DefaultBinderFactory (org.springframework.cloud.stream.binder.DefaultBinderFactory)1 DefaultPollableMessageSource (org.springframework.cloud.stream.binder.DefaultPollableMessageSource)1 ExtendedConsumerProperties (org.springframework.cloud.stream.binder.ExtendedConsumerProperties)1 ExtendedPropertiesBinder (org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)1 PollableConsumerBinder (org.springframework.cloud.stream.binder.PollableConsumerBinder)1 PollableSource (org.springframework.cloud.stream.binder.PollableSource)1 ProducerProperties (org.springframework.cloud.stream.binder.ProducerProperties)1 BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)1 AbstractMessageChannel (org.springframework.integration.channel.AbstractMessageChannel)1 DirectChannel (org.springframework.integration.channel.DirectChannel)1 MessageChannel (org.springframework.messaging.MessageChannel)1