pubsub

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2020 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Overview

Package pubsub implements the CloudEvent transport implementation using pubsub.

Index

Constants

View Source
const (
	DefaultProjectEnvKey      = "GOOGLE_CLOUD_PROJECT"
	DefaultTopicEnvKey        = "PUBSUB_TOPIC"
	DefaultSubscriptionEnvKey = "PUBSUB_SUBSCRIPTION"
)
View Source
const (
	StructuredContentType = "Content-Type"
)
View Source
const (
	TransportName = "Pub/Sub"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Codec

type Codec struct {
	Encoding Encoding

	// DefaultEncodingSelectionFn allows for encoding selection strategies to be injected.
	DefaultEncodingSelectionFn EncodingSelector
	// contains filtered or unexported fields
}

func (*Codec) Decode

func (c *Codec) Decode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error)

func (*Codec) Encode

type CodecStructured

type CodecStructured struct {
	Encoding Encoding
}

CodecStructured represents an structured http transport codec for all versions. Intended to be used as a base class.

type CodecV03

type CodecV03 struct {
	CodecStructured

	DefaultEncoding Encoding
}

func (CodecV03) Decode

func (CodecV03) Encode

type CodecV1 added in v0.10.0

type CodecV1 struct {
	CodecStructured

	DefaultEncoding Encoding
}

func (CodecV1) Decode added in v0.10.0

func (v CodecV1) Decode(ctx context.Context, msg transport.Message) (*cloudevents.Event, error)

func (CodecV1) Encode added in v0.10.0

type Encoding

type Encoding int32

Encoding to use for pubsub transport.

const (
	// Default allows pubsub transport implementation to pick.
	Default Encoding = iota
	// BinaryV03 is Binary CloudEvents spec v0.3.
	BinaryV03
	// BinaryV1 is Binary CloudEvents spec v1.0.
	BinaryV1
	// StructuredV03 is Structured CloudEvents spec v0.3.
	StructuredV03
	// StructuredV1 is Structured CloudEvents spec v1.0.
	StructuredV1

	// Unknown is unknown.
	Unknown

	// Binary is used for Context Based Encoding Selections to use the
	// DefaultBinaryEncodingSelectionStrategy
	Binary = "binary"

	// Structured is used for Context Based Encoding Selections to use the
	// DefaultStructuredEncodingSelectionStrategy
	Structured = "structured"
)

func DefaultBinaryEncodingSelectionStrategy

func DefaultBinaryEncodingSelectionStrategy(ctx context.Context, e cloudevents.Event) Encoding

DefaultBinaryEncodingSelectionStrategy implements a selection process for which binary encoding to use based on spec version of the event.

func DefaultStructuredEncodingSelectionStrategy

func DefaultStructuredEncodingSelectionStrategy(ctx context.Context, e cloudevents.Event) Encoding

DefaultStructuredEncodingSelectionStrategy implements a selection process for which structured encoding to use based on spec version of the event.

func (Encoding) Name added in v0.10.2

func (e Encoding) Name() string

Name creates a string to represent the the codec name.

func (Encoding) String

func (e Encoding) String() string

String pretty-prints the encoding as a string.

func (Encoding) Version

func (e Encoding) Version() string

Version pretty-prints the encoding version as a string.

type EncodingSelector

type EncodingSelector func(context.Context, cloudevents.Event) Encoding

type Message

type Message struct {
	// Data is the actual data in the message.
	Data []byte

	// Attributes represents the key-value pairs the current message
	// is labelled with.
	Attributes map[string]string
}

Message represents a Pub/Sub message.

func (Message) CloudEventsVersion

func (m Message) CloudEventsVersion() string

type Option

type Option func(*Transport) error

Option is the function signature required to be considered an pubsub.Option.

func AllowCreateSubscription

func AllowCreateSubscription(allow bool) Option

AllowCreateSubscription sets if the transport can create a subscription if it does not exist.

func AllowCreateTopic

func AllowCreateTopic(allow bool) Option

AllowCreateTopic sets if the transport can create a topic if it does not exist.

func WithBinaryEncoding

func WithBinaryEncoding() Option

WithBinaryEncoding sets the encoding selection strategy for default encoding selections based on Event, the encoded event will be the given version in Binary form.

func WithClient

func WithClient(client *pubsub.Client) Option

WithClient sets the pubsub client for pubsub transport. Use this for explicit auth setup. Otherwise the env var 'GOOGLE_APPLICATION_CREDENTIALS' is used. See https://cloud.google.com/docs/authentication/production for more details.

func WithDefaultEncodingSelector

func WithDefaultEncodingSelector(fn EncodingSelector) Option

WithDefaultEncodingSelector sets the encoding selection strategy for default encoding selections based on Event.

func WithEncoding

func WithEncoding(encoding Encoding) Option

WithEncoding sets the encoding for pubsub transport.

func WithProjectID

func WithProjectID(projectID string) Option

WithProjectID sets the project ID for pubsub transport.

func WithProjectIDFromDefaultEnv

func WithProjectIDFromDefaultEnv() Option

WithProjectIDFromDefaultEnv sets the project ID for pubsub transport from the environment variable named 'GOOGLE_CLOUD_PROJECT'.

func WithProjectIDFromEnv

func WithProjectIDFromEnv(key string) Option

WithProjectIDFromEnv sets the project ID for pubsub transport from a given environment variable name.

func WithReceiveSettings added in v0.11.0

func WithReceiveSettings(rs *pubsub.ReceiveSettings) Option

WithReceiveSettings sets the Pubsub ReceiveSettings for pull subscriptions.

func WithStructuredEncoding

func WithStructuredEncoding() Option

WithStructuredEncoding sets the encoding selection strategy for default encoding selections based on Event, the encoded event will be the given version in Structured form.

func WithSubscriptionAndTopicID added in v0.10.0

func WithSubscriptionAndTopicID(subscriptionID, topicID string) Option

WithSubscriptionAndTopicID sets the subscription and topic IDs for pubsub transport. This option can be used multiple times.

func WithSubscriptionID

func WithSubscriptionID(subscriptionID string) Option

WithSubscriptionID sets the subscription ID for pubsub transport. This option can be used multiple times.

func WithSubscriptionIDFromDefaultEnv

func WithSubscriptionIDFromDefaultEnv() Option

WithSubscriptionIDFromDefaultEnv sets the subscription ID for pubsub transport from the environment variable named 'PUBSUB_SUBSCRIPTION'.

func WithSubscriptionIDFromEnv

func WithSubscriptionIDFromEnv(key string) Option

WithSubscriptionIDFromEnv sets the subscription ID for pubsub transport from a given environment variable name.

func WithTopicID

func WithTopicID(topicID string) Option

WithTopicID sets the topic ID for pubsub transport.

func WithTopicIDFromDefaultEnv

func WithTopicIDFromDefaultEnv() Option

WithTopicIDFromDefaultEnv sets the topic ID for pubsub transport from the environment variable named 'PUBSUB_TOPIC'.

func WithTopicIDFromEnv

func WithTopicIDFromEnv(key string) Option

WithTopicIDFromEnv sets the topic ID for pubsub transport from a given environment variable name.

type Transport

type Transport struct {
	// Encoding
	Encoding Encoding

	// DefaultEncodingSelectionFn allows for other encoding selection strategies to be injected.
	DefaultEncodingSelectionFn EncodingSelector

	// ReceiveSettings is used to configure Pubsub pull subscription.
	ReceiveSettings *pubsub.ReceiveSettings

	// AllowCreateTopic controls if the transport can create a topic if it does
	// not exist.
	AllowCreateTopic bool

	// AllowCreateSubscription controls if the transport can create a
	// subscription if it does not exist.
	AllowCreateSubscription bool

	// Receiver
	Receiver transport.Receiver

	// Converter is invoked if the incoming transport receives an undecodable
	// message.
	Converter transport.Converter
	// contains filtered or unexported fields
}

Transport acts as both a pubsub topic and a pubsub subscription .

func New

func New(ctx context.Context, opts ...Option) (*Transport, error)

New creates a new pubsub transport.

func (*Transport) HasConverter

func (t *Transport) HasConverter() bool

HasConverter implements Transport.HasConverter

func (*Transport) HasTracePropagation added in v1.1.0

func (t *Transport) HasTracePropagation() bool

HasTracePropagation implements Transport.HasTracePropagation

func (*Transport) Send

Send implements Transport.Send

func (*Transport) SetConverter

func (t *Transport) SetConverter(c transport.Converter)

SetConverter implements Transport.SetConverter

func (*Transport) SetReceiver

func (t *Transport) SetReceiver(r transport.Receiver)

SetReceiver implements Transport.SetReceiver

func (*Transport) StartReceiver

func (t *Transport) StartReceiver(ctx context.Context) error

StartReceiver implements Transport.StartReceiver NOTE: This is a blocking call.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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