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
- func AttributesFrom(ctx context.Context) map[string]string
- func WithCustomAttributes(ctx context.Context, attrs map[string]string) context.Context
- func WithOrderingKey(ctx context.Context, key string) context.Context
- func WritePubSubMessage(ctx context.Context, m binding.Message, pubsubMessage *pubsub.Message, ...) error
- type Message
- func (m *Message) Finish(err error) error
- func (m *Message) GetAttribute(k spec.Kind) (spec.Attribute, interface{})
- func (m *Message) GetExtension(name string) interface{}
- func (m *Message) ReadBinary(ctx context.Context, encoder binding.BinaryWriter) (err error)
- func (m *Message) ReadEncoding() binding.Encoding
- func (m *Message) ReadStructured(ctx context.Context, encoder binding.StructuredWriter) error
- type Option
- func AllowCreateSubscription(allow bool) Option
- func AllowCreateTopic(allow bool) Option
- func WithClient(client *pubsub.Client) Option
- func WithFilter(filter string) Option
- func WithFilterFromEnv(key string) Option
- func WithMessageOrdering() Option
- func WithMessageOrderingFromDefaultEnv() Option
- func WithMessageOrderingFromEnv(key string) Option
- func WithProjectID(projectID string) Option
- func WithProjectIDFromDefaultEnv() Option
- func WithProjectIDFromEnv(key string) Option
- func WithReceiveSettings(rs *pubsub.ReceiveSettings) Option
- func WithSubscriptionAndTopicID(subscriptionID, topicID string) Option
- func WithSubscriptionID(subscriptionID string) Option
- func WithSubscriptionIDAndFilter(subscriptionID, filter string) Option
- func WithSubscriptionIDFromDefaultEnv() Option
- func WithSubscriptionIDFromEnv(key string) Option
- func WithSubscriptionTopicIDAndFilter(subscriptionID, topicID, filter string) Option
- func WithTopicID(topicID string) Option
- func WithTopicIDFromDefaultEnv() Option
- func WithTopicIDFromEnv(key string) Option
- type Protocol
Constants ¶
const ( DefaultProjectEnvKey = "GOOGLE_CLOUD_PROJECT" DefaultTopicEnvKey = "PUBSUB_TOPIC" DefaultSubscriptionEnvKey = "PUBSUB_SUBSCRIPTION" DefaultMessageOrderingEnvKey = "PUBSUB_MESSAGE_ORDERING" )
const (
ProtocolName = "Pub/Sub"
)
Variables ¶
This section is empty.
Functions ¶
func WithCustomAttributes ¶ added in v2.15.0
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
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 ¶
NewMessage returns a binding.Message with data and attributes. This message *can* be read several times safely
func (*Message) Finish ¶
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 (*Message) GetExtension ¶
func (*Message) ReadBinary ¶
func (*Message) ReadEncoding ¶
func (*Message) ReadStructured ¶
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 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 WithFilter ¶ added in v2.7.0
WithFilter sets the subscription filter for pubsub transport.
func WithFilterFromEnv ¶ added in v2.7.0
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
WithMessageOrderingFromEnv enables message ordering for all topics and subscriptions from a given environment variable name.
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 ¶
func WithReceiveSettings(rs *pubsub.ReceiveSettings) Option
WithReceiveSettings sets the Pubsub ReceiveSettings for pull subscriptions.
func WithSubscriptionAndTopicID ¶
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 WithSubscriptionIDAndFilter ¶ added in v2.7.0
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 ¶
WithSubscriptionIDFromEnv sets the subscription ID for pubsub transport from a given environment variable name.
func WithSubscriptionTopicIDAndFilter ¶ added in v2.7.0
WithSubscriptionTopicIDAndFilter sets the subscription with filter option and topic IDs for pubsub transport. This option can be used multiple times.
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 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 .