DMS for Kafka Event Source

DMS for Kafka is a message queuing service that provides Kafka premium instances. If you create a Kafka trigger for a function, when a message is sent to a Kafka instance topic, FunctionGraph will retrieve the message and trigger the function to perform other operations.

For the use of Kafka triggers, please refer to Using a Kafka Trigger.

Kafka example event

{
  "event_version": "v1.0",
  "event_time": 1576737962,
  "trigger_type": "KAFKA",
  "region": "eu-de",
  "instance_id": "08fd3e1b-cf56-401f-b4c6-81fd2a1d3ae6",
  "records": [
      {
          "messages": [
              "kafka message1",
              "kafka message2",
              "kafka message3",
              "kafka message4",
              "kafka message5"
          ],
          "topic_id": "topic-test"
      }
  ]
}

Parameter description

Parameter

Type

Description

event_version

String

Event version

event_time

String

Time when an event occurs

trigger_type

String

Event type: KAFKA

region

String

Region where a Kafka instance resides

instance_id

String

Kafka instance ID

messages

String[]

Message content

topic_id

String

Message ID

Example

const { DMS4KafkaEvent } = require("@opentelekomcloud-community/fg-dms4kafka-event");

exports.initializer = function (context, callback) {
  const logger = context.getLogger();
  logger.info("Function initialized");
  callback(null, "");
};

exports.handler = async function (event, context) {
  const logger = context.getLogger();

  logger.info("Function Name:", context.getFunctionName());

  const kafkaEvent = new DMS4KafkaEvent(event);

  logger.info("Trigger type:", kafkaEvent.getTriggerType());
  
  const output = {  
    trigger_type: kafkaEvent.getTriggerType(),
  };

  return output;
};