mirror of
https://github.com/openfaas/faas.git
synced 2025-06-19 20:46:41 +00:00
Vendor new queue-worker version
Introduces 0.4.6 of queue-worker - see upstream repo for changes. Signed-off-by: Alex Ellis (VMware) <alexellis2@gmail.com>
This commit is contained in:
17
gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler.go
generated
vendored
17
gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler.go
generated
vendored
@ -15,15 +15,26 @@ type NatsQueue struct {
|
||||
nc stan.Conn
|
||||
}
|
||||
|
||||
type NatsConfig interface {
|
||||
GetClientID() string
|
||||
}
|
||||
|
||||
type DefaultNatsConfig struct {
|
||||
}
|
||||
|
||||
func (DefaultNatsConfig) GetClientID() string {
|
||||
val, _ := os.Hostname()
|
||||
return "faas-publisher-" + val
|
||||
}
|
||||
|
||||
// CreateNatsQueue ready for asynchronous processing
|
||||
func CreateNatsQueue(address string, port int) (*NatsQueue, error) {
|
||||
func CreateNatsQueue(address string, port int, clientConfig NatsConfig) (*NatsQueue, error) {
|
||||
queue1 := NatsQueue{}
|
||||
var err error
|
||||
natsURL := fmt.Sprintf("nats://%s:%d", address, port)
|
||||
log.Printf("Opening connection to %s\n", natsURL)
|
||||
|
||||
val, _ := os.Hostname()
|
||||
clientID := "faas-publisher-" + val
|
||||
clientID := clientConfig.GetClientID()
|
||||
clusterID := "faas-cluster"
|
||||
|
||||
nc, err := stan.Connect(clusterID, clientID, stan.NatsURL(natsURL))
|
||||
|
19
gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler_test.go
generated
vendored
Normal file
19
gateway/vendor/github.com/openfaas/nats-queue-worker/handler/handler_test.go
generated
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_GetClientID_ContainsHostname(t *testing.T) {
|
||||
c := DefaultNatsConfig{}
|
||||
|
||||
val := c.GetClientID()
|
||||
|
||||
hostname, _ := os.Hostname()
|
||||
if !strings.HasSuffix(val, hostname) {
|
||||
t.Errorf("GetClientID should contain hostname as suffix, got: %s", val)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user