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

<?php

require_once __DIR__ . '/../vendor/autoload.php';

use OTC\fg_dms4kafka_event\DMS4KafkaEvent;

function initializer($context)
{
  $logger = $context->getLogger();
  $output = 'Initializer called for function: ' . $context->getFunctionName();
  $logger->debug($output);
  return $output;
}

function handler($event, $context)
{
  $logger = $context->getLogger();

  $logger->info('Function Name: ' . $context->getFunctionName());

  $dms4kafkaEvent = new DMS4KafkaEvent($event);

  $logger->info('Trigger type: ' . $dms4kafkaEvent->getTriggerType());

  $output = [
    'trigger_type' => $dms4kafkaEvent->getTriggerType(),
  ];

  return $output;
}

Full sample code is available in the samples-doc/scratch-event-dms4kafka.