0

这个问题与为什么我需要轮询消息集线器有关,与该答案链接的文档显示Kafka将支持“长轮询”概念,但是现有的nodejs支持消息集线器没有明确的方法来实现这样的机制。为 nodejs 提供的演示应用程序仅使用 250 毫秒的计时器间隔来处理从服务器检索消息。我想用更复杂的长轮询方法替换它,使用 Kafka 支持长轮询方法: To avoid this we have parameters in our pull request that allow the consumer request to block in a "long poll" waiting until data arrives 但是现有实现似乎不允许配置任何此类参数,也不清楚必要的参数是什么是。get函数的原型定义为:

MessageHub.ConsumerInstance.prototype.get(topicName [toValue])

Retrieves a message from the provided topic name.

    topicName - (String) (required), the topic to retrieve messages from.
    toValue - (Boolean) (optional), unwraps base64 encoded messages, if true. Defaults to true.

Returns a Promise object which will be fulfilled when the request to the service resolves.

所以没有配置选项。或者,您能否提供一个链接,该文档定义了在 message-hub.js 模块中实现的那些 URL 的 URL 和可用选项?

4

1 回答 1

1

您提到的一个 npm 模块是在 Message Hub 提供的 REST API 之上构建的 - 它本质上是 Confluent REST 代理 API 减去 AVRO 支持 http://docs.confluent.io/2.0.1/kafka-休息/文档/api.html

那个 npm 没有为你提供完整的 Kafka api。它仅提供 REST API 的一个子集

Kafka 文档所指的长轮询是 Java 消费者轮询中的超时 https://kafka.apache.org/0102/javadoc/org/apache/kafka/clients/consumer/KafkaConsumer.html#poll(long)

Node.js 的一个好的客户端是 https://github.com/Blizzard/node-rdkafka

请在 https://github.com/ibm-messaging/message-hub-samples中查看我们的编码示例

于 2017-06-07T15:16:57.237 回答