gcp

package
v0.0.0-...-2cbf6af Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Publisher

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

Publisher publishes a message on a Google Cloud Pub/Sub topic.

For more info on how Google Cloud Pub/Sub Publisher work, check https://cloud.google.com/pubsub/docs/publisher.

func NewPublisher

func NewPublisher(client *gcppubsub.Client) (*Publisher, error)

NewPublisher create a new GCP publisher.

It required a call to Close in order to stop processing messages and close topic connections.

func (*Publisher) Close

func (p *Publisher) Close() error

Close notifies the Publisher to stop processing messages, send all the remaining messages and close the connection.

func (*Publisher) Publish

func (p *Publisher) Publish(ctx context.Context, topic string, msg pubsub.Message) error

Publish publishes a message on a Google Cloud Pub/Sub topic. It blocks until the message is successfully published or an error occurred.

To receive messages published to a topic, you must create a subscription to that topic. Only messages published to the topic after the subscription is created are available to subscriber applications.

See https://cloud.google.com/pubsub/docs/publisher to find out more about how Google Cloud Pub/Sub Publishers work.

type Subscriber

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

Subscriber attaches to a Google Cloud Pub/Sub subscription and returns a Go channel with messages from the topic. Be aware that in Google Cloud Pub/Sub, only messages sent after the subscription was created can be consumed.

For more info on how Google Cloud Pub/Sub Subscribers work, check https://cloud.google.com/pubsub/docs/subscriber.

func NewSubscriber

func NewSubscriber(client *gcppubsub.Client, opts ...SubscriberOption) (*Subscriber, error)

NewSubscriber creates a new GCP PubSub Subscriber.

it required a call to Close in order to stop processing messages and close subscriber connections.

func (*Subscriber) Close

func (s *Subscriber) Close() error

Close notifies the Subscriber to stop processing messages on all subscriptions, and terminate the connection.

func (*Subscriber) Subscribe

func (s *Subscriber) Subscribe(ctx context.Context, subscription string, handler pubsub.Handler) error

Subscribe consumes Google Cloud Pub/Sub.

In Google Cloud Pub/Sub, it is impossible to subscribe directly to a topic. Instead, a *subscription* is used. Each subscription has one topic, but there may be multiple subscriptions to one topic (with different names).

Be aware that in Google Cloud Pub/Sub, only messages sent after the subscription was created can be consumed.

See https://cloud.google.com/pubsub/docs/subscriber to find out more about how Google Cloud Pub/Sub Subscriptions work.

func (*Subscriber) SubscribeWithAck

func (s *Subscriber) SubscribeWithAck(ctx context.Context, subscription string, handler pubsub.HandlerWithAck) error

type SubscriberOption

type SubscriberOption func(*gcppubsub.ReceiveSettings)

SubscriberOption defines a Subscriber option.

func WithMaxExtension

func WithMaxExtension(d time.Duration) SubscriberOption

WithMaxExtension defines the maximum period for which the Subscription should automatically extend the ack deadline for each message.

The Subscription will automatically extend the ack deadline of all fetched Messages up to the duration specified. Automatic deadline extension beyond the initial receipt may be disabled by specifying a duration less than 0.

func WithMaxExtensionPeriod

func WithMaxExtensionPeriod(d time.Duration) SubscriberOption

WithMaxExtensionPeriod defines the maximum duration by which to extend the ack deadline at a time. The ack deadline will continue to be extended by up to this duration until MaxExtension is reached. Setting MaxExtensionPeriod bounds the maximum amount of time before a message redelivery in the event the subscriber fails to extend the deadline.

MaxExtensionPeriod must be between 10s and 600s (inclusive). This configuration can be disabled by specifying a duration less than (or equal to) 0.

func WithMaxOutstandingBytes

func WithMaxOutstandingBytes(n int) SubscriberOption

WithMaxOutstandingBytes defines the maximum size of unprocessed messages (unacknowledged but not yet expired). If MaxOutstandingBytes is 0, it will be treated as if it were DefaultReceiveSettings.MaxOutstandingBytes. If the value is negative, then there will be no limit on the number of bytes for unprocessed messages.

func WithMaxOutstandingMessages

func WithMaxOutstandingMessages(n int) SubscriberOption

WithMaxOutstandingMessages defines the maximum number of unprocessed messages (unacknowledged but not yet expired). If MaxOutstandingMessages is 0, it will be treated as if it were DefaultReceiveSettings.MaxOutstandingMessages. If the value is negative, then there will be no limit on the number of unprocessed messages.

func WithMinExtensionPeriod

func WithMinExtensionPeriod(d time.Duration) SubscriberOption

WithMinExtensionPeriod defines the min duration for a single lease extension attempt. By default the 99th percentile of ack latency is used to determine lease extension periods but this value can be set to minimize the number of extraneous RPCs sent.

MinExtensionPeriod must be between 10s and 600s (inclusive). This configuration can be disabled by specifying a duration less than (or equal to) 0. Defaults to off but set to 60 seconds if the subscription has exactly-once delivery enabled, which will be added in a future release.

func WithNumGoroutines

func WithNumGoroutines(n int) SubscriberOption

WithNumGoroutines defines the number of goroutines that each datastructure along the Receive path will spawn. Adjusting this value adjusts concurrency along the receive path.

NumGoroutines defaults 10.

NumGoroutines does not limit the number of messages that can be processed concurrently. Even with one goroutine, many messages might be processed at once, because that goroutine may continually receive messages and invoke the function passed to Receive on them. To limit the number of messages being processed concurrently, set MaxOutstandingMessages.

Jump to

Keyboard shortcuts

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