【问题标题】:How do I set up a 'long poll' using Bluemix Message Hub in NodeJS如何在 NodeJS 中使用 Bluemix Message Hub 设置“长轮询”
【发布时间】:2017-06-07 23:16:57
【问题描述】:

这个问题与why do I need to poll message hub有关,与该答案链接的文档显示Kafka将支持“长轮询”概念,但现有的nodejs支持message-hub没有明确的方法来实现这样的机制。为 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 和可用选项?

【问题讨论】:

    标签: node.js ibm-cloud message-hub


    【解决方案1】:

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

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

    Kafka文档所指的long poll是Java Consumer poll中的超时 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

    【讨论】:

    • 谢谢。第一个 URL 对我了解如何在 nodeJS 中进行这项工作至关重要。我在示例(第 3 个 URL)中看到的是,如果没有要使用的消息,nodeJS 会立即返回,而不是等到发生超时或提供消息。 Consumer/Get 的查询参数只允许 maxbytes,但配置选项意味着 max.timeout.ms 应该默认为 1000ms。这不会发生 - 如果没有要检索的消息,rest 会立即返回空结果。
    猜你喜欢
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 2016-03-09
    • 1970-01-01
    • 2011-08-08
    相关资源
    最近更新 更多