Trigger functions from Kafka

OpenFaaS PRO offers an additional component that can be used to invoke functions from Kafka topics.

Installation

You can install the Kafka connector using its helm chart, or by using arkade.

Installation with arkade

  1. export TOPICS="payment.created"
  2. arkade install kafka-connector \
  3. --broker-host kafka-broker \
  4. --topics $TOPICS \
  5. --license-file $HOME/.openfaas/LICENSE

Installation with Helm

See helm chart

Usage

Once you have configured a number of topics, you can then annotate your functions so that they get triggered by any incoming messages on those topics.

Create a new function:

  1. export OPENFAAS_PREFIX=ghcr.io/openfaas
  2. faas-cli new --lang go provision-customer

Now add an annotation for the payment.created topic, so that the provision-customer function is invoked for any message received:

  1. version: 1.0
  2. provider:
  3. name: openfaas
  4. gateway: http://127.0.0.1:8080
  5. functions:
  6. provision-customer:
  7. annotations:
  8. topic: payment.created
  9. lang: go
  10. handler: ./provision-customer
  11. image: ghcr.io/openfaas:provision-customer

Now deploy your function, and publish an event to your Kafka broker on the payment.created topic.

See also

Blog post / walk-through: Staying on topic: trigger your OpenFaaS functions with Apache Kafka