Java Code Examples for org.springframework.cloud.stream.binder.ConsumerProperties

The following examples show how to use org.springframework.cloud.stream.binder.ConsumerProperties. These examples are extracted from open source projects. 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
@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
@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
@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
/**
 * Provide the {@link Serde} for inbound value.
 * @param consumerProperties {@link ConsumerProperties} on binding
 * @param extendedConsumerProperties binding level extended
 * {@link KafkaStreamsConsumerProperties}
 * @return configurd {@link Serde} for the inbound value.
 */
public Serde<?> getInboundValueSerde(ConsumerProperties consumerProperties,
		KafkaStreamsConsumerProperties extendedConsumerProperties) {
	Serde<?> valueSerde;

	String valueSerdeString = extendedConsumerProperties.getValueSerde();
	try {
		if (consumerProperties != null && consumerProperties.isUseNativeDecoding()) {
			valueSerde = getValueSerde(valueSerdeString);
		}
		else {
			valueSerde = Serdes.ByteArray();
		}
	}
	catch (ClassNotFoundException ex) {
		throw new IllegalStateException("Serde class not found: ", ex);
	}
	return valueSerde;
}
 
Example 5
public Serde<?> getInboundValueSerde(ConsumerProperties consumerProperties,
									KafkaStreamsConsumerProperties extendedConsumerProperties,
									ResolvableType resolvableType) {
	Serde<?> valueSerde;

	String valueSerdeString = extendedConsumerProperties.getValueSerde();
	try {
		if (consumerProperties != null && consumerProperties.isUseNativeDecoding()) {
			valueSerde = getValueSerde(valueSerdeString, resolvableType);
		}
		else {
			valueSerde = Serdes.ByteArray();
		}
	}
	catch (ClassNotFoundException ex) {
		throw new IllegalStateException("Serde class not found: ", ex);
	}
	return valueSerde;
}
 
Example 6
Source Project: spring-cloud-stream   Source File: BindingService.java    License: Apache License 2.0 6 votes vote down vote up
public <T> Binding<T> doBindConsumer(T input, String inputName,
		Binder<T, ConsumerProperties, ?> binder,
		ConsumerProperties consumerProperties, String target) {
	if (this.taskScheduler == null
			|| this.bindingServiceProperties.getBindingRetryInterval() <= 0) {
		return binder.bindConsumer(target,
				this.bindingServiceProperties.getGroup(inputName), input,
				consumerProperties);
	}
	else {
		try {
			return binder.bindConsumer(target,
					this.bindingServiceProperties.getGroup(inputName), input,
					consumerProperties);
		}
		catch (RuntimeException e) {
			LateBinding<T> late = new LateBinding<T>(target,
					e.getCause() == null ? e.toString() : e.getCause().getMessage(), consumerProperties, true);
			rescheduleConsumerBinding(input, inputName, binder, consumerProperties,
					target, late, e);
			this.consumerBindings.put(inputName, Collections.singletonList(late));
			return late;
		}
	}
}
 
Example 7
Source Project: spring-cloud-stream   Source File: BindingService.java    License: Apache License 2.0 6 votes vote down vote up
public <T> void rescheduleConsumerBinding(final T input, final String inputName,
		final Binder<T, ConsumerProperties, ?> binder,
		final ConsumerProperties consumerProperties, final String target,
		final LateBinding<T> late, RuntimeException exception) {
	assertNotIllegalException(exception);
	this.log.error("Failed to create consumer binding; retrying in "
			+ this.bindingServiceProperties.getBindingRetryInterval() + " seconds",
			exception);
	this.scheduleTask(() -> {
		try {
			late.setDelegate(binder.bindConsumer(target,
					this.bindingServiceProperties.getGroup(inputName), input,
					consumerProperties));
		}
		catch (RuntimeException e) {
			rescheduleConsumerBinding(input, inputName, binder, consumerProperties,
					target, late, e);
		}
	});
}
 
Example 8
Source Project: spring-cloud-stream   Source File: BindingService.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public <T> Binding<T> doBindPollableConsumer(T input, String inputName,
		Binder<T, ConsumerProperties, ?> binder,
		ConsumerProperties consumerProperties, String target) {
	if (this.taskScheduler == null
			|| this.bindingServiceProperties.getBindingRetryInterval() <= 0) {
		return ((PollableConsumerBinder) binder).bindPollableConsumer(target,
				this.bindingServiceProperties.getGroup(inputName),
				(PollableSource) input, consumerProperties);
	}
	else {
		try {
			return ((PollableConsumerBinder) binder).bindPollableConsumer(target,
					this.bindingServiceProperties.getGroup(inputName),
					(PollableSource) input, consumerProperties);
		}
		catch (RuntimeException e) {
			LateBinding<T> late = new LateBinding<T>(target,
					e.getCause() == null ? e.toString() : e.getCause().getMessage(), consumerProperties, true);
			reschedulePollableConsumerBinding(input, inputName, binder,
					consumerProperties, target, late, e);
			return late;
		}
	}
}
 
Example 9
Source Project: spring-cloud-stream   Source File: BindingService.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
public <T> void reschedulePollableConsumerBinding(final T input,
		final String inputName, final Binder<T, ConsumerProperties, ?> binder,
		final ConsumerProperties consumerProperties, final String target,
		final LateBinding<T> late, RuntimeException exception) {
	assertNotIllegalException(exception);
	this.log.error("Failed to create consumer binding; retrying in "
			+ this.bindingServiceProperties.getBindingRetryInterval() + " seconds",
			exception);
	this.scheduleTask(() -> {
		try {
			late.setDelegate(((PollableConsumerBinder) binder).bindPollableConsumer(
					target, this.bindingServiceProperties.getGroup(inputName),
					(PollableSource) input, consumerProperties));
		}
		catch (RuntimeException e) {
			reschedulePollableConsumerBinding(input, inputName, binder,
					consumerProperties, target, late, e);
		}
	});
}
 
Example 10
Source Project: spring-cloud-stream   Source File: BindingServiceTests.java    License: Apache License 2.0 6 votes vote down vote up
@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.");
	}
}
 
Example 11
Source Project: spring-cloud-stream   Source File: RetryTemplateTests.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Test
public void testSpecificCustomRetryTemplate() throws Exception {
	ApplicationContext context = new SpringApplicationBuilder(
			SpecificCustomRetryTemplateConfiguration.class)
					.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false",
							"--spring.cloud.stream.bindings.input.consumer.retry-template-name=retryTemplateTwo");

	RetryTemplate retryTemplateTwo = context.getBean("retryTemplateTwo",
			RetryTemplate.class);
	BindingServiceProperties bindingServiceProperties = context
			.getBean(BindingServiceProperties.class);
	ConsumerProperties consumerProperties = bindingServiceProperties
			.getConsumerProperties("input");
	AbstractBinder binder = context.getBean(AbstractBinder.class);

	Method m = AbstractBinder.class.getDeclaredMethod("buildRetryTemplate",
			ConsumerProperties.class);
	m.setAccessible(true);
	RetryTemplate retryTemplate = (RetryTemplate) m.invoke(binder,
			consumerProperties);
	assertThat(retryTemplate).isEqualTo(retryTemplateTwo);
}
 
Example 12
Source Project: spring-cloud-consul   Source File: TestConsumer.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void run(ApplicationArguments args) throws Exception {
	logger.info("Consumer running with binder {}", this.binder);
	SubscribableChannel consumerChannel = new ExecutorSubscribableChannel();
	consumerChannel.subscribe(new MessageHandler() {
		@Override
		public void handleMessage(Message<?> message) throws MessagingException {
			TestConsumer.this.messagePayload = (String) message.getPayload();
			logger.info("Received message: {}", TestConsumer.this.messagePayload);
		}
	});
	String group = null;

	if (args.containsOption("group")) {
		group = args.getOptionValues("group").get(0);
	}

	this.binder.bindConsumer(ConsulBinderTests.BINDING_NAME, group, consumerChannel,
			new ConsumerProperties());
	this.isBound = true;
}
 
Example 13
/**
 * 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 14
Source Project: spring-cloud-stream   Source File: FunctionConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
FunctionWrapper(Function function, ConsumerProperties consumerProperties,
		ProducerProperties producerProperties, ConfigurableApplicationContext applicationContext) {

	isRoutingFunction = ((FunctionInvocationWrapper) function).getTarget() instanceof RoutingFunction;
	this.applicationContext = applicationContext;
	this.function = new PartitionAwareFunctionWrapper((FunctionInvocationWrapper) function, this.applicationContext, producerProperties);
	this.consumerProperties = consumerProperties;
	this.producerProperties = producerProperties;
	this.headersField = ReflectionUtils.findField(MessageHeaders.class, "headers");
	this.headersField.setAccessible(true);
}
 
Example 15
@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 16
/**
 * 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 17
private boolean isNativeEncodingNotSet(ProducerProperties producerProperties,
		ConsumerProperties consumerProperties, boolean input) {
	if (input) {
		return consumerProperties == null
				|| !consumerProperties.isUseNativeDecoding();
	}
	else {
		return producerProperties == null
				|| !producerProperties.isUseNativeEncoding();
	}
}
 
Example 18
@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());
	assertThat(argumentCaptor.getValue().getInstanceIndex()).isEqualTo(0);
	assertThat(argumentCaptor.getValue().getInstanceCount()).isEqualTo(2);
	verifyNoMoreInteractions(binder);
}
 
Example 19
Source Project: spring-cloud-stream   Source File: BindingServiceTests.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testDefaultGroup() throws Exception {
	BindingServiceProperties properties = new BindingServiceProperties();
	Map<String, BindingProperties> bindingProperties = new HashMap<>();
	BindingProperties props = new BindingProperties();
	props.setDestination("foo");
	final String inputChannelName = "input";
	bindingProperties.put(inputChannelName, props);
	properties.setBindings(bindingProperties);
	DefaultBinderFactory binderFactory = createMockBinderFactory();
	Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
	BindingService service = new BindingService(properties, binderFactory);
	MessageChannel inputChannel = new DirectChannel();
	Binding<MessageChannel> mockBinding = Mockito.mock(Binding.class);
	when(binder.bindConsumer(eq("foo"), isNull(), same(inputChannel),
			any(ConsumerProperties.class))).thenReturn(mockBinding);
	Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
			inputChannelName);
	assertThat(bindings).hasSize(1);
	Binding<MessageChannel> binding = bindings.iterator().next();
	assertThat(binding).isSameAs(mockBinding);
	service.unbindConsumers(inputChannelName);
	verify(binder).bindConsumer(eq("foo"), isNull(), same(inputChannel),
			any(ConsumerProperties.class));
	verify(binding).unbind();
	binderFactory.destroy();
}
 
Example 20
Source Project: spring-cloud-stream   Source File: BindingServiceTests.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testExplicitGroup() throws Exception {
	BindingServiceProperties properties = new BindingServiceProperties();
	Map<String, BindingProperties> bindingProperties = new HashMap<>();
	BindingProperties props = new BindingProperties();
	props.setDestination("foo");
	props.setGroup("fooGroup");
	final String inputChannelName = "input";
	bindingProperties.put(inputChannelName, props);
	properties.setBindings(bindingProperties);
	DefaultBinderFactory binderFactory = createMockBinderFactory();
	Binder binder = binderFactory.getBinder("mock", MessageChannel.class);
	BindingService service = new BindingService(properties, binderFactory);
	MessageChannel inputChannel = new DirectChannel();
	Binding<MessageChannel> mockBinding = Mockito.mock(Binding.class);
	when(binder.bindConsumer(eq("foo"), eq("fooGroup"), same(inputChannel),
			any(ConsumerProperties.class))).thenReturn(mockBinding);
	Collection<Binding<MessageChannel>> bindings = service.bindConsumer(inputChannel,
			inputChannelName);
	assertThat(bindings).hasSize(1);
	Binding<MessageChannel> binding = bindings.iterator().next();
	assertThat(binding).isSameAs(mockBinding);

	service.unbindConsumers(inputChannelName);
	verify(binder).bindConsumer(eq("foo"), eq(props.getGroup()), same(inputChannel),
			any(ConsumerProperties.class));
	verify(binding).unbind();
	binderFactory.destroy();
}
 
Example 21
@SuppressWarnings("unchecked")
@Bean
public Binder<T, ? extends ConsumerProperties, ? extends ProducerProperties> springIntegrationChannelBinder(
		TestChannelBinderProvisioner provisioner) {
	return (Binder<T, ? extends ConsumerProperties, ? extends ProducerProperties>) new TestChannelBinder(
			provisioner);
}
 
Example 22
Source Project: spring-cloud-stream   Source File: TestChannelBinder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected MessageProducer createConsumerEndpoint(ConsumerDestination destination,
		String group, ConsumerProperties properties) throws Exception {
	ErrorMessageStrategy errorMessageStrategy = new DefaultErrorMessageStrategy();
	SubscribableChannel siBinderInputChannel = ((SpringIntegrationConsumerDestination) destination)
			.getChannel();

	IntegrationMessageListeningContainer messageListenerContainer = new IntegrationMessageListeningContainer();
	IntegrationBinderInboundChannelAdapter adapter = new IntegrationBinderInboundChannelAdapter(
			messageListenerContainer);

	String groupName = StringUtils.hasText(group) ? group : "anonymous";
	ErrorInfrastructure errorInfrastructure = registerErrorInfrastructure(destination,
			groupName, properties);
	if (properties.getMaxAttempts() > 1) {
		adapter.setRetryTemplate(buildRetryTemplate(properties));
		adapter.setRecoveryCallback(errorInfrastructure.getRecoverer());
	}
	else {
		adapter.setErrorMessageStrategy(errorMessageStrategy);
		adapter.setErrorChannel(errorInfrastructure.getErrorChannel());
	}

	siBinderInputChannel.subscribe(messageListenerContainer);

	return adapter;
}
 
Example 23
Source Project: spring-cloud-stream   Source File: TestChannelBinder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected PolledConsumerResources createPolledConsumerResources(String name,
		String group, ConsumerDestination destination,
		ConsumerProperties consumerProperties) {
	return new PolledConsumerResources(this.messageSourceDelegate,
			registerErrorInfrastructure(destination, group, consumerProperties));
}
 
Example 24
Source Project: spring-cloud-stream   Source File: TestChannelBinder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected MessageHandler getErrorMessageHandler(ConsumerDestination destination,
		String group, ConsumerProperties consumerProperties) {
	return m -> {
		this.logger.debug("Error handled: " + m);
		this.lastError = m;
	};
}
 
Example 25
/**
 * Will provision consumer destination as SI {@link DirectChannel}.
 */
@Override
public ConsumerDestination provisionConsumerDestination(String name, String group,
		ConsumerProperties properties) throws ProvisioningException {
	SubscribableChannel destination = this.provisionDestination(name, false);
	if (this.source != null) {
		this.source.setChannel(destination);
	}
	return new SpringIntegrationConsumerDestination(name, destination);
}
 
Example 26
@Bean
@SuppressWarnings("unchecked")
public BinderFactory binderFactory(final Binder<MessageChannel, ?, ?> binder) {
	return new BinderFactory() {
		@Override
		public <T> Binder<T, ? extends ConsumerProperties, ? extends ProducerProperties> getBinder(
				String configurationName, Class<? extends T> bindableType) {
			return (Binder<T, ? extends ConsumerProperties, ? extends ProducerProperties>) binder;
		}
	};
}
 
Example 27
Source Project: spring-cloud-consul   Source File: ConsulBinder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Binding<MessageChannel> doBindConsumer(String name, String group,
		MessageChannel inputChannel, ConsumerProperties properties) {
	ConsulInboundMessageProducer messageProducer = new ConsulInboundMessageProducer(
			this.eventService);
	messageProducer.setOutputChannel(inputChannel);
	messageProducer.setBeanFactory(this.getBeanFactory());
	messageProducer.afterPropertiesSet();
	messageProducer.start();

	return new DefaultBinding<>(name, group, inputChannel, messageProducer);
}
 
Example 28
Source Project: gem   Source File: ChannelBindingServiceProperties.java    License: MIT License 4 votes vote down vote up
public ConsumerProperties getConsumerProperties(String inputChannelName) {
	return bindingServiceProperties.getConsumerProperties(inputChannelName);
}
 
Example 29
@Test
public void testKstreamWordCountFunction() throws NoSuchMethodException {
	SpringApplication app = new SpringApplication(SerdeProvidedAsBeanApp.class);
	app.setWebApplicationType(WebApplicationType.NONE);

	try (ConfigurableApplicationContext context = app.run(
			"--server.port=0",
			"--spring.jmx.enabled=false",
			"--spring.cloud.stream.bindings.process-in-0.destination=purchases",
			"--spring.cloud.stream.bindings.process-out-0.destination=coffee",
			"--spring.cloud.stream.kafka.streams.binder.functions.process.applicationId=process-id-0",
			"--spring.cloud.stream.kafka.streams.binder.configuration.commit.interval.ms=1000",
			"--spring.cloud.stream.kafka.streams.binder.configuration.default.key.serde" +
					"=org.apache.kafka.common.serialization.Serdes$StringSerde",
			"--spring.cloud.stream.kafka.streams.binder.configuration.default.value.serde" +
					"=org.apache.kafka.common.serialization.Serdes$StringSerde",
			"--spring.cloud.stream.kafka.streams.binder.brokers=" + embeddedKafka.getBrokersAsString())) {

		final Method method = SerdeProvidedAsBeanApp.class.getMethod("process");

		ResolvableType resolvableType = ResolvableType.forMethodReturnType(method, SerdeProvidedAsBeanApp.class);

		final KeyValueSerdeResolver keyValueSerdeResolver = context.getBean(KeyValueSerdeResolver.class);
		final BindingServiceProperties bindingServiceProperties = context.getBean(BindingServiceProperties.class);
		final KafkaStreamsExtendedBindingProperties kafkaStreamsExtendedBindingProperties = context.getBean(KafkaStreamsExtendedBindingProperties.class);

		final ConsumerProperties consumerProperties = bindingServiceProperties.getBindingProperties("process-in-0").getConsumer();
		final KafkaStreamsConsumerProperties kafkaStreamsConsumerProperties = kafkaStreamsExtendedBindingProperties.getExtendedConsumerProperties("input");
		kafkaStreamsExtendedBindingProperties.getExtendedConsumerProperties("input");
		final Serde<?> inboundValueSerde = keyValueSerdeResolver.getInboundValueSerde(consumerProperties, kafkaStreamsConsumerProperties, resolvableType.getGeneric(0));

		Assert.isTrue(inboundValueSerde instanceof FooSerde, "Inbound Value Serde is not matched");

		final ProducerProperties producerProperties = bindingServiceProperties.getBindingProperties("process-out-0").getProducer();
		final KafkaStreamsProducerProperties kafkaStreamsProducerProperties = kafkaStreamsExtendedBindingProperties.getExtendedProducerProperties("output");
		kafkaStreamsExtendedBindingProperties.getExtendedProducerProperties("output");
		final Serde<?> outboundValueSerde = keyValueSerdeResolver.getOutboundValueSerde(producerProperties, kafkaStreamsProducerProperties, resolvableType.getGeneric(1));

		Assert.isTrue(outboundValueSerde instanceof FooSerde, "Outbound Value Serde is not matched");
	}
}
 
Example 30
@Test
public void testKafkaBinderExtendedProperties() throws Exception {

	BinderFactory binderFactory = context.getBeanFactory()
			.getBean(BinderFactory.class);
	Binder<MessageChannel, ? extends ConsumerProperties, ? extends ProducerProperties> kafkaBinder = binderFactory
			.getBinder("kafka", MessageChannel.class);

	KafkaProducerProperties kafkaProducerProperties = (KafkaProducerProperties) ((ExtendedPropertiesBinder) kafkaBinder)
			.getExtendedProducerProperties("standard-out");

	// binding "standard-out" gets FooSerializer defined on the binding itself
	// and BarSerializer through default property.
	assertThat(kafkaProducerProperties.getConfiguration().get("key.serializer"))
			.isEqualTo("FooSerializer.class");
	assertThat(kafkaProducerProperties.getConfiguration().get("value.serializer"))
			.isEqualTo("BarSerializer.class");

	assertThat(kafkaProducerProperties.getConfiguration().get("foo"))
			.isEqualTo("bindingSpecificPropertyShouldWinOverDefault");

	// @checkstyle:off
	KafkaConsumerProperties kafkaConsumerProperties = (KafkaConsumerProperties) ((ExtendedPropertiesBinder) kafkaBinder)
			.getExtendedConsumerProperties("standard-in");
	// @checkstyle:on
	// binding "standard-in" gets FooSerializer defined on the binding itself
	// and BarSerializer through default property.
	assertThat(kafkaConsumerProperties.getConfiguration().get("key.serializer"))
			.isEqualTo("FooSerializer.class");
	assertThat(kafkaConsumerProperties.getConfiguration().get("value.serializer"))
			.isEqualTo("BarSerializer.class");

	// @checkstyle:off
	KafkaProducerProperties customKafkaProducerProperties = (KafkaProducerProperties) ((ExtendedPropertiesBinder) kafkaBinder)
			.getExtendedProducerProperties("custom-out");
	// @checkstyle:on

	// binding "standard-out" gets BarSerializer and BarSerializer for
	// key.serializer/value.serializer through default properties.
	assertThat(customKafkaProducerProperties.getConfiguration().get("key.serializer"))
			.isEqualTo("BarSerializer.class");
	assertThat(
			customKafkaProducerProperties.getConfiguration().get("value.serializer"))
					.isEqualTo("BarSerializer.class");

	// through default properties.
	assertThat(customKafkaProducerProperties.getConfiguration().get("foo"))
			.isEqualTo("bar");

	// @checkstyle:off
	KafkaConsumerProperties customKafkaConsumerProperties = (KafkaConsumerProperties) ((ExtendedPropertiesBinder) kafkaBinder)
			.getExtendedConsumerProperties("custom-in");
	// @checkstyle:on
	// binding "standard-in" gets BarSerializer and BarSerializer for
	// key.serializer/value.serializer through default properties.
	assertThat(customKafkaConsumerProperties.getConfiguration().get("key.serializer"))
			.isEqualTo("BarSerializer.class");
	assertThat(
			customKafkaConsumerProperties.getConfiguration().get("value.serializer"))
					.isEqualTo("BarSerializer.class");

	assertThat(kafkaConsumerProperties.isAckEachRecord()).isEqualTo(true);
	assertThat(customKafkaConsumerProperties.isAckEachRecord()).isEqualTo(false);

	RebalanceListener rebalanceListener = context.getBean(RebalanceListener.class);
	assertThat(rebalanceListener.latch.await(10, TimeUnit.SECONDS)).isTrue();
	assertThat(rebalanceListener.bindings.keySet()).contains("standard-in",
			"custom-in");
	assertThat(rebalanceListener.bindings.values()).containsExactly(Boolean.TRUE,
			Boolean.TRUE);
}