Skip to content

Kafka Consumer

The Kafka Consumer is listening on a Topic destination to a Kafka messaging server.

Basic Usage

Start listening on a topic

import { consumer } from "sdk/kafka";
consumer.topic("topic1", "{}").startListening("<kafka-project>/<kafka-handler>", 1000);

File: <kafka-project>/<kafka-handler.js>

exports.onMessage = function(message) {
    console.log("Hello from My Kafka Listener! Message: " + message);
};

exports.onError = function(error) {
    console.error("Error from My Kafka Listener! Error: " + error);
};

Stop listening on a topic

import { consumer } from "sdk/kafka";
consumer.topic("topic1", "{}").stopListening();

Functions


Function Description Returns
topic(destination, configuration) Returns an object representing a Kafka Topic Topic

Configuration object key-value pairs can be taken from https://kafka.apache.org/documentation/#consumerconfigs

Objects


Topic

Function Description Returns
startListening(handler, timeout) Receives a message from this Kafka Topic if any with the given handler and timeout in milliseconds -
stopListening() Stops listening for new messages -