use of org.springframework.cloud.stream.binder.ConsumerProperties in project spring-cloud-stream by spring-cloud.
the class BindingServiceTests method testConsumerPropertiesValidation.
@Test
public void testConsumerPropertiesValidation() {
BindingServiceProperties serviceProperties = new BindingServiceProperties();
Map<String, BindingProperties> bindingProperties = new HashMap<>();
BindingProperties props = new BindingProperties();
ConsumerProperties consumerProperties = new ConsumerProperties();
consumerProperties.setConcurrency(0);
props.setDestination("foo");
props.setConsumer(consumerProperties);
final String inputChannelName = "input";
bindingProperties.put(inputChannelName, props);
serviceProperties.setBindings(bindingProperties);
DefaultBinderFactory binderFactory = createMockBinderFactory();
BindingService service = new BindingService(serviceProperties, binderFactory);
MessageChannel inputChannel = new DirectChannel();
try {
service.bindConsumer(inputChannel, inputChannelName);
fail("Consumer properties should be validated.");
} catch (IllegalStateException e) {
assertThat(e).hasMessageContaining("Concurrency should be greater than zero.");
}
}
use of org.springframework.cloud.stream.binder.ConsumerProperties in project spring-cloud-stream by spring-cloud.
the class MessageConverterConfigurer method configureMessageChannel.
/**
* Setup data-type and message converters for the given message channel.
*
* @param channel message channel to set the data-type and message converters
* @param channelName the channel name
* @param inbound inbound (i.e., "input") or outbound channel
*/
private void configureMessageChannel(MessageChannel channel, String channelName, boolean inbound) {
Assert.isAssignable(AbstractMessageChannel.class, channel.getClass());
AbstractMessageChannel messageChannel = (AbstractMessageChannel) channel;
BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(channelName);
String contentType = bindingProperties.getContentType();
ProducerProperties producerProperties = bindingProperties.getProducer();
if (!inbound && producerProperties != null && producerProperties.isPartitioned()) {
messageChannel.addInterceptor(new PartitioningInterceptor(bindingProperties, getPartitionKeyExtractorStrategy(producerProperties), getPartitionSelectorStrategy(producerProperties)));
}
ConsumerProperties consumerProperties = bindingProperties.getConsumer();
if (this.isNativeEncodingNotSet(producerProperties, consumerProperties, inbound)) {
if (inbound) {
messageChannel.addInterceptor(new InboundContentTypeEnhancingInterceptor(contentType));
} else {
messageChannel.addInterceptor(new OutboundContentTypeConvertingInterceptor(contentType, this.compositeMessageConverterFactory.getMessageConverterForAllRegistered()));
}
}
}
use of org.springframework.cloud.stream.binder.ConsumerProperties in project spring-cloud-stream by spring-cloud.
the class MessageConverterConfigurer method configurePolledMessageSource.
@Override
public void configurePolledMessageSource(PollableMessageSource binding, String name) {
BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(name);
String contentType = bindingProperties.getContentType();
ConsumerProperties consumerProperties = bindingProperties.getConsumer();
if ((consumerProperties == null || !consumerProperties.isUseNativeDecoding()) && binding instanceof DefaultPollableMessageSource) {
((DefaultPollableMessageSource) binding).addInterceptor(new InboundContentTypeEnhancingInterceptor(contentType));
}
}
use of org.springframework.cloud.stream.binder.ConsumerProperties in project spring-cloud-consul by spring-cloud.
the class TestConsumer method run.
@Override
public void run(ApplicationArguments args) throws Exception {
logger.info("Consumer running with binder {}", binder);
SubscribableChannel consumerChannel = new ExecutorSubscribableChannel();
consumerChannel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
messagePayload = (String) message.getPayload();
logger.info("Received message: {}", messagePayload);
}
});
String group = null;
if (args.containsOption("group")) {
group = args.getOptionValues("group").get(0);
}
binder.bindConsumer(ConsulBinderTests.BINDING_NAME, group, consumerChannel, new ConsumerProperties());
isBound = true;
}
use of org.springframework.cloud.stream.binder.ConsumerProperties in project spring-cloud-stream by spring-cloud.
the class BindingServiceProperties method getConsumerProperties.
public ConsumerProperties getConsumerProperties(String inputBindingName) {
Assert.notNull(inputBindingName, "The input binding name cannot be null");
BindingProperties bindingProperties = getBindingProperties(inputBindingName);
ConsumerProperties consumerProperties = bindingProperties.getConsumer();
if (consumerProperties == null) {
consumerProperties = new ConsumerProperties();
bindingProperties.setConsumer(consumerProperties);
}
// propagate instance count and instance index if not already set
if (consumerProperties.getInstanceCount() < 0) {
consumerProperties.setInstanceCount(this.instanceCount);
}
if (consumerProperties.getInstanceIndex() < 0) {
consumerProperties.setInstanceIndex(this.instanceIndex);
}
return consumerProperties;
}
Aggregations