MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / InitializeEvents

Function InitializeEvents

cmd/internal/shared/events.go:47–78  ·  view source on GitHub ↗

InitializeEvents initializes the event system.

(ctx context.Context, component Component, conf config.ServiceBase)

Source from the content-addressed store, hash-verified

45
46// InitializeEvents initializes the event system.
47func InitializeEvents(ctx context.Context, component Component, conf config.ServiceBase) error {
48 var ps events.PubSub
49 switch conf.Events.Backend {
50 case "internal":
51 ps = basic.NewPubSub()
52 case "redis":
53 ps = redis.NewPubSub(ctx, component, conf.Events.Redis, conf.Events.Batch)
54 case "cloud":
55 cloudPS, err := cloud.NewPubSub(ctx, component, conf.Events.Cloud.PublishURL, conf.Events.Cloud.SubscribeURL)
56 if err != nil {
57 return err
58 }
59 ps = cloudPS
60 default:
61 return fmt.Errorf("unknown events backend: %s", conf.Events.Backend)
62 }
63
64 var extraStreams []mux.Option
65 if conf.TTGC.Enabled {
66 matcher, err := mux.MatchPatterns(managedclient.EventNamePattern)
67 if err != nil {
68 return err
69 }
70 extraStreams = append(extraStreams, mux.WithStream(managedclient.NewEvents(component), matcher))
71 }
72
73 if len(extraStreams) > 0 {
74 ps = mux.New(component, ps, extraStreams...)
75 }
76 events.SetDefaultPubSub(ps)
77 return nil
78}

Callers 1

start.goFile · 0.92

Calls 8

NewPubSubFunction · 0.92
NewPubSubFunction · 0.92
NewPubSubFunction · 0.92
MatchPatternsFunction · 0.92
WithStreamFunction · 0.92
NewFunction · 0.92
SetDefaultPubSubFunction · 0.92
ErrorfMethod · 0.65

Tested by

no test coverage detected