在 Kubernetes 中查询远程状态存储(交互式查询)
Querying Remote State Stores in Kubernetes (Interactive Queries)
对于查询部署在 Kubernetes 中的应用程序实例之间的远程状态存储,是否有任何建议?我们的应用程序实例部署了 2 个或更多副本。
基于文档
https://kafka.apache.org/10/documentation/streams/developer-guide/interactive-queries.html#id7
streams.allMetadataForStore("word-count")
.stream()
.map(streamsMetadata -> {
// Construct the (fictituous) full endpoint URL to query the current remote application instance
String url = "http://" + streamsMetadata.host() + ":" + streamsMetadata.port() + "/word-count/alice";
// Read and return the count for 'alice', if any.
return http.getLong(url);
})
.filter(s -> s != null)
.findFirst();
streamsMetadata.host() 会产生 POD IP 吗?如果是,是否允许从这个 pod 调用另一个 pod?这是正确的做法吗?
streamsMetadata.host()
此方法 returns 无论您通过 application.server
配置参数配置什么。即,每个应用程序实例(在您的情况下是每个 POD),必须设置此配置以提供如何访问它的信息(例如,它的 IP 和端口)。 Kafka Streams 为您将此信息分发到所有应用程序实例。
您还需要相应地配置 PODs 以允许通过指定端口的 sending/receiving 查询请求。这部分是您需要自己编写的附加代码,即某种 "query routing layer"。 Kafka Streams 仅内置支持查询本地状态和分发有关哪个状态托管在何处的元数据;但是没有内置的删除查询支持。
可以在 Github 上找到查询路由层的示例实现 (WordCountInteractiveQueries
):https://github.com/confluentinc/kafka-streams-examples
我还建议查看文档和博客 post:
对于查询部署在 Kubernetes 中的应用程序实例之间的远程状态存储,是否有任何建议?我们的应用程序实例部署了 2 个或更多副本。
基于文档 https://kafka.apache.org/10/documentation/streams/developer-guide/interactive-queries.html#id7
streams.allMetadataForStore("word-count")
.stream()
.map(streamsMetadata -> {
// Construct the (fictituous) full endpoint URL to query the current remote application instance
String url = "http://" + streamsMetadata.host() + ":" + streamsMetadata.port() + "/word-count/alice";
// Read and return the count for 'alice', if any.
return http.getLong(url);
})
.filter(s -> s != null)
.findFirst();
streamsMetadata.host() 会产生 POD IP 吗?如果是,是否允许从这个 pod 调用另一个 pod?这是正确的做法吗?
streamsMetadata.host()
此方法 returns 无论您通过 application.server
配置参数配置什么。即,每个应用程序实例(在您的情况下是每个 POD),必须设置此配置以提供如何访问它的信息(例如,它的 IP 和端口)。 Kafka Streams 为您将此信息分发到所有应用程序实例。
您还需要相应地配置 PODs 以允许通过指定端口的 sending/receiving 查询请求。这部分是您需要自己编写的附加代码,即某种 "query routing layer"。 Kafka Streams 仅内置支持查询本地状态和分发有关哪个状态托管在何处的元数据;但是没有内置的删除查询支持。
可以在 Github 上找到查询路由层的示例实现 (WordCountInteractiveQueries
):https://github.com/confluentinc/kafka-streams-examples
我还建议查看文档和博客 post: