pubsub

package module
v2.15.2 Latest Latest
Warning

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

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

Documentation

Overview

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

PubSub Messages can be modified beyond what CloudEvents cover by using `WithOrderingKey` or `WithCustomAttributes`. See function docs for more details.

Index

Constants

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

Variables

This section is empty.

Functions

func AttributesFrom added in v2.15.0

func AttributesFrom(ctx context.Context) map[string]string

func WithCustomAttributes added in v2.15.0

func WithCustomAttributes(ctx context.Context, attrs map[string]string) context.Context

WithCustomAttributes sets Message Attributes without any CloudEvent logic. Note that this function is not intended for CloudEvent Extensions or any `ce-`-prefixed Attributes. For these please see `Event` and `Event.SetExtension`.

func WithOrderingKey added in v2.7.0

func WithOrderingKey(ctx context.Context, key string) context.Context

WithOrderingKey allows to set the Pub/Sub ordering key for publishing events.

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 Pubsub message will be acked; otherwise nacked and return the error.

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 WithFilter added in v2.7.0

func WithFilter(filter string) Option

WithFilter sets the subscription filter for pubsub transport.

func WithFilterFromEnv added in v2.7.0

func WithFilterFromEnv(key string) Option

WithFilterFromEnv sets the subscription filter for pubsub transport from a given environment variable name.

func WithMessageOrdering added in v2.7.0

func WithMessageOrdering() Option

WithMessageOrdering enables message ordering for all topics and subscriptions.

func WithMessageOrderingFromDefaultEnv added in v2.7.0

func WithMessageOrderingFromDefaultEnv() Option

WithMessageOrderingFromDefaultEnv enables message ordering for all topics and subscriptions from the environment variable named 'PUBSUB_MESSAGE_ORDERING'.

func WithMessageOrderingFromEnv added in v2.7.0

func WithMessageOrderingFromEnv(key string) Option

WithMessageOrderingFromEnv enables message ordering for all topics and subscriptions from a given environment variable name.

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 WithSubscriptionIDAndFilter added in v2.7.0

func WithSubscriptionIDAndFilter(subscriptionID, filter string) Option

WithSubscriptionIDAndFilter sets the subscription and topic IDs 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 WithSubscriptionTopicIDAndFilter added in v2.7.0

func WithSubscriptionTopicIDAndFilter(subscriptionID, topicID, filter string) Option

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

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

	// MessageOrdering enables message ordering for all topics and subscriptions.
	MessageOrdering 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