org.springframework.cloud.stream.binder.ProducerProperties Java Examples
The following examples show how to use
org.springframework.cloud.stream.binder.ProducerProperties.
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: KStreamBoundElementFactory.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public KStream createOutput(final String name) { BindingProperties bindingProperties = this.bindingServiceProperties.getBindingProperties(name); ProducerProperties producerProperties = bindingProperties.getProducer(); if (producerProperties == null) { producerProperties = this.bindingServiceProperties.getProducerProperties(name); producerProperties.setUseNativeEncoding(true); } else { if (!encodingDecodingBindAdviceHandler.isEncodingSettingProvided()) { producerProperties.setUseNativeEncoding(true); } } return createProxyForKStream(name); }
Example #2
Source File: TestProducer.java From spring-cloud-consul with Apache License 2.0 | 6 votes |
@Override public void run(ApplicationArguments args) throws Exception { /* * if (args.containsOption("partitioned") && * Boolean.valueOf(args.getOptionValues("partitioned").get(0))) { * binder.setPartitionSelector(stubPartitionSelectorStrategy()); } */ SubscribableChannel producerChannel = producerChannel(); ProducerProperties properties = new ProducerProperties(); properties.setPartitionKeyExpression( new SpelExpressionParser().parseExpression("payload")); this.binder.bindProducer(ConsulBinderTests.BINDING_NAME, producerChannel, properties); Message<String> message = new GenericMessage<>(ConsulBinderTests.MESSAGE_PAYLOAD); logger.info("Writing message to binder {}", this.binder); producerChannel.send(message); }
Example #3
Source File: ConsulBinder.java From spring-cloud-consul with Apache License 2.0 | 6 votes |
@Override protected Binding<MessageChannel> doBindProducer(String name, MessageChannel channel, ProducerProperties properties) { Assert.isInstanceOf(SubscribableChannel.class, channel); this.logger.debug("Binding Consul client to eventName " + name); ConsulSendingHandler sendingHandler = new ConsulSendingHandler( this.eventService.getConsulClient(), name); EventDrivenConsumer consumer = new EventDrivenConsumer( (SubscribableChannel) channel, sendingHandler); consumer.setBeanFactory(getBeanFactory()); consumer.setBeanName(String.format(BEAN_NAME_TEMPLATE, name)); consumer.afterPropertiesSet(); consumer.start(); return new DefaultBinding<>(name, null, channel, consumer); }
Example #4
Source File: BindingServiceTests.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@Test public void testProducerPropertiesValidation() { BindingServiceProperties serviceProperties = new BindingServiceProperties(); Map<String, BindingProperties> bindingProperties = new HashMap<>(); BindingProperties props = new BindingProperties(); ProducerProperties producerProperties = new ProducerProperties(); producerProperties.setPartitionCount(0); props.setDestination("foo"); props.setProducer(producerProperties); final String outputChannelName = "output"; bindingProperties.put(outputChannelName, props); serviceProperties.setBindings(bindingProperties); DefaultBinderFactory binderFactory = createMockBinderFactory(); BindingService service = new BindingService(serviceProperties, binderFactory); MessageChannel outputChannel = new DirectChannel(); try { service.bindProducer(outputChannel, outputChannelName); fail("Producer properties should be validated."); } catch (IllegalStateException e) { assertThat(e) .hasMessageContaining("Partition count should be greater than zero."); } }
Example #5
Source File: BindingService.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
public <T> void rescheduleProducerBinding(final T output, final String bindingTarget, final Binder<T, ?, ProducerProperties> binder, final ProducerProperties producerProperties, final LateBinding<T> late, final RuntimeException exception) { assertNotIllegalException(exception); this.log.error("Failed to create producer binding; retrying in " + this.bindingServiceProperties.getBindingRetryInterval() + " seconds", exception); this.scheduleTask(() -> { try { late.setDelegate( binder.bindProducer(bindingTarget, output, producerProperties)); } catch (RuntimeException e) { rescheduleProducerBinding(output, bindingTarget, binder, producerProperties, late, e); } }); }
Example #6
Source File: BindingService.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
public <T> Binding<T> doBindProducer(T output, String bindingTarget, Binder<T, ?, ProducerProperties> binder, ProducerProperties producerProperties) { if (this.taskScheduler == null || this.bindingServiceProperties.getBindingRetryInterval() <= 0) { return binder.bindProducer(bindingTarget, output, producerProperties); } else { try { return binder.bindProducer(bindingTarget, output, producerProperties); } catch (RuntimeException e) { LateBinding<T> late = new LateBinding<T>(bindingTarget, e.getCause() == null ? e.toString() : e.getCause().getMessage(), producerProperties, false); rescheduleProducerBinding(output, bindingTarget, binder, producerProperties, late, e); return late; } } }
Example #7
Source File: PartitionAwareFunctionWrapper.java From spring-cloud-stream with Apache License 2.0 | 6 votes |
@SuppressWarnings("unchecked") PartitionAwareFunctionWrapper(FunctionInvocationWrapper function, ConfigurableApplicationContext context, ProducerProperties producerProperties) { this.function = function; if (producerProperties != null && producerProperties.isPartitioned()) { StandardEvaluationContext evaluationContext = ExpressionUtils.createStandardEvaluationContext(context.getBeanFactory()); PartitionHandler partitionHandler = new PartitionHandler(evaluationContext, producerProperties, context.getBeanFactory()); this.outputMessageEnricher = outputMessage -> { int partitionId = partitionHandler.determinePartition(outputMessage); return MessageBuilder .fromMessage(outputMessage) .setHeader(BinderHeaders.PARTITION_HEADER, partitionId).build(); }; } else { this.outputMessageEnricher = null; } }
Example #8
Source File: KeyValueSerdeResolver.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
/** * Provide the {@link Serde} for outbound value. * @param producerProperties {@link ProducerProperties} on binding * @param kafkaStreamsProducerProperties binding level extended * {@link KafkaStreamsProducerProperties} * @return configurd {@link Serde} for the outbound value. */ public Serde<?> getOutboundValueSerde(ProducerProperties producerProperties, KafkaStreamsProducerProperties kafkaStreamsProducerProperties) { Serde<?> valueSerde; try { if (producerProperties.isUseNativeEncoding()) { valueSerde = getValueSerde( kafkaStreamsProducerProperties.getValueSerde()); } else { valueSerde = Serdes.ByteArray(); } } catch (ClassNotFoundException ex) { throw new IllegalStateException("Serde class not found: ", ex); } return valueSerde; }
Example #9
Source File: KeyValueSerdeResolver.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 6 votes |
public Serde<?> getOutboundValueSerde(ProducerProperties producerProperties, KafkaStreamsProducerProperties kafkaStreamsProducerProperties, ResolvableType resolvableType) { Serde<?> valueSerde; try { if (producerProperties.isUseNativeEncoding()) { valueSerde = getValueSerde( kafkaStreamsProducerProperties.getValueSerde(), resolvableType); } else { valueSerde = Serdes.ByteArray(); } } catch (ClassNotFoundException ex) { throw new IllegalStateException("Serde class not found: ", ex); } return valueSerde; }
Example #10
Source File: StreamBridge.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
SubscribableChannel resolveDestination(String destinationName, ProducerProperties producerProperties) { SubscribableChannel messageChannel = this.channelCache.get(destinationName); if (messageChannel == null) { messageChannel = new DirectWithAttributesChannel(); this.bindingService.bindProducer(messageChannel, destinationName, false); this.channelCache.put(destinationName, messageChannel); } return messageChannel; }
Example #11
Source File: FunctionConfiguration.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
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 #12
Source File: BindingService.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) public <T> Binding<T> bindProducer(T output, String outputName, boolean cache) { String bindingTarget = this.bindingServiceProperties .getBindingDestination(outputName); Class<?> outputClass = output.getClass(); if (output instanceof Advised) { outputClass = Stream.of(((Advised) output).getProxiedInterfaces()).filter(c -> !c.getName().contains("org.springframework")).findFirst() .orElse(outputClass); } Binder<T, ?, ProducerProperties> binder = (Binder<T, ?, ProducerProperties>) getBinder( outputName, outputClass); ProducerProperties producerProperties = this.bindingServiceProperties .getProducerProperties(outputName); if (binder instanceof ExtendedPropertiesBinder) { Object extension = ((ExtendedPropertiesBinder) binder) .getExtendedProducerProperties(outputName); ExtendedProducerProperties extendedProducerProperties = new ExtendedProducerProperties<>( extension); BeanUtils.copyProperties(producerProperties, extendedProducerProperties); producerProperties = extendedProducerProperties; } validate(producerProperties); Binding<T> binding = doBindProducer(output, bindingTarget, binder, producerProperties); if (cache) { this.producerBindings.put(outputName, binding); } return binding; }
Example #13
Source File: TestSupportBinderAutoConfiguration.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@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 #14
Source File: TestSupportBinder.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
/** * Registers a single subscriber to the channel, that enqueues messages for later * retrieval and assertion in tests. */ @Override public Binding<MessageChannel> bindProducer(String name, MessageChannel outboundBindTarget, ProducerProperties properties) { final BlockingQueue<Message<?>> queue = this.messageCollector .register(outboundBindTarget, properties.isUseNativeEncoding()); ((SubscribableChannel) outboundBindTarget).subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { queue.add(message); } }); this.messageChannels.put(name, outboundBindTarget); return new TestBinding(outboundBindTarget, this.messageCollector); }
Example #15
Source File: TestChannelBinderProvisioner.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
/** * Will provision producer destination as an SI {@link PublishSubscribeChannel}. <br> * This provides convenience of registering additional subscriber (handler in the test * method) along side of being able to call {@link OutputDestination#receive()} to get * a {@link Message} for additional assertions. */ @Override public ProducerDestination provisionProducerDestination(String name, ProducerProperties properties) throws ProvisioningException { SubscribableChannel destination = this.provisionDestination(name, true); this.target.setChannel(destination); return new SpringIntegrationProducerDestination(name, destination); }
Example #16
Source File: MessageConverterConfigurer.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
/** * 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
Source File: MessageConverterConfigurer.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
private boolean isNativeEncodingNotSet(ProducerProperties producerProperties, ConsumerProperties consumerProperties, boolean input) { if (input) { return consumerProperties == null || !consumerProperties.isUseNativeDecoding(); } else { return producerProperties == null || !producerProperties.isUseNativeEncoding(); } }
Example #18
Source File: TestChannelBinder.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@Override protected MessageHandler createProducerMessageHandler(ProducerDestination destination, ProducerProperties producerProperties, MessageChannel errorChannel) throws Exception { BridgeHandler handler = new BridgeHandler(); handler.setBeanFactory(this.beanFactory); handler.setOutputChannel( ((SpringIntegrationProducerDestination) destination).getChannel()); return handler; }
Example #19
Source File: TestChannelBinderConfiguration.java From spring-cloud-stream with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") @Bean public Binder<T, ? extends ConsumerProperties, ? extends ProducerProperties> springIntegrationChannelBinder( TestChannelBinderProvisioner provisioner) { return (Binder<T, ? extends ConsumerProperties, ? extends ProducerProperties>) new TestChannelBinder( provisioner); }
Example #20
Source File: ChannelBindingServiceProperties.java From gem with MIT License | 4 votes |
public ProducerProperties getProducerProperties(String outputChannelName) { return bindingServiceProperties.getProducerProperties(outputChannelName); }
Example #21
Source File: FunctionBindingTestUtils.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
@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"); } }
Example #22
Source File: StubBinder1.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
@Override public Binding<Object> bindProducer(String name, Object outboundBindTarget, ProducerProperties properties) { return null; }
Example #23
Source File: StubBinder2.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
@Override public Binding<Object> bindProducer(String name, Object outboundBindTarget, ProducerProperties properties) { return null; }
Example #24
Source File: BindingServiceTests.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
@Override public Binding<SomeBindableType> bindProducer(String name, SomeBindableType outboundBindTarget, ProducerProperties producerProperties) { throw new UnsupportedOperationException(); }
Example #25
Source File: BindingServiceTests.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
@SuppressWarnings({ "rawtypes", "unchecked" }) @Test public void testLateBindingProducer() throws Exception { BindingServiceProperties properties = new BindingServiceProperties(); properties.setBindingRetryInterval(1); Map<String, BindingProperties> bindingProperties = new HashMap<>(); BindingProperties props = new BindingProperties(); props.setDestination("foo"); final String outputChannelName = "output"; bindingProperties.put(outputChannelName, props); properties.setBindings(bindingProperties); DefaultBinderFactory binderFactory = createMockBinderFactory(); Binder binder = binderFactory.getBinder("mock", MessageChannel.class); ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler(); scheduler.initialize(); BindingService service = new BindingService(properties, binderFactory, scheduler); MessageChannel outputChannel = new DirectChannel(); final Binding<MessageChannel> mockBinding = Mockito.mock(Binding.class); final CountDownLatch fail = new CountDownLatch(2); doAnswer(i -> { fail.countDown(); if (fail.getCount() == 1) { throw new RuntimeException("fail"); } return mockBinding; }).when(binder).bindProducer(eq("foo"), same(outputChannel), any(ProducerProperties.class)); Binding<MessageChannel> binding = service.bindProducer(outputChannel, outputChannelName); assertThat(fail.await(10, TimeUnit.SECONDS)).isTrue(); assertThat(binding).isNotNull(); Binding delegate = TestUtils.getPropertyValue(binding, "delegate", Binding.class); int n = 0; while (n++ < 300 && delegate == null) { Thread.sleep(100); delegate = TestUtils.getPropertyValue(binding, "delegate", Binding.class); } assertThat(delegate).isSameAs(mockBinding); service.unbindProducers(outputChannelName); verify(binder, times(2)).bindProducer(eq("foo"), same(outputChannel), any(ProducerProperties.class)); verify(delegate).unbind(); binderFactory.destroy(); scheduler.destroy(); }
Example #26
Source File: BindingServiceProperties.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
public void updateProducerProperties(String bindingName, ProducerProperties producerProperties) { if (this.bindings.containsKey(bindingName)) { this.bindings.get(bindingName).setProducer(producerProperties); } }
Example #27
Source File: BindingProperties.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
public void setProducer(ProducerProperties producer) { this.producer = producer; }
Example #28
Source File: BindingProperties.java From spring-cloud-stream with Apache License 2.0 | 4 votes |
public ProducerProperties getProducer() { return this.producer; }
Example #29
Source File: SerdesProvidedAsBeansTests.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 4 votes |
@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
Source File: KafkaBinderExtendedPropertiesTest.java From spring-cloud-stream-binder-kafka with Apache License 2.0 | 4 votes |
@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); }