Commit 47f89bfd authored by Lukas Burgey's avatar Lukas Burgey
Browse files

Connect to services exchange

parent 8c65f3a7
......@@ -29,6 +29,15 @@ type (
}
)
func appendIfMissing(slice []string, newElem string) []string {
for _, elem := range slice {
if elem == newElem {
return slice
}
}
return append(slice, newElem)
}
func (c config) Log(formatString string, params ...interface{}) {
log.Printf("%s "+formatString, append([]interface{}{"[Conf]"}, params...)...)
}
......@@ -38,14 +47,28 @@ func (c consumer) Log(formatString string, params ...interface{}) {
}
func (c *config) consumer() (cons *consumer) {
var groupRoutingKeys []string
for groupName := range c.GroupToServices {
groupRoutingKeys = append(groupRoutingKeys, fmt.Sprintf("%s", groupName))
// calculate all the routing keys for the exchanges
groupRoutingKeys := []string{}
entitlementRoutingKeys := []string{}
// all services we provide (either for groups or entitlements)
serviceRoutingKeys := []string{}
for groupName, groupServices := range c.GroupToServices {
groupRoutingKeys = appendIfMissing(groupRoutingKeys, groupName)
for _, groupService := range groupServices {
serviceRoutingKeys = appendIfMissing(serviceRoutingKeys, groupService.Name)
}
}
var entitlementRoutingKeys []string
for entitlementName := range c.EntitlementToServices {
entitlementRoutingKeys = append(entitlementRoutingKeys, fmt.Sprintf("%s", entitlementName))
for entitlementName, entitlementServices := range c.EntitlementToServices {
entitlementRoutingKeys = appendIfMissing(entitlementRoutingKeys, entitlementName)
for _, entitlementService := range entitlementServices {
serviceRoutingKeys = appendIfMissing(serviceRoutingKeys, entitlementService.Name)
}
}
cons = &consumer{
......@@ -57,6 +80,9 @@ func (c *config) consumer() (cons *consumer) {
exchange{
"entitlements", "topic", entitlementRoutingKeys,
},
exchange{
"services", "topic", serviceRoutingKeys,
},
},
consumer: c.consume,
reconnectTimeout: c.ReconnectTimeout,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment