cloud

package
v0.0.0-...-5352646 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

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

Example
package main

import (
	"context"

	"go.thethings.network/lorawan-stack/pkg/events"
	"go.thethings.network/lorawan-stack/pkg/events/cloud"

	_ "gocloud.dev/pubsub/mempubsub"
)

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

	// This sends all events received from a Go Cloud pub sub to the default pubsub.
	cloudPubSub, err := cloud.WrapPubSub(context.TODO(), events.DefaultPubSub(), "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, 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 WrapPubSub

func WrapPubSub(ctx context.Context, wrapped events.PubSub, pubURL, subURL string) (ps *PubSub, err error)

WrapPubSub wraps an existing PubSub and publishes all events received from Go Cloud to that PubSub. If the subURL is an empty string, this PubSub will only publish to Go Cloud.

func (*PubSub) Close

func (ps *PubSub) Close() (err error)

Close the Go Cloud publisher.

func (*PubSub) Publish

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

Publish an event to Go Cloud.

Jump to

Keyboard shortcuts

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