Coder Social home page Coder Social logo

ftrigger's Introduction

Triggers for Functions as a Service (FaaS) Functions

Functions as a Service (FaaS) is a framework by Alex Ellis for building serverless functions on Docker Swarm. This repo provides a tool called ftrigger that is designed to sit alongside a FaaS gateway, observe labels on function services, and then automatically trigger functions based on the conditions described in the labels.

The only supported trigger at the moment is for Kafka topics. A time-based trigger (something like cron) will be developed next.

Configuring Function Services to Respond to Kafka Messages

FaaS functions can be declared as Docker services. If the service containers are labeled with function: 'true', they will be automatically registered to a running gateway and made available.

echoit:
  image: functions/alpine:health
  labels:
    function: "true"
  environment:
    fprocess: "cat"

ftrigger watches a running gateway and scans functions for service labels matching the pattern ftrigger.*, where the wildcard matches the name of a trigger service (only kafka is available). The trigger can be configured with labels extending from that, such as the pattern ftrigger.kafka.* for the kafka trigger service.

In the following example, the echoit function is labeled to respond to Kafka messages on the echo topic.

echoit:
  image: functions/alpine:health
  labels:
    function: "true"
  environment:
    fprocess: "cat"
  deploy:
    labels:
      ftrigger.kafka: 'true'
      ftrigger.kafka.topic: 'echo'

By default, the kafka trigger sends the Kafka message value as the function request body. This can be changed to a JSON object with the message key and value by setting ftrigger.kafka.data to key-value.

echoit:
  ...
  deploy:
    labels:
      ftrigger.kafka: 'true'
      ftrigger.kafka.topic: 'echo'
      ftrigger.kafka.data: 'key-value'

There are no other options at this time.

Test Drive

You can quickly deploy ftrigger on Play with Docker, a community-run Docker playground, by clicking the following button.

Try in PWD

The demo stack is configured with an echoit function configured to respond to messages on the Kafka topic named echo. You can produce messages in the topic by running kafka-console-producer in the kafka service's container, then typing into the console. Every line is published as a message in the topic.

SERVICE_NAME=ftrigger_kafka
TASK_ID=$(docker service ps --filter 'desired-state=running' $SERVICE_NAME -q)
CONTAINER_ID=$(docker inspect --format '{{ .Status.ContainerStatus.ContainerID }}' $TASK_ID)
docker exec -it $CONTAINER_ID kafka-console-producer --broker-list kafka:9092 --topic echo
(type messages here, one per line)

The gateway logs will show that the function is being called for every message. Here is an example run in Play with Docker, with two messages (“abc” and “def” produced to the topic), and the gateway logs showing the echoit function called two times in response.

[node1] (local) [email protected] ~
$ SERVICE_NAME=ftrigger_kafka
[node1] (local) [email protected] ~
$ TASK_ID=$(docker service ps --filter 'desired-state=running' $SERVICE_NAME -q)
[node1] (local) [email protected] ~
$ CONTAINER_ID=$(docker inspect --format '{{ .Status.ContainerStatus.ContainerID }}' $TASK_ID)
[node1] (local) [email protected] ~
$ docker exec -it $CONTAINER_ID kafka-console-producer --broker-list kafka:9092 --topic echo
abc
def
^C[node1] (local) [email protected] ~
$ docker service logs ftrigger_gateway
ftrigger_gateway.1.p86ucxfnkubk@node1    | 2017/10/11 22:36:18 HTTP Read Timeout: 8s
ftrigger_gateway.1.p86ucxfnkubk@node1    | 2017/10/11 22:36:18 HTTP Write Timeout: 8s
ftrigger_gateway.1.p86ucxfnkubk@node1    | 2017/10/11 22:36:18 Docker API version: 1.32, 17.09.0-ce
ftrigger_gateway.1.p86ucxfnkubk@node1    | Resolving: 'ftrigger_echoit'
ftrigger_gateway.1.p86ucxfnkubk@node1    | [1507761443] Forwarding request [] to: http://10.0.1.5:8080/
ftrigger_gateway.1.p86ucxfnkubk@node1    | [1507761443] took 0.009424 seconds
ftrigger_gateway.1.p86ucxfnkubk@node1    | Resolving: 'ftrigger_echoit'
ftrigger_gateway.1.p86ucxfnkubk@node1    | [1507761445] Forwarding request [] to: http://10.0.1.5:8080/
ftrigger_gateway.1.p86ucxfnkubk@node1    | [1507761445] took 0.002649 seconds

Maintenance

This repository and image are currently maintained by the Research Management Systems project at the University of Calgary.

ftrigger's People

Contributors

kinghuang avatar

Stargazers

Xavier Ngansop avatar

Watchers

James Cloos avatar Alex Ellis avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.