cloud

package
v0.0.0-...-60b8695 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package cloud implements an events.PubSub implementation that uses Go Cloud PubSub.

Example
package main

import (
	"context"

	"github.com/aureliar8/ttn-fork/pkg/component"
	"github.com/aureliar8/ttn-fork/pkg/events"
	"github.com/aureliar8/ttn-fork/pkg/events/cloud"

	_ "gocloud.dev/pubsub/mempubsub"
)

func main() {
	// The task starter is used for automatic re-subscription on failure.
	taskStarter := component.StartTaskFunc(component.DefaultStartTask)

	// Import the desired cloud pub-sub drivers (see godoc.org/gocloud.dev).
	// In this example we use "gocloud.dev/pubsub/mempubsub".

	cloudPubSub, err := cloud.NewPubSub(context.TODO(), taskStarter, "mem://events", "mem://events")
	if err != nil {
		// Handle error.
	}

	// Replace the default pubsub so that we will now publish to a Go Cloud pub sub.
	events.SetDefaultPubSub(cloudPubSub)
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PubSub

type PubSub struct {
	events.PubSub
	// contains filtered or unexported fields
}

PubSub with Go Cloud backend.

func NewPubSub

func NewPubSub(ctx context.Context, taskStarter component.TaskStarter, pubURL, subURL string) (*PubSub, error)

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.

func (*PubSub) Close

func (ps *PubSub) Close(ctx context.Context) error

Close the Go Cloud publisher.

func (*PubSub) Publish

func (ps *PubSub) Publish(evt events.Event)

Publish an event to Go Cloud.

func (*PubSub) Subscribe

func (ps *PubSub) Subscribe(ctx context.Context, name string, ids []*ttnpb.EntityIdentifiers, hdl events.Handler) error

Subscribe to events from Go Cloud.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL