Fix spurious warnings from InteractiveQueryService

Set applicationId properly in functions with multiple inputs
This commit is contained in:
Soby Chacko
2019-10-09 00:28:54 -04:00
parent c7fa1ce275
commit 98431ed8a0
3 changed files with 20 additions and 8 deletions

View File

@@ -16,8 +16,10 @@
package org.springframework.cloud.stream.binder.kafka.streams;
import java.util.Iterator;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -84,19 +86,24 @@ public class InteractiveQueryService {
retryTemplate.setRetryPolicy(retryPolicy);
return retryTemplate.execute(context -> {
T store;
for (KafkaStreams kafkaStream : InteractiveQueryService.this.kafkaStreamsRegistry.getKafkaStreams()) {
T store = null;
final Set<KafkaStreams> kafkaStreams = InteractiveQueryService.this.kafkaStreamsRegistry.getKafkaStreams();
final Iterator<KafkaStreams> iterator = kafkaStreams.iterator();
Throwable throwable = null;
while (iterator.hasNext()) {
try {
store = kafkaStream.store(storeName, storeType);
if (store != null) {
return store;
}
store = iterator.next().store(storeName, storeType);
}
catch (InvalidStateStoreException e) {
LOG.warn("Error when retrieving state store: " + storeName, e);
// pass through..
throwable = e;
}
}
throw new IllegalStateException("Error when retrieving state store: " + storeName);
if (store != null) {
return store;
}
throw new IllegalStateException("Error when retrieving state store: j " + storeName, throwable);
});
}

View File

@@ -35,6 +35,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.kafka.common.serialization.Serde;
import org.apache.kafka.common.serialization.Serdes;
import org.apache.kafka.streams.StreamsBuilder;
import org.apache.kafka.streams.StreamsConfig;
import org.apache.kafka.streams.Topology;
import org.apache.kafka.streams.kstream.KStream;
@@ -296,8 +297,10 @@ public class KafkaStreamsFunctionProcessor extends AbstractKafkaStreamsBinderPro
StreamsBuilderFactoryBean streamsBuilderFactoryBean =
this.methodStreamsBuilderFactoryBeanMap.get(functionName);
StreamsBuilder streamsBuilder = streamsBuilderFactoryBean.getObject();
final String applicationId = streamsBuilderFactoryBean.getStreamsConfiguration().getProperty(StreamsConfig.APPLICATION_ID_CONFIG);
KafkaStreamsConsumerProperties extendedConsumerProperties =
this.kafkaStreamsExtendedBindingProperties.getExtendedConsumerProperties(input);
extendedConsumerProperties.setApplicationId(applicationId);
//get state store spec
Serde<?> keySerde = this.keyValueSerdeResolver.getInboundKeySerde(extendedConsumerProperties, stringResolvableTypeMap.get(input));

View File

@@ -251,8 +251,10 @@ class KafkaStreamsStreamListenerSetupMethodOrchestrator extends AbstractKafkaStr
StreamsBuilderFactoryBean streamsBuilderFactoryBean = this.methodStreamsBuilderFactoryBeanMap
.get(method);
StreamsBuilder streamsBuilder = streamsBuilderFactoryBean.getObject();
final String applicationId = streamsBuilderFactoryBean.getStreamsConfiguration().getProperty(StreamsConfig.APPLICATION_ID_CONFIG);
KafkaStreamsConsumerProperties extendedConsumerProperties = this.kafkaStreamsExtendedBindingProperties
.getExtendedConsumerProperties(inboundName);
extendedConsumerProperties.setApplicationId(applicationId);
// get state store spec
KafkaStreamsStateStoreProperties spec = buildStateStoreSpec(method);