Skip to content
Snippets Groups Projects
Commit 3c338ffe authored by Malte Bauch's avatar Malte Bauch
Browse files

WIP: added goroutine to catch subscribe channel output

parent ca0da1f0
No related branches found
No related tags found
3 merge requests!376Add additional example application hostname-checker,!343Add basic application framework and example application to show interaction between events an NBI,!342Resolve "Add an option to send gNMI Subscribe requests via SBI"
Pipeline #107935 failed
...@@ -63,11 +63,11 @@ The device UUID and request path must be specified as a positional arguments.`, ...@@ -63,11 +63,11 @@ The device UUID and request path must be specified as a positional arguments.`,
Subscription: []*pnd.Subscription{ Subscription: []*pnd.Subscription{
{ {
Path: args[1], Path: args[1],
StreamMode: pnd.StreamMode_STREAM_MODE_TARGET_DEFINED, StreamMode: pnd.StreamMode_STREAM_MODE_SAMPLE,
SampleInterval: 1000000000, SampleInterval: 1000000000,
}, },
}, },
Mode: pnd.SubscriptionMode_SUBSCRIPTION_MODE_ONCE, Mode: pnd.SubscriptionMode_SUBSCRIPTION_MODE_STREAM,
}, },
) )
if err != nil { if err != nil {
......
...@@ -198,7 +198,7 @@ func (g *Gnmi) Subscribe(ctx context.Context, params ...string) error { ...@@ -198,7 +198,7 @@ func (g *Gnmi) Subscribe(ctx context.Context, params ...string) error {
if g.client == nil { if g.client == nil {
return &errors.ErrNilClient{} return &errors.ErrNilClient{}
} }
return g.subscribe(ctx) return g.subscribe2(ctx)
} }
// Type returns the gNMI transport type // Type returns the gNMI transport type
...@@ -330,7 +330,7 @@ func (g *Gnmi) subscribe(ctx context.Context) error { ...@@ -330,7 +330,7 @@ func (g *Gnmi) subscribe(ctx context.Context) error {
} }
// Subscribe calls GNMI subscribe // Subscribe calls GNMI subscribe
func (g *Gnmi) subscribe2(ctx context.Context, stringRespChan chan string) error { func (g *Gnmi) subscribe2(ctx context.Context) error {
ctx = gnmi.NewContext(ctx, g.config) ctx = gnmi.NewContext(ctx, g.config)
opts, ok := ctx.Value(types.CtxKeyOpts).(*gnmi.SubscribeOptions) opts, ok := ctx.Value(types.CtxKeyOpts).(*gnmi.SubscribeOptions)
if !ok { if !ok {
...@@ -339,6 +339,19 @@ func (g *Gnmi) subscribe2(ctx context.Context, stringRespChan chan string) error ...@@ -339,6 +339,19 @@ func (g *Gnmi) subscribe2(ctx context.Context, stringRespChan chan string) error
Type: &gnmi.SubscribeOptions{}, Type: &gnmi.SubscribeOptions{},
} }
} }
stringRespChan := make(chan string)
go func() {
for {
resp := <-stringRespChan
if resp != "" {
log.Info(resp)
} else {
log.Info("recieved empty string")
}
}
}()
go func() { go func() {
log.WithFields(log.Fields{ log.WithFields(log.Fields{
"address": opts.Target, "address": opts.Target,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment