Search in sources :

Example 31 with BindingProperties

use of org.springframework.cloud.stream.config.BindingProperties in project spring-cloud-stream by spring-cloud.

the class MessageConverterConfigurerTests method testConfigureOutputChannelWithBadContentType.

// @Test
public void testConfigureOutputChannelWithBadContentType() {
    BindingServiceProperties props = new BindingServiceProperties();
    BindingProperties bindingProps = new BindingProperties();
    bindingProps.setContentType("application/json");
    props.setBindings(Collections.singletonMap("foo", bindingProps));
    CompositeMessageConverterFactory converterFactory = new CompositeMessageConverterFactory(Collections.<MessageConverter>emptyList(), null);
    MessageConverterConfigurer configurer = new MessageConverterConfigurer(props, converterFactory);
    QueueChannel out = new QueueChannel();
    configurer.configureOutputChannel(out, "foo");
    out.send(new GenericMessage<Foo>(new Foo(), Collections.<String, Object>singletonMap(MessageHeaders.CONTENT_TYPE, "bad/ct")));
    Message<?> received = out.receive(0);
    assertThat(received).isNotNull();
    assertThat(received.getPayload()).isInstanceOf(Foo.class);
}
Also used : QueueChannel(org.springframework.integration.channel.QueueChannel) BindingProperties(org.springframework.cloud.stream.config.BindingProperties) BindingServiceProperties(org.springframework.cloud.stream.config.BindingServiceProperties) CompositeMessageConverterFactory(org.springframework.cloud.stream.converter.CompositeMessageConverterFactory)

Example 32 with BindingProperties

use of org.springframework.cloud.stream.config.BindingProperties in project spring-cloud-stream by spring-cloud.

the class SourceBindingWithGlobalPropertiesTest method testGlobalPropertiesSet.

@Test
public void testGlobalPropertiesSet() {
    BindingProperties bindingProperties = serviceProperties.getBindingProperties(Source.OUTPUT);
    Assertions.assertThat(bindingProperties.getContentType()).isEqualTo("application/json");
    Assertions.assertThat(bindingProperties.getDestination()).isEqualTo("ticktock");
    Assertions.assertThat(bindingProperties.getProducer().getRequiredGroups()).containsExactly("someGroup");
    Assertions.assertThat(bindingProperties.getProducer().getHeaderMode()).isEqualTo(HeaderMode.none);
}
Also used : BindingProperties(org.springframework.cloud.stream.config.BindingProperties) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 33 with BindingProperties

use of org.springframework.cloud.stream.config.BindingProperties in project spring-cloud-stream by spring-cloud.

the class ChannelsEndpoint method channels.

@ReadOperation
public Map<String, Object> channels() {
    ChannelsMetaData map = new ChannelsMetaData();
    Map<String, BindingProperties> inputs = map.getInputs();
    Map<String, BindingProperties> outputs = map.getOutputs();
    for (Bindable factory : this.adapters) {
        for (String name : factory.getInputs()) {
            inputs.put(name, this.properties.getBindingProperties(name));
        }
        for (String name : factory.getOutputs()) {
            outputs.put(name, this.properties.getBindingProperties(name));
        }
    }
    return new ObjectMapper().convertValue(map, new TypeReference<Map<String, Object>>() {
    });
}
Also used : BindingProperties(org.springframework.cloud.stream.config.BindingProperties) Bindable(org.springframework.cloud.stream.binding.Bindable) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ReadOperation(org.springframework.boot.actuate.endpoint.annotation.ReadOperation)

Example 34 with BindingProperties

use of org.springframework.cloud.stream.config.BindingProperties in project spring-cloud-netflix by spring-cloud.

the class HystrixStreamAutoConfiguration method init.

@PostConstruct
public void init() {
    BindingProperties outputBinding = this.bindings.getBindings().get(HystrixStreamClient.OUTPUT);
    if (outputBinding == null) {
        this.bindings.getBindings().put(HystrixStreamClient.OUTPUT, new BindingProperties());
    }
    BindingProperties output = this.bindings.getBindings().get(HystrixStreamClient.OUTPUT);
    if (output.getDestination() == null) {
        output.setDestination(this.properties.getDestination());
    }
    if (output.getContentType() == null) {
        output.setContentType(this.properties.getContentType());
    }
}
Also used : BindingProperties(org.springframework.cloud.stream.config.BindingProperties) PostConstruct(javax.annotation.PostConstruct)

Aggregations

BindingProperties (org.springframework.cloud.stream.config.BindingProperties)34 Test (org.junit.Test)26 DirectChannel (org.springframework.integration.channel.DirectChannel)21 MessageChannel (org.springframework.messaging.MessageChannel)21 BindingServiceProperties (org.springframework.cloud.stream.config.BindingServiceProperties)12 QueueChannel (org.springframework.integration.channel.QueueChannel)10 Message (org.springframework.messaging.Message)9 HashMap (java.util.HashMap)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 ConsumerProperties (org.springframework.cloud.stream.binder.ConsumerProperties)8 DefaultBinderFactory (org.springframework.cloud.stream.binder.DefaultBinderFactory)8 CountDownLatch (java.util.concurrent.CountDownLatch)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 ExtendedPropertiesBinder (org.springframework.cloud.stream.binder.ExtendedPropertiesBinder)6 Binder (org.springframework.cloud.stream.binder.Binder)5 Binding (org.springframework.cloud.stream.binder.Binding)5 StreamListenerMessageHandler (org.springframework.cloud.stream.binding.StreamListenerMessageHandler)5 ProducerProperties (org.springframework.cloud.stream.binder.ProducerProperties)4 CompositeMessageConverterFactory (org.springframework.cloud.stream.converter.CompositeMessageConverterFactory)4 ExtendedProducerProperties (org.springframework.cloud.stream.binder.ExtendedProducerProperties)3