nav-img
Advanced

Using an Open-Source Kafka Trigger

This section describes how to create an open-source Kafka trigger and configure an event to trigger a function.

If you use an open-source Kafka trigger for a function, FunctionGraph periodically polls messages from a specific topic in Kafka and passes the messages as an input parameter to invoke the function.

Prerequisites

Before creating a trigger, make sure you have prepared the following:

Creating an Open-Source Kafka Trigger

  1. Log in to the FunctionGraph console. In the navigation pane, choose Functions > Function List.
  2. Click the function to be configured to go to the function details page.
  3. Choose Configuration > Triggers and click Create Trigger.
  4. Set the following parameters:

    • Trigger Type: Select Kafka (OPENSOURCEKAFKA).
    • Connection Address: Addresses of brokers running Kafka. Separate the addresses with commas (,).
    • Topic: Enter one or more topics.
    • Batch Size: Maximum number of data records that can be processed by the function at a time.

  5. Click OK.

    Note

    The network configuration must be the same as that of the ECS where Kafka is deployed, including the VPC and subnet.

Enabling an Open-Source Kafka Trigger

By default, open-source Kafka triggers are disabled. To use such a trigger, click Enable on the Trigger page.

Note

If a trigger cannot be disabled, contact technical support.

Configuring an Open-Source Kafka Event to Trigger the Function

  1. On the Code tab page, click Configure Test Event.
  2. Set the parameters described in Table 1 and click Create.

    Table 1 Test event information

    Parameter

    Description

    Configure Test Event

    You can choose to create a test event or edit an existing one.

    Use the default option Create new test event.

    Event Template

    Select Kafka (OPENSOURCEKAFKA) to use the built-in open-source Kafka event template.

    Event Name

    The event name can contain 1 to 25 characters and must start with a letter and end with a letter or digit. Only letters, digits, underscores (_), and hyphens (-) are allowed. For example, kafka-123test.

    Test event

    The system automatically loads the built-in Kafka event template, which is used in this example without modifications.

  3. Click Test. The function test result is displayed.