Documentation ¶
Overview ¶
Package gcp contains an implementation of ship.Publisher and ship.Subscriber interface.
Index ¶
- type Option
- type PubSub
- func (p *PubSub) EnsureTopics(topics ...string) error
- func (p *PubSub) Publish(topic string, message *ship.Message) error
- func (p *PubSub) PublishRaw(topic string, message *ship.RawMessage) error
- func (p *PubSub) Stop() error
- func (p *PubSub) Subscribe(subscription string, handler ship.MessageHandler) error
- func (p *PubSub) SubscribeRaw(subscription string, handler ship.RawMessageHandler) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
Option is an option setter used to configure creation.
func WithCreateSubscription ¶
WithCreateSubscription toggle subscription creation if it does not exists.
func WithCreateTopic ¶
WithCreateTopic toggle topic creation if it does not exists.
func WithEndpoint ¶
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.
type PubSub ¶
type PubSub struct {
// contains filtered or unexported fields
}
PubSub is a wrapper over GCP PubSub.
func NewClient ¶
NewClient creates an instance of GCP PubSub. All methods are thread-safe until mentioned specifically.
func (*PubSub) EnsureTopics ¶
EnsureTopics checks whether a topic exists or not.
If createTopic is `true` it will create the 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) 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)