Fix lookup of RabbitMQ for dispatch in CF

This commit is contained in:
Michele Mancioppi
2019-09-05 05:36:43 +02:00
parent e44ddda513
commit e76fd26775

View File

@@ -9,6 +9,7 @@ import (
"strconv" "strconv"
"encoding/json" "encoding/json"
"strings" "strings"
"errors"
"github.com/streadway/amqp" "github.com/streadway/amqp"
"github.com/instana/go-sensor" "github.com/instana/go-sensor"
@@ -184,18 +185,28 @@ func main() {
panic(err) panic(err)
} }
log.Printf("Cloud Foundry detected")
bindingFound := false
services := appEnv.Services services := appEnv.Services
for _, service := range services { for _, service := range services {
for _, serviceBinding := range service { for _, serviceBinding := range service {
bindingName, ok := serviceBinding.CredentialString("binding_name") bindingName := serviceBinding.Name
if ok { if strings.Compare(bindingName, "dispatch_queue") == 0 {
if strings.Compare(bindingName, "dispatch_queue") == 0 { bindingFound = true
amqpUri, _ = serviceBinding.CredentialString("uri")
} log.Printf("RabbitMQ service binding '%s' found", bindingName)
amqpUri, _ = serviceBinding.CredentialString("uri")
} }
} }
} }
if !bindingFound {
panic(errors.New("Service binding 'dispatch_queue' not found!"))
}
} }
// get error threshold from environment // get error threshold from environment