All Projects → openfaas → Connector Sdk

openfaas / Connector Sdk

Licence: mit
SDK for connecting events to functions

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to Connector Sdk

Vent
jQuery inspired DOM events library
Stars: ✭ 30 (-26.83%)
Mutual labels:  events
Annwvyn
Annwvyn C++ Open Source designed-for-VR game engine and application developement framework
Stars: ✭ 34 (-17.07%)
Mutual labels:  sdk
Elm Ecosystem
Stars: ✭ 36 (-12.2%)
Mutual labels:  ecosystem
Ios P2p Engine
Let your viewers become your unlimitedly scalable CDN.
Stars: ✭ 31 (-24.39%)
Mutual labels:  sdk
Hedera Sdk Rust
Hedera SDK for Rust
Stars: ✭ 33 (-19.51%)
Mutual labels:  sdk
Eventing
Open source specification and implementation of Knative event binding and delivery
Stars: ✭ 980 (+2290.24%)
Mutual labels:  events
Openapi Core Ruby Sdk
Alibaba Cloud Core SDK for Ruby
Stars: ✭ 29 (-29.27%)
Mutual labels:  sdk
Sdk
Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
Stars: ✭ 996 (+2329.27%)
Mutual labels:  sdk
Think Wechat
企业微信SDK for ThinkPHP5
Stars: ✭ 34 (-17.07%)
Mutual labels:  sdk
Connect Java Sdk
Java client library for the Square Connect v2 API
Stars: ✭ 36 (-12.2%)
Mutual labels:  sdk
Vue Tabevents
Event-Based communication across opened tabs for Vue 2.x
Stars: ✭ 31 (-24.39%)
Mutual labels:  events
Uphold Sdk Android
Uphold Android SDK
Stars: ✭ 32 (-21.95%)
Mutual labels:  sdk
Sdk
MEGA C++ SDK
Stars: ✭ 980 (+2290.24%)
Mutual labels:  sdk
Intrinio Realtime Node Sdk
Intrinio NodeJS SDK for Real-Time Stock & Crypto Prices
Stars: ✭ 30 (-26.83%)
Mutual labels:  sdk
Aquameta
Web development platform built entirely in PostgreSQL
Stars: ✭ 987 (+2307.32%)
Mutual labels:  events
Facebook
A Facebook Graph API SDK For Go.
Stars: ✭ 948 (+2212.2%)
Mutual labels:  sdk
Javasdk
the Java SDK for hyperchain (developing)
Stars: ✭ 35 (-14.63%)
Mutual labels:  sdk
Waliyun
阿里云Node.js Open API SDK(完整版)
Stars: ✭ 40 (-2.44%)
Mutual labels:  sdk
Commercetools Php Sdk
The e-commerce SDK from commercetools for PHP.
Stars: ✭ 38 (-7.32%)
Mutual labels:  sdk
Oauth Pythonclient
The Python OAuth client provides a set of methods that make it easier to work with Intuit's OAuth and OpenID implementation.
Stars: ✭ 36 (-12.2%)
Mutual labels:  sdk

connector-sdk

The connector-sdk is a library written in Go that you can use to create event-connectors for OpenFaaS functions.

How it works:

  • Create a new CLI application with Go
  • Add the code to subscribe to events or messages from your source - i.e. a database, webhooks, message queue
  • Add the github.com/openfaas/connector-sdk/types package to your code
  • Setup a types.ControllerConfig with the gateway location
  • Run types.NewController
  • Whenever you receive a message from your source, run controller.Invoke(topic, data)

Then whichever functions in your cluster have matching annotation of "topic: topic" will be invoked.

Conceptual design:

Conceptual design

Each function expresses which topics it can be triggered by, the broker then invokes them using the SDK.

See also: Triggers in OpenFaaS

Creating your own connector

See the examples in the OpenFaaS Docs for inspiration.

You can copy one of them and adapt it, or see the "tester" example in this repo.

The tester example doesn't have an event subscription, but a for loop and sleep combination which simulates receiving an event. You would replace the timer with the callback function from your source such as a HTTP webhook endpoint, a pub-sub SDK or likewise.

Within the event subscriber code, you should call "Invoke()", passing in the topic and message. The functions advertise their "topic".

	// Simulate events emitting from queue/pub-sub
	for {
		log.Printf("Invoking on topic vm.powered.on - %s\n", gateway)
		time.Sleep(2 * time.Second)
		data := []byte("test " + time.Now().String())
		controller.Invoke("vm.powered.on", &data)
	}

The results can then be printed using a result receiver.

// ResponseReceiver enables connector to receive results from the
// function invocation
type ResponseReceiver struct {
}

// Response is triggered by the controller when a message is
// received from the function invocation
func (ResponseReceiver) Response(res types.InvokerResponse) {
	if res.Error != nil {
		log.Printf("tester got error: %s", res.Error.Error())
	} else {
		log.Printf("tester got result: [%d] %s => %s (%d) bytes", res.Status, res.Topic, res.Function, len(*res.Body))
	}
}

There are no retry mechanisms at present, but you could use the receiver to requeue failed invocations, or to send on to a dead-letter queue (DLQ).

If you expect many requests in a short period of time, you may want to defer the executions using OpenFaaS' built-in asynchronous queue.

Set the following in ControllerConfig:

	config := &types.ControllerConfig{
        ...
		AsyncFunctionInvocation: true,
	}

View the code: cmd/tester/main.go

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].