Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/apache-kafka/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Join KStream GlobalKTable使用Spring Cloud Stream连接-如何检查GlobalKTable的内容?_Join_Apache Kafka_Spring Cloud Stream - Fatal编程技术网

Join KStream GlobalKTable使用Spring Cloud Stream连接-如何检查GlobalKTable的内容?

Join KStream GlobalKTable使用Spring Cloud Stream连接-如何检查GlobalKTable的内容?,join,apache-kafka,spring-cloud-stream,Join,Apache Kafka,Spring Cloud Stream,我正在使用SpringCloudStream实现KStream GlobalKTable连接,我面临的问题是,连接操作没有得到任何匹配,但它肯定应该得到。代码如下所示: @Component @EnableBinding(CustomProcessor.class) public class MyProcessor { private static final Log LOGGER = LogFactory.getLog(MyProcessor.class); @Autowire

我正在使用SpringCloudStream实现KStream GlobalKTable连接,我面临的问题是,连接操作没有得到任何匹配,但它肯定应该得到。代码如下所示:

@Component
@EnableBinding(CustomProcessor.class)
public class MyProcessor {
  private static final Log LOGGER = 
  LogFactory.getLog(MyProcessor.class);

  @Autowired
  private InteractiveQueryService interactiveQueryService;

  ReadOnlyKeyValueStore<Object, Object> keyValueStore;

  @StreamListener
  @SendTo(CustomProcessor.OUTPUT)
  public KStream<EventKey, EventEnriched> process(
    @Input(CustomProcessor.INPUT) KStream<EventKey, EventEnriched> inputStream,
    @Input(CustomProcessor.LOOKUP) GlobalKTable<LookupKey, LookupData> lookupStore
  ) {

    keyValueStore = interactiveQueryService.getQueryableStore("lookupStore", QueryableStoreTypes.keyValueStore());

    LOGGER.info("Lookup: " + keyValueStore.get(new LookupKey("google.de")));

    return inputStream.leftJoin(
      lookupStore,
      (inputKey, inputValue) -> {
        return new LookupKey(inputValue.getDomain().replace("www.", ""));
      },
      this::enrichData
    );
  }


  public EventEnriched enrichData(EventEnriched input, LookupData lookupRecord) {

    ...

  }
}
代码运行正常,但GlobalKTable似乎为null。但如果我打电话

LOGGER.info("Lookup: " + keyValueStore.get(new LookupKey("google.de")));
为了导入GlobalKTable,运行应用程序失败时,请执行以下操作:

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-06-26T09:04:00.000 [ERROR] [main-858] [org.springframework.boot.SpringApplication] [reportFailure:858] Application run failed
org.springframework.beans.factory.BeanInitializationException: Cannot setup StreamListener for public org.apache.kafka.streams.kstream.KStream MyProcessor.process(org.apache.kafka.streams.kstream.KStream,org.apache.kafka.streams.kstream.GlobalKTable); nested exception is java.lang.reflect.InvocationTargetException
at org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsStreamListenerSetupMethodOrchestrator.orchestrateStreamListenerSetupMethod(KafkaStreamsStreamListenerSetupMethodOrchestrator.java:214)
at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.doPostProcess(StreamListenerAnnotationBeanPostProcessor.java:226)
at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.lambda$postProcessAfterInitialization$0(StreamListenerAnnotationBeanPostProcessor.java:196)
at java.base/java.lang.Iterable.forEach(Iterable.java:75)
at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.injectAndPostProcessDependencies(StreamListenerAnnotationBeanPostProcessor.java:330)
at org.springframework.cloud.stream.binding.StreamListenerAnnotationBeanPostProcessor.afterSingletonsInstantiated(StreamListenerAnnotationBeanPostProcessor.java:113)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:866)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:877)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549)
at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142)
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775)
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:316)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248)
at Transformer.main(Transformer.java:31)
Caused by: java.lang.reflect.InvocationTargetException: null
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.springframework.cloud.stream.binder.kafka.streams.KafkaStreamsStreamListenerSetupMethodOrchestrator.orchestrateStreamListenerSetupMethod(KafkaStreamsStreamListenerSetupMethodOrchestrator.java:179)
... 15 common frames omitted
Caused by: java.lang.NullPointerException: null
at MyProcessor.process(MyProcessor.java:62)
... 20 common frames omitted

Process finished with exit code 1
有人看到代码中有问题吗?如何检查GlobaKTable的内容

致意
马丁

现在我离问题越来越近了。我试图查询查找商店。如果我使用

final ReadOnlyKeyValueStore<LookupKey, LookupData> lookupStore =
            interactiveQueryService.getQueryableStore("myStore", QueryableStoreTypes.<LookupKey, LookupData>keyValueStore())
从不返回值。但是如果我创建一个如下的HashMap:

final KeyValueIterator<LookupKey, LookupData> lookups = lookupStore.all();

Map<LookupKey, LookupData> lookupMap = new HashMap<>();
while (lookups.hasNext()) {
    KeyValue<LookupKey, LookupData> nextLookup = lookups.next();
    lookupMap.put(nextLookup.key, nextLookup.value);
}
lookups.close();
final KeyValueIterator lookups=lookupStore.all();
Map lookupMap=newhashmap();
while(lookups.hasNext()){
KeyValue nextLookup=lookups.next();
lookupMap.put(nextLookup.key,nextLookup.value);
}
lookups.close();

hashMap包含正确的数据,并向每个键返回正确的值。但由于某些原因,GlobalKTable本身无法联接。它从未获得任何匹配项。

我认为LookupKey类型的键可能是join没有获得任何匹配项的原因。也许左键和右键对象的相等性存在问题。您是如何具体化“lookupStore”的。我没有看到任何地方您正在将任何数据物化到存储中。可能是调用该操作时状态存储不可用或未就绪。在my application.yml中,我有属性:
spring.cloud.stream.kafka.streams.bindings.lookupTable.consumer.materialedas:lookupStore
我需要代码中的其他内容吗?哦,我没有意识到这一点。这应该行得通。如果你能分享一个小的可复制样品(带有复制说明),我可以看一眼。我的错,我以前没有提到过。我会试着准备一个样品。到目前为止谢谢。问题出在avro对象键上。在将它们更改为字符串并更正avro模式中的名称空间之后,问题就解决了。
final ReadOnlyKeyValueStore<LookupKey, LookupData> lookupStore =
            interactiveQueryService.getQueryableStore("myStore", QueryableStoreTypes.<LookupKey, LookupData>keyValueStore())
lookupStore.get(key)
final KeyValueIterator<LookupKey, LookupData> lookups = lookupStore.all();

Map<LookupKey, LookupData> lookupMap = new HashMap<>();
while (lookups.hasNext()) {
    KeyValue<LookupKey, LookupData> nextLookup = lookups.next();
    lookupMap.put(nextLookup.key, nextLookup.value);
}
lookups.close();