From 3c338ffe1aaaeb89716048967c2c93fc951cd552 Mon Sep 17 00:00:00 2001 From: Malte Bauch <malte.bauch@extern.h-da.de> Date: Wed, 6 Jul 2022 18:37:15 +0200 Subject: [PATCH] WIP: added goroutine to catch subscribe channel output --- cli/cmd/deviceSubscribe.go | 4 ++-- controller/nucleus/gnmi_transport.go | 17 +++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/cli/cmd/deviceSubscribe.go b/cli/cmd/deviceSubscribe.go index baa3a86f2..dbe2e5c9e 100644 --- a/cli/cmd/deviceSubscribe.go +++ b/cli/cmd/deviceSubscribe.go @@ -63,11 +63,11 @@ The device UUID and request path must be specified as a positional arguments.`, Subscription: []*pnd.Subscription{ { Path: args[1], - StreamMode: pnd.StreamMode_STREAM_MODE_TARGET_DEFINED, + StreamMode: pnd.StreamMode_STREAM_MODE_SAMPLE, SampleInterval: 1000000000, }, }, - Mode: pnd.SubscriptionMode_SUBSCRIPTION_MODE_ONCE, + Mode: pnd.SubscriptionMode_SUBSCRIPTION_MODE_STREAM, }, ) if err != nil { diff --git a/controller/nucleus/gnmi_transport.go b/controller/nucleus/gnmi_transport.go index 8b8e5a2c3..5e7e2e145 100644 --- a/controller/nucleus/gnmi_transport.go +++ b/controller/nucleus/gnmi_transport.go @@ -198,7 +198,7 @@ func (g *Gnmi) Subscribe(ctx context.Context, params ...string) error { if g.client == nil { return &errors.ErrNilClient{} } - return g.subscribe(ctx) + return g.subscribe2(ctx) } // Type returns the gNMI transport type @@ -330,7 +330,7 @@ func (g *Gnmi) subscribe(ctx context.Context) error { } // 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) opts, ok := ctx.Value(types.CtxKeyOpts).(*gnmi.SubscribeOptions) if !ok { @@ -339,6 +339,19 @@ func (g *Gnmi) subscribe2(ctx context.Context, stringRespChan chan string) error 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() { log.WithFields(log.Fields{ "address": opts.Target, -- GitLab