Search in sources :

Example 1 with PollableSource

use of org.springframework.cloud.stream.binder.PollableSource 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)

Aggregations

ArrayList (java.util.ArrayList)1 Binder (org.springframework.cloud.stream.binder.Binder)1 Binding (org.springframework.cloud.stream.binder.Binding)1 ConsumerProperties (org.springframework.cloud.stream.binder.ConsumerProperties)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 DataBinder (org.springframework.validation.DataBinder)1