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)
| 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. |
| 36 | func 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. |
| 56 | type PubSub struct { |