Skip to content

Commit

Permalink
Rebase with upstream. Added topic environment variable.
Browse files Browse the repository at this point in the history
Signed-off-by: Rishabh Gupta<[email protected]>
  • Loading branch information
zeerorg committed Jan 28, 2019
1 parent b59bcbe commit ddcf919
Show file tree
Hide file tree
Showing 17 changed files with 781 additions and 54 deletions.
14 changes: 11 additions & 3 deletions cmd/tester/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cmd/tester/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

[[constraint]]
name = "github.com/openfaas-incubator/connector-sdk"
version = "0.2.0"
version = "0.3.1"

[prune]
go-tests = true
Expand Down
2 changes: 1 addition & 1 deletion cmd/tester/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ To check if it actually works and triggers a function, deploy any function with
You can also run this command to deploy a sample function and see `trigger-func` invocation count growing in ui.

```bash
faas-cli deploy --image=functions/nodeinfo --name=trigger-func --annotation topic=faas-request
faas-cli deploy --image=functions/nodeinfo --name=trigger-func --annotation topic=vm.powered.on
```
42 changes: 35 additions & 7 deletions cmd/tester/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
package main

import (
"errors"
"log"
"os"
"time"

"github.com/openfaas-incubator/connector-sdk/types"
)

func main() {
creds := types.GetCredentials()
config := &types.ControllerConfig{
RebuildInterval: time.Millisecond * 1000,
GatewayURL: "http://127.0.0.1:8080",
PrintResponse: true,
PrintResponseBody: true,
config, err := getControllerConfig()
if err != nil {
panic(err)
}

controller := types.NewController(creds, config)
Expand All @@ -27,11 +27,16 @@ func main() {

controller.BeginMapBuilder()

topic, err := getTopic()
if err != nil {
panic(err)
}

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

}
Expand All @@ -49,4 +54,27 @@ func (ResponseReceiver) Response(res types.InvokerResponse) {
} else {
log.Printf("tester got result: [%d] %s => %s (%d) bytes", res.Status, res.Topic, res.Function, len(*res.Body))
}
}
}

func getControllerConfig() (*types.ControllerConfig, error) {
gatewayURL, ok := os.LookupEnv("gateway_url")
if !ok {
return nil, errors.New("Gateway URL not set")
}

return &types.ControllerConfig{
RebuildInterval: time.Millisecond * 1000,
GatewayURL: gatewayURL,
PrintResponse: true,
PrintResponseBody: true,
}, nil
}

func getTopic() (string, error) {
topic, ok := os.LookupEnv("topic")
if !ok {
return "", errors.New("topic not provided")
}

return topic, nil
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit ddcf919

Please sign in to comment.