How to use the node-rdkafka.createReadStream function in node-rdkafka

To help you get started, we’ve selected a few node-rdkafka examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ancashoria / graphql-kafka-subscriptions / src / kafka-pubsub.ts View on Github external
private createConsumer(topic: string) {
    // Create a group for each instance. The consumer will receive all messages from the topic
    const groupId = this.options.groupId || Math.ceil(Math.random() * 9999)
    const stream = Kafka.createReadStream(
        Object.assign(
          {},
          {
            'group.id': `kafka-group-${groupId}`,
            'metadata.broker.list': this.brokerList(),
          },
          this.options.globalConfig,
        ),
        {},
        { topics: [topic] }
    );
    stream.consumer.on('data', (message) => {
      let parsedMessage = JSON.parse(message.value.toString())

      // Using channel abstraction
      if (parsedMessage.channel) {
github ancashoria / graphql-kafka-subscriptions / dist / kafka-pubsub.js View on Github external
KafkaPubSub.prototype.createConsumer = function (topic) {
        var _this = this;
        var groupId = this.options.groupId || Math.ceil(Math.random() * 9999);
        var stream = Kafka.createReadStream(Object.assign({}, {
            'group.id': "kafka-group-" + groupId,
            'metadata.broker.list': this.brokerList(),
        }, this.options.globalConfig), {}, { topics: [topic] });
        stream.consumer.on('data', function (message) {
            var parsedMessage = JSON.parse(message.value.toString());
            if (parsedMessage.channel) {
                var channel = parsedMessage.channel, payload = __rest(parsedMessage, ["channel"]);
                _this.onMessage(parsedMessage.channel, payload);
            }
            else {
                _this.onMessage(topic, parsedMessage);
            }
        });
        return stream;
    };
    return KafkaPubSub;