pubsub

package module
v0.0.0-...-3401ade Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: Apache-2.0 Imports: 16 Imported by: 4

Documentation

Overview

Package pubsub implements a Pub/Sub binding using google.cloud.com/go/pubsub module

Index

Constants

View Source
const (
	DefaultProjectEnvKey      = "GOOGLE_CLOUD_PROJECT"
	DefaultTopicEnvKey        = "PUBSUB_TOPIC"
	DefaultSubscriptionEnvKey = "PUBSUB_SUBSCRIPTION"
)
View Source
const (
	ProtocolName = "Pub/Sub"
)

Variables

This section is empty.

Functions

func WritePubSubMessage

func WritePubSubMessage(ctx context.Context, m binding.Message, pubsubMessage *pubsub.Message, transformers ...binding.Transformer) error

WritePubSubMessage fills the provided pubsubMessage with the message m. Using context you can tweak the encoding processing (more details on binding.Write documentation).

Types

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message represents a Pub/Sub message. This message *can* be read several times safely

func NewMessage

func NewMessage(pm *pubsub.Message) *Message

NewMessage returns a binding.Message with data and attributes. This message *can* be read several times safely

func (*Message) Finish

func (m *Message) Finish(err error) error

Finish marks the message to be forgotten. If err is nil, the underlying Psubsub message will be acked; otherwise nacked.

func (*Message) GetAttribute

func (m *Message) GetAttribute(k spec.Kind) (spec.Attribute, interface{})

func (*Message) GetExtension

func (m *Message) GetExtension(name string) interface{}

func (*Message) ReadBinary

func (m *Message) ReadBinary(ctx context.Context, encoder binding.BinaryWriter) (err error)

func (*Message) ReadEncoding

func (m *Message) ReadEncoding() binding.Encoding

func (*Message) ReadStructured

func (m *Message) ReadStructured(ctx context.Context, encoder binding.StructuredWriter) error

type Option

type Option func(*Protocol) 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 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 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

func WithReceiveSettings(rs *pubsub.ReceiveSettings) Option

WithReceiveSettings sets the Pubsub ReceiveSettings for pull subscriptions.

func WithSubscriptionAndTopicID

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 Protocol

type Protocol struct {

	// 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
	// contains filtered or unexported fields
}

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

func New

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

New creates a new pubsub transport.

func (*Protocol) Close

func (t *Protocol) Close(ctx context.Context) error

Close implements Closer.Close

func (*Protocol) OpenInbound

func (t *Protocol) OpenInbound(ctx context.Context) error

func (*Protocol) Receive

func (t *Protocol) Receive(ctx context.Context) (binding.Message, error)

Receive implements Receiver.Receive

func (*Protocol) Send

func (t *Protocol) Send(ctx context.Context, in binding.Message, transformers ...binding.Transformer) error

Send implements Sender.Send

Directories

Path Synopsis
Package context provides the pubsub ProtocolContext.
Package context provides the pubsub ProtocolContext.
Package internal provides the internal pubsub Connection type.
Package internal provides the internal pubsub Connection type.

Jump to

Keyboard shortcuts

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