{"id":19865642,"url":"https://github.com/openfaas/connector-sdk","last_synced_at":"2025-04-06T08:14:57.394Z","repository":{"id":47202386,"uuid":"158098712","full_name":"openfaas/connector-sdk","owner":"openfaas","description":"SDK for connecting events to functions","archived":false,"fork":false,"pushed_at":"2025-01-21T12:29:47.000Z","size":16647,"stargazers_count":53,"open_issues_count":14,"forks_count":25,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T07:09:51.189Z","etag":null,"topics":["ecosystem","events","openfaas","sdk","triggers"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openfaas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-11-18T15:35:21.000Z","updated_at":"2025-02-11T21:57:55.000Z","dependencies_parsed_at":"2025-02-23T07:11:33.100Z","dependency_job_id":"1c3a1ac7-5e86-4926-859f-3b3408bb7d9c","html_url":"https://github.com/openfaas/connector-sdk","commit_stats":null,"previous_names":["openfaas-incubator/connector-sdk"],"tags_count":29,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfaas%2Fconnector-sdk","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfaas%2Fconnector-sdk/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfaas%2Fconnector-sdk/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openfaas%2Fconnector-sdk/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openfaas","download_url":"https://codeload.github.com/openfaas/connector-sdk/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247451667,"owners_count":20940944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ecosystem","events","openfaas","sdk","triggers"],"created_at":"2024-11-12T15:23:33.416Z","updated_at":"2025-04-06T08:14:57.361Z","avatar_url":"https://github.com/openfaas.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"## connector-sdk\n\nThe connector-sdk is a library written in Go that you can use to create event-connectors for OpenFaaS functions.\n\nHow it works:\n\n* Create a new CLI application with Go\n* Add the code to subscribe to events or messages from your source - i.e. a database, webhooks, message queue\n* Add the `github.com/openfaas/connector-sdk/types` package to your code\n* Setup a `types.ControllerConfig` with the gateway location\n* Run `types.NewController`\n* Whenever you receive a message from your source, run `controller.Invoke(topic, data)`\n\nThen whichever functions in your cluster have matching annotation of \"topic: topic\" will be invoked.\n\n### Conceptual design:\n\n![Conceptual design](https://pbs.twimg.com/media/DrlGTNtWkAEGbnQ.jpg)\n\n\u003e Each function expresses which topics it can be triggered by, the broker then invokes them using the SDK.\n\nSee also: [Triggers in OpenFaaS](https://docs.openfaas.com/reference/triggers/)\n\n## Creating your own connector\n\nSee the examples in the [OpenFaaS Docs](https://docs.openfaas.com/reference/triggers/) for inspiration.\n\nYou can copy one of them and adapt it, or see the \"tester\" example in this repo.\n\nThe 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.\n\nWithin the event subscriber code, you should call \"Invoke()\", passing in the topic and message. The functions advertise their \"topic\".\n\n```go\n\n\tadditionalHeaders := http.Header{}\n\tadditionalHeaders.Add(\"X-Served-By\", \"cmd/tester\")\n\n\t// Simulate events emitting from queue/pub-sub\n\tfor {\n\t\tlog.Printf(\"Invoking on topic payment - %s\\n\", gateway)\n\t\ttime.Sleep(2 * time.Second)\n\t\tdata := []byte(\"test \" + time.Now().String())\n\t\tcontroller.Invoke(\"payment\", \u0026data, additionalHeaders)\n\t}\n```\n\nThe results can then be printed using a result receiver.\n\n```go\n// ResponseReceiver enables connector to receive results from the\n// function invocation\ntype ResponseReceiver struct {\n}\n\n// Response is triggered by the controller when a message is\n// received from the function invocation\nfunc (ResponseReceiver) Response(res types.InvokerResponse) {\n\tif res.Error != nil {\n\t\tlog.Printf(\"tester got error: %s\", res.Error.Error())\n\t} else {\n\t\tlog.Printf(\"tester got result: [%d] %s =\u003e %s (%d) bytes\", res.Status, res.Topic, res.Function, len(*res.Body))\n\t}\n}\n```\n\nThere 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).\n\nIf you expect many requests in a short period of time, you may want to defer the executions using OpenFaaS' built-in asynchronous queue.\n\nSet the following in `ControllerConfig`:\n\n```go\n\tconfig := \u0026types.ControllerConfig{\n        ...\n\t\tAsyncFunctionInvocation: true,\n\t}\n```\n\nIf you need to use the `Content-Type` header to validate or to check when it invoke the function you can set the `Content-Type`\nin `ControllerConfig`:\n\n```go\n\tconfig := \u0026types.ControllerConfig{\n        ...\n\t\tContentType: \"application/json\",\n\t}\n```\n\nView the code: [cmd/tester/main.go](cmd/tester/main.go)\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfaas%2Fconnector-sdk","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenfaas%2Fconnector-sdk","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenfaas%2Fconnector-sdk/lists"}