如何在 NodeJS 中使用 Bluemix Message Hub 设置 'long poll'

How do I set up a 'long poll' using Bluemix Message Hub in NodeJS

此问题与有关,文档link与该答案一起显示Kafka将支持'long-poll'概念,但现有的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.

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

您提到的那个是构建在 Message Hub 提供的 REST API 之上的 npm 模块 - 这本质上是 Confluent REST Proxy API 减去 AVRO 支持 http://docs.confluent.io/2.0.1/kafka-rest/docs/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