简体   繁体   English

使用 nodejs 查询 Kafka 主题

[英]Query a Kafka Topic with nodejs

I'm a bit puzzled.我有点不解。 Is there really no NodeJS API to query Kafka topics (eg as with Kafka Streams and the Java API)?真的没有 NodeJS API 来查询 Kafka 主题(例如 Kafka Streams 和 Java API)吗? Am I missing something?我错过了什么吗?

Just to get this straight.只是为了弄清楚这一点。 Only be notified of the latest event/record of a topic is not enough for me.仅通知主题的最新事件/记录对我来说是不够的。 I want to query and process the topics' records - and then maybe store an aggregate to another topic.我想查询和处理主题的记录 - 然后可能将聚合存储到另一个主题。

thanks for your thoughts if this is possible with nodejs and a library only.如果只有 nodejs 和一个库可以做到这一点,感谢您的想法。

Here what worked for me and most people use.这是对我和大多数人有用的东西。

Limited solution有限的解决方案

If you are stubborn and want to insist on a node.js library to wrap things up for you: https://nodefluent.github.io/kafka-streams/docs/如果你很固执,想坚持使用 node.js 库来为你整理一下: https://nodefluent.github.io/kafka-streams/docs/

As of today they offer:截至今天,他们提供:

  • easy access streams轻松访问流
  • merge streams合并流
  • split streams分流

Full blown solution完整的解决方案

The easiest way (as from today - there are rumors Confluent is creating more libraries and also one for nodejs) one can query kafka is by the REST API .最简单的方法(从今天开始——有传言说 Confluent 正在创建更多的库,还有一个用于 nodejs),可以通过REST API查询 kafka。 It is part of the ksqlDB and ksqlDB is part of the confluent platform which also ships with Zookeeper and a Kafka instance, which you probably already have.它是 ksqlDB 的一部分,ksqlDB 是融合平台的一部分,该平台还附带了 Zookeeper 和 Kafka 实例,您可能已经拥有了。 If you wonder how to install:如果您想知道如何安装:

  1. It spins up in 1 minutes with the docker yml file .它使用docker yml 文件在 1 分钟内启动。

  2. Run docker-compose up -d docker-compose up -d

  3. See the ports and services running with docker ps查看运行的端口和服务docker ps

  4. Start requesting the status from the REST API by simply sending a GET request to http://0.0.0.0:8088/ .只需向http://0.0.0.0:8088/发送 GET 请求,即可开始从 REST API 请求状态。 It will return service information.它将返回服务信息。

     { "KsqlServerInfo": { "version": "6.2.0", "kafkaClusterId": "uOXfee3zQ76vCKBbREw1yg", "ksqlServiceId": "default_", "serverStatus": "RUNNING" } }

Hope the strips some of you from the initial research.希望你们中的一些人从最初的研究中脱身。 And.... if we are lucky there will be a wrapper library soon.而且....如果我们幸运的话,很快就会有一个包装器库。

Then create a stream out of your topic and voila.然后根据您的主题创建一个 stream,瞧。 You are ready to query your topic (through the stream) with the REST API .您已准备好使用REST API查询您的主题(通过流)。 Since the REST API offers HTTP2, one could also expect continuous updates on freshly arriving records in the stream. Apply Push Queries for this.由于 REST API 提供 HTTP2,因此还可以预期 stream 中新到达的记录会持续更新。为此应用推送查询。 Pull queries will cut the line after the result has been delivered.拉取查询将在结果交付后切断线路。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM