This repository was archived by the owner on Aug 1, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupstream.go
More file actions
62 lines (56 loc) · 1.62 KB
/
upstream.go
File metadata and controls
62 lines (56 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// SPDX-FileCopyrightText: 2025 Comcast Cable Communications Management, LLC
// SPDX-License-Identifier: Apache-2.0
package main
import (
"context"
"time"
"github.com/xmidt-org/kratos" // nolint:staticcheck
"go.uber.org/fx"
"go.uber.org/zap"
)
func StartUpstreamConnection(config Config, lc fx.Lifecycle, logger *zap.Logger) (kratos.Client, error) {
queueConfig := kratos.QueueConfig{
MaxWorkers: 5,
Size: 100,
}
client, err := kratos.NewClient(kratos.ClientConfig{
DeviceName: config.DeviceID,
FirmwareName: config.FirmwareName,
ModelName: config.HardwareModel,
Manufacturer: config.HardwareManufacturer,
DestinationURL: config.URL,
OutboundQueue: queueConfig,
WRPEncoderQueue: queueConfig,
WRPDecoderQueue: queueConfig,
HandlerRegistryQueue: queueConfig,
HandleMsgQueue: queueConfig,
Handlers: []kratos.HandlerConfig{},
HandlePingMiss: func() error {
logger.Error("msg", zap.Any("error", "Ping Miss"))
// TODO: handle reconnect
return nil
},
ClientLogger: logger,
PingConfig: kratos.PingConfig{
PingWait: time.Second * time.Duration(config.PingTimeout),
MaxPingMiss: 3,
},
})
if err != nil {
logger.Error("failed to create client", zap.Error(err))
if client != nil {
closeErr := client.Close()
logger.Info("failed to close bad client", zap.Error(closeErr))
}
}
logger.Info("kratos client created")
lc.Append(fx.Hook{
OnStart: func(context context.Context) error {
return nil
},
OnStop: func(context context.Context) error {
return client.Close()
},
})
return client, nil
}