基于Kafka的Pub / Sub与NodeJS

时间:2016-04-25 23:39:06

标签: node.js apache-kafka publish-subscribe

我正在尝试使用Apache Kafka开发Pub / Sub系统。 Rest API是用NodeJS编写的。我使用的库是No-Kafka。用户传入他想要使用的队列的主题和偏移量(起始位置),API返回前10条消息。

var Consumer = new kafka.Consumer;
var client1 = new kafka.Client;
var consumer = new Consumer(client1, [{
    topic: 'TutorialTopic',
    partition: 0,
    offset: 0
}], {
    autoCommit: true,
    fromOffset: true
});


app.get('/consume/:off', function(req, res) {
    console.log("In Consume");

    consumer.setOffset('TutorialTopic', 0, req.params.off);
    consumer.on('message', function(message) {
        console.log("Consumer Ready");
        console.log(message);
    });

    res.send("Consumed");

});

我正在使用Hurl-it在线发送HTTP请求。每当我提出请求时,都需要450到2000毫秒。这是一个很好的响应时间吗?如果不是,我该如何提高API的速度?

如果您需要其他信息,请与我们联系。 提前谢谢。

编辑:我的代码与Kafka-node。

class Texture {};
class Color {};
class Square {};

class ITextured { public: virtual void setTexture(Texture) = 0; };
class IColored { public: virtual void setColor(Color) = 0; };

class ColoredSquare : public IColored, public ITextured, public Square {
    Texture tex;
    Color col;
public:
    virtual void setTexture(Texture t) { tex = t; }
    virtual void setColor(Color c) { col = c; }
};

因为图书馆提供了一个" on"事件处理程序,如何识别两个或更多人同时访问我的网站?使用kafka-node访问特定偏移量的消息的最佳方法是什么?

0 个答案:

没有答案
相关问题