gcp

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package gcp contains an implementation of ship.Publisher and ship.Subscriber interface.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*PubSub) error

Option is an option setter used to configure creation.

func WithCreateSubscription

func WithCreateSubscription(create bool) Option

WithCreateSubscription toggle subscription creation if it does not exists.

func WithCreateTopic

func WithCreateTopic(create bool) Option

WithCreateTopic toggle topic creation if it does not exists.

func WithEndpoint

func WithEndpoint(endpoint string) Option

WithEndpoint changes the pubsub endpoint.

func WithGRPCConn

func WithGRPCConn(conn *grpc.ClientConn) Option

WithGRPCConn uses the provided connection instead of the default one. This function is useful for connecting with mock server.

func WithLogger

func WithLogger(logger *zap.Logger) Option

WithLogger attaches a zap logger.

type PubSub

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

PubSub is a wrapper over GCP PubSub.

func NewClient

func NewClient(
	projectID string, options ...Option,
) (*PubSub, error)

NewClient creates an instance of GCP PubSub. All methods are thread-safe until mentioned specifically.

func (*PubSub) EnsureTopics

func (p *PubSub) EnsureTopics(topics ...string) error

EnsureTopics checks whether a topic exists or not.

If createTopic is `true` it will create the topic.

func (*PubSub) Publish

func (p *PubSub) Publish(topic string, message *ship.Message) error

Publish publishes the message to a given topic.

func (*PubSub) PublishRaw added in v0.3.1

func (p *PubSub) PublishRaw(topic string, message *ship.RawMessage) error

PublishRaw publishes the message to a given topic.

func (*PubSub) Stop

func (p *PubSub) Stop() error

Stop stops the pubsub gracefully.

func (*PubSub) Subscribe

func (p *PubSub) Subscribe(
	subscription string, handler ship.MessageHandler,
) error

Subscribe subscribes a handler to a given subscription. It stops receiving message in case of, panics.

It is a non-blocking call. NOTE: to stop the subscriptions. Call Stop method.

Example:

pubsub, err := New("projectID")
if err != nil {
	// do something with error
	return
}

pubsub.Subscribe("some-subscription-name", handler)
pubsub.Subscribe("some-subscription-name2", handler2)
pubsub.Subscribe("some-subscription-name3", handler3)

func (*PubSub) SubscribeRaw added in v0.2.0

func (p *PubSub) SubscribeRaw(
	subscription string, handler ship.RawMessageHandler,
) error

SubscribeRaw subscribes a handler to a given subscription. It stops receiving message in case of, panics.

It is a non-blocking call. NOTE: to stop the subscriptions. Call Stop method.

Example:

pubsub, err := New("projectID")
if err != nil {
	// do something with error
	return
}

pubsub.Subscribe("some-subscription-name", handler)
pubsub.Subscribe("some-subscription-name2", handler2)
pubsub.Subscribe("some-subscription-name3", handler3)

Jump to

Keyboard shortcuts

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