SEBA-619 implement event subscriber to subscribe events
Scope of this story was augmented to include functionality to modify properties of a subscription
subscribe to events 1 by 1 instead of a list of events
get subscription destination ip from an env variable configured thru helm charts
Change-Id: If72848bd804c11998b4584634669d68bd9d9e7e0
diff --git a/main.go b/main.go
index 477568f..6394ba7 100644
--- a/main.go
+++ b/main.go
@@ -24,6 +24,7 @@
"github.com/Shopify/sarama"
"google.golang.org/grpc"
"golang.org/x/net/context"
+ "crypto/tls"
empty "github.com/golang/protobuf/ptypes/empty"
importer "./proto"
)
@@ -35,8 +36,10 @@
var DataProducer sarama.AsyncProducer
+var default_events = [...]string{"ResourceAdded","ResourceRemoved","Alert"}
+
type device struct {
- subscription []string
+ subscriptions map[string]uint
freq uint32
}
@@ -49,6 +52,7 @@
func (s *Server) SendDeviceInfo(c context.Context, info *importer.DeviceInfo) (*empty.Empty, error) {
d := device {
+ subscriptions: make(map[string]uint),
freq: info.Frequency,
}
s.devicemap[info.IpAddress] = &d
@@ -56,15 +60,24 @@
return &empty.Empty{}, nil
}
func(s *Server) subscribeevents() {
+ http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
for {
select {
- case info:= <-s.devicechan:
- ip_address:= info.IpAddress
+ case info:= <-s.devicechan:
+ ip_address:= info.IpAddress
fmt.Println("Configuring %s ...", ip_address)
// call subscription function with info.IpAddress
+ for _, event := range default_events {
+ rtn, id := add_subscription(ip_address, event)
+ if rtn {
+ s.devicemap[ip_address].subscriptions[event] = id
+ fmt.Println("subscription added", event, id)
+ }
+ }
}
}
}
+
func NewGrpcServer(grpcport string) (l net.Listener, g *grpc.Server, e error) {
fmt.Println("Listening %s ...", grpcport)
g = grpc.NewServer()