Java Code Examples for org.springframework.cloud.stream.config.BindingProperties#getConsumer()

The following examples show how to use org.springframework.cloud.stream.config.BindingProperties#getConsumer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlobalKTableBoundElementFactory.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 8 votes vote down vote up
@Override
public GlobalKTable createInput(String name) {
	BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(name);
	ConsumerProperties consumerProperties = bindingProperties.getConsumer();
	if (consumerProperties == null) {
		consumerProperties = this.bindingServiceProperties.getConsumerProperties(name);
		consumerProperties.setUseNativeDecoding(true);
	}
	else {
		if (!encodingDecodingBindAdviceHandler.isDecodingSettingProvided()) {
			consumerProperties.setUseNativeDecoding(true);
		}
	}
	// Always set multiplex to true in the kafka streams binder
	consumerProperties.setMultiplex(true);

	// @checkstyle:off
	GlobalKTableBoundElementFactory.GlobalKTableWrapperHandler wrapper = new GlobalKTableBoundElementFactory.GlobalKTableWrapperHandler();
	// @checkstyle:on
	ProxyFactory proxyFactory = new ProxyFactory(
			GlobalKTableBoundElementFactory.GlobalKTableWrapper.class,
			GlobalKTable.class);
	proxyFactory.addAdvice(wrapper);

	return (GlobalKTable) proxyFactory.getProxy();
}
 
Example 2
Source File: KStreamBoundElementFactory.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@Override
public KStream createInput(String name) {
	BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(name);
	ConsumerProperties consumerProperties = bindingProperties.getConsumer();
	if (consumerProperties == null) {
		consumerProperties = this.bindingServiceProperties.getConsumerProperties(name);
		consumerProperties.setUseNativeDecoding(true);
	}
	else {
		if (!encodingDecodingBindAdviceHandler.isDecodingSettingProvided()) {
			consumerProperties.setUseNativeDecoding(true);
		}
	}
	// Always set multiplex to true in the kafka streams binder
	consumerProperties.setMultiplex(true);
	return createProxyForKStream(name);
}
 
Example 3
Source File: KTableBoundElementFactory.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 6 votes vote down vote up
@Override
public KTable createInput(String name) {
	BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(name);
	ConsumerProperties consumerProperties = bindingProperties.getConsumer();
	if (consumerProperties == null) {
		consumerProperties = this.bindingServiceProperties.getConsumerProperties(name);
		consumerProperties.setUseNativeDecoding(true);
	}
	else {
		if (!encodingDecodingBindAdviceHandler.isDecodingSettingProvided()) {
			consumerProperties.setUseNativeDecoding(true);
		}
	}
	// Always set multiplex to true in the kafka streams binder
	consumerProperties.setMultiplex(true);

	KTableBoundElementFactory.KTableWrapperHandler wrapper = new KTableBoundElementFactory.KTableWrapperHandler();
	ProxyFactory proxyFactory = new ProxyFactory(
			KTableBoundElementFactory.KTableWrapper.class, KTable.class);
	proxyFactory.addAdvice(wrapper);

	return (KTable) proxyFactory.getProxy();
}
 
Example 4
Source File: KafkaStreamsBindingInformationCatalogue.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 5 votes vote down vote up
/**
 * Is native decoding is enabled on this {@link KStream}.
 * @param bindingTarget binding target for KStream
 * @return true if native decoding is enabled, fasle otherwise.
 */
boolean isUseNativeDecoding(KStream<?, ?> bindingTarget) {
	BindingProperties bindingProperties = this.bindingProperties.get(bindingTarget);
	if (bindingProperties.getConsumer() == null) {
		bindingProperties.setConsumer(new ConsumerProperties());
	}
	return bindingProperties.getConsumer().isUseNativeDecoding();
}
 
Example 5
Source File: MessageConverterConfigurer.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@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));
	}
}
 
Example 6
Source File: MessageConverterConfigurer.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
	boolean partitioned = !inbound && producerProperties != null && producerProperties.isPartitioned();
	boolean functional = streamFunctionProperties != null
			&& (StringUtils.hasText(streamFunctionProperties.getDefinition()) || StringUtils.hasText(bindingServiceProperties.getSource()));

	if (partitioned) {
		if (inbound || !functional) {
			messageChannel.addInterceptor(new PartitioningInterceptor(bindingProperties));
		}
	}

	ConsumerProperties consumerProperties = bindingProperties.getConsumer();
	if (this.isNativeEncodingNotSet(producerProperties, consumerProperties, inbound)) {
		if (inbound) {
			messageChannel.addInterceptor(
					new InboundContentTypeEnhancingInterceptor(contentType));
		}
		else {
			messageChannel.addInterceptor(
					new OutboundContentTypeConvertingInterceptor(contentType,
							this.compositeMessageConverter));
		}
	}
}
 
Example 7
Source File: FunctionBindingTestUtils.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("rawtypes")
public static void bind(ConfigurableApplicationContext applicationContext, Object function) {
	try {
		Object targetFunction = function;
		if (function instanceof FunctionRegistration) {
			targetFunction = ((FunctionRegistration) function).getTarget();
		}
		String functionName = targetFunction instanceof Function ? "function" : (targetFunction instanceof Consumer ? "consumer" : "supplier");

		System.setProperty("spring.cloud.function.definition", functionName);
		applicationContext.getBeanFactory().registerSingleton(functionName, function);

		Object actualFunction =  ((FunctionInvocationWrapper) applicationContext
				.getBean(FunctionCatalog.class).lookup(functionName)).getTarget();

		InitializingBean functionBindingRegistrar = applicationContext.getBean("functionBindingRegistrar", InitializingBean.class);
		functionBindingRegistrar.afterPropertiesSet();

		BindableProxyFactory bindingProxy = applicationContext.getBean("&" + functionName + "_binding", BindableProxyFactory.class);
		bindingProxy.afterPropertiesSet();

		InitializingBean functionBinder = applicationContext.getBean("functionInitializer", InitializingBean.class);
		functionBinder.afterPropertiesSet();

		BindingServiceProperties bindingProperties = applicationContext.getBean(BindingServiceProperties.class);
		String inputBindingName = functionName + "-in-0";
		String outputBindingName = functionName + "-out-0";
		Map<String, BindingProperties> bindings = bindingProperties.getBindings();
		BindingProperties inputProperties = bindings.get(inputBindingName);
		BindingProperties outputProperties = bindings.get(outputBindingName);
		ConsumerProperties consumerProperties = inputProperties.getConsumer();
		ProducerProperties producerProperties = outputProperties.getProducer();

		TestChannelBinder binder = applicationContext.getBean(TestChannelBinder.class);
		if (actualFunction instanceof Supplier || actualFunction instanceof Function) {
			Binding<MessageChannel> bindProducer = binder.bindProducer(outputProperties.getDestination(),
					applicationContext.getBean(outputBindingName, MessageChannel.class),
					producerProperties == null ? new ProducerProperties() : producerProperties);
			bindProducer.start();
		}
		if (actualFunction instanceof Consumer || actualFunction instanceof Function) {
			Binding<MessageChannel> bindConsumer = binder.bindConsumer(inputProperties.getDestination(), null,
					applicationContext.getBean(inputBindingName, MessageChannel.class),
					consumerProperties == null ? new ConsumerProperties() : consumerProperties);
			bindConsumer.start();
		}
	}
	catch (Exception e) {
		throw new IllegalStateException("Failed to bind function", e);
	}
	finally {
		System.clearProperty("spring.cloud.function.definition");
	}
}