Documentation ¶
Overview ¶
Package pubsub implements the CloudEvent transport implementation using pubsub.
Index ¶
- Constants
- type Codec
- type CodecStructured
- type CodecV03
- type CodecV1
- type Encoding
- type EncodingSelector
- type Message
- type Option
- func AllowCreateSubscription(allow bool) Option
- func AllowCreateTopic(allow bool) Option
- func WithBinaryEncoding() Option
- func WithClient(client *pubsub.Client) Option
- func WithDefaultEncodingSelector(fn EncodingSelector) Option
- func WithEncoding(encoding Encoding) Option
- func WithProjectID(projectID string) Option
- func WithProjectIDFromDefaultEnv() Option
- func WithProjectIDFromEnv(key string) Option
- func WithReceiveSettings(rs *pubsub.ReceiveSettings) Option
- func WithStructuredEncoding() Option
- func WithSubscriptionAndTopicID(subscriptionID, topicID string) Option
- func WithSubscriptionID(subscriptionID string) Option
- func WithSubscriptionIDFromDefaultEnv() Option
- func WithSubscriptionIDFromEnv(key string) Option
- func WithTopicID(topicID string) Option
- func WithTopicIDFromDefaultEnv() Option
- func WithTopicIDFromEnv(key string) Option
- type Transport
- func (t *Transport) HasConverter() bool
- func (t *Transport) HasTracePropagation() bool
- func (t *Transport) Send(ctx context.Context, event cloudevents.Event) (context.Context, *cloudevents.Event, error)
- func (t *Transport) SetConverter(c transport.Converter)
- func (t *Transport) SetReceiver(r transport.Receiver)
- func (t *Transport) StartReceiver(ctx context.Context) error
Constants ¶
const ( DefaultProjectEnvKey = "GOOGLE_CLOUD_PROJECT" DefaultTopicEnvKey = "PUBSUB_TOPIC" DefaultSubscriptionEnvKey = "PUBSUB_SUBSCRIPTION" )
const (
StructuredContentType = "Content-Type"
)
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 }
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 }
type CodecV1 ¶ added in v0.10.0
type CodecV1 struct { CodecStructured DefaultEncoding Encoding }
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.
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 ¶
type Option ¶
Option is the function signature required to be considered an pubsub.Option.
func AllowCreateSubscription ¶
AllowCreateSubscription sets if the transport can create a subscription if it does not exist.
func AllowCreateTopic ¶
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 ¶
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 ¶
WithEncoding sets the encoding for pubsub transport.
func WithProjectID ¶
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 ¶
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
WithSubscriptionAndTopicID sets the subscription and topic IDs for pubsub transport. This option can be used multiple times.
func WithSubscriptionID ¶
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 ¶
WithSubscriptionIDFromEnv sets the subscription ID for pubsub transport from a given environment variable name.
func WithTopicID ¶
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 ¶
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 (*Transport) HasConverter ¶
HasConverter implements Transport.HasConverter
func (*Transport) HasTracePropagation ¶ added in v1.1.0
HasTracePropagation implements Transport.HasTracePropagation
func (*Transport) Send ¶
func (t *Transport) Send(ctx context.Context, event cloudevents.Event) (context.Context, *cloudevents.Event, error)
Send implements Transport.Send
func (*Transport) SetConverter ¶
SetConverter implements Transport.SetConverter
func (*Transport) SetReceiver ¶
SetReceiver implements Transport.SetReceiver