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

Function NewPubSub

pkg/events/cloud/cloud.go:36–53  ·  view source on GitHub ↗

NewPubSub creates a new PubSub that publishes and subscribes to Go Cloud. If the subURL is an empty string, this PubSub will only publish to Go Cloud.

(ctx context.Context, taskStarter task.Starter, pubURL, subURL string)

Source from the content-addressed store, hash-verified

34// NewPubSub creates a new PubSub that publishes and subscribes to Go Cloud.
35// If the subURL is an empty string, this PubSub will only publish to Go Cloud.
36func NewPubSub(ctx context.Context, taskStarter task.Starter, pubURL, subURL string) (*PubSub, error) {
37 ctx = log.NewContextWithField(ctx, "namespace", "events/cloud")
38 ctx, cancel := context.WithCancel(ctx)
39 ps := &PubSub{
40 PubSub: basic.NewPubSub(),
41 taskStarter: taskStarter,
42 ctx: ctx,
43 cancel: cancel,
44 contentType: "application/protobuf",
45 subURL: subURL,
46 }
47 var err error
48 ps.topic, err = pubsub.OpenTopic(ctx, pubURL)
49 if err != nil {
50 return nil, err
51 }
52 return ps, nil
53}
54
55// PubSub with Go Cloud backend.
56type PubSub struct {

Callers 3

ExampleFunction · 0.92
TestCloudPubSubFunction · 0.92
InitializeEventsFunction · 0.92

Calls 2

NewContextWithFieldFunction · 0.92
NewPubSubFunction · 0.92

Tested by 2

ExampleFunction · 0.74
TestCloudPubSubFunction · 0.74