List of usage examples for org.springframework.kafka.config StreamsBuilderFactoryBean setAutoStartup
public void setAutoStartup(boolean autoStartup)
From source file:org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsStreamListenerSetupMethodOrchestrator.java
@SuppressWarnings({ "unchecked" }) private void buildStreamsBuilderAndRetrieveConfig(Method method, ApplicationContext applicationContext, String inboundName) {//w w w .j a va2 s . c o m ConfigurableListableBeanFactory beanFactory = this.applicationContext.getBeanFactory(); Map<String, Object> streamConfigGlobalProperties = applicationContext .getBean("streamConfigGlobalProperties", Map.class); KafkaStreamsConsumerProperties extendedConsumerProperties = this.kafkaStreamsExtendedBindingProperties .getExtendedConsumerProperties(inboundName); streamConfigGlobalProperties.putAll(extendedConsumerProperties.getConfiguration()); String applicationId = extendedConsumerProperties.getApplicationId(); //override application.id if set at the individual binding level. if (StringUtils.hasText(applicationId)) { streamConfigGlobalProperties.put(StreamsConfig.APPLICATION_ID_CONFIG, applicationId); } int concurrency = this.bindingServiceProperties.getConsumerProperties(inboundName).getConcurrency(); // override concurrency if set at the individual binding level. if (concurrency > 1) { streamConfigGlobalProperties.put(StreamsConfig.NUM_STREAM_THREADS_CONFIG, concurrency); } Map<String, KafkaStreamsDlqDispatch> kafkaStreamsDlqDispatchers = applicationContext .getBean("kafkaStreamsDlqDispatchers", Map.class); KafkaStreamsConfiguration kafkaStreamsConfiguration = new KafkaStreamsConfiguration( streamConfigGlobalProperties) { @Override public Properties asProperties() { Properties properties = super.asProperties(); properties.put(SendToDlqAndContinue.KAFKA_STREAMS_DLQ_DISPATCHERS, kafkaStreamsDlqDispatchers); return properties; } }; StreamsBuilderFactoryBean streamsBuilder = this.cleanupConfig == null ? new StreamsBuilderFactoryBean(kafkaStreamsConfiguration) : new StreamsBuilderFactoryBean(kafkaStreamsConfiguration, this.cleanupConfig); streamsBuilder.setAutoStartup(false); BeanDefinition streamsBuilderBeanDefinition = BeanDefinitionBuilder .genericBeanDefinition((Class<StreamsBuilderFactoryBean>) streamsBuilder.getClass(), () -> streamsBuilder) .getRawBeanDefinition(); ((BeanDefinitionRegistry) beanFactory).registerBeanDefinition("stream-builder-" + method.getName(), streamsBuilderBeanDefinition); StreamsBuilderFactoryBean streamsBuilderX = applicationContext .getBean("&stream-builder-" + method.getName(), StreamsBuilderFactoryBean.class); this.methodStreamsBuilderFactoryBeanMap.put(method, streamsBuilderX); }