pubsub

package module
Version: v0.0.0-...-1fdb7e3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2022 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package pubsub provides a Google PubSub abstraction.

Example
package main

import (
	"context"

	"github.com/bsm/bps"
	_ "github.com/bsm/bps/pubsub"
)

func main() {
	ctx := context.TODO()
	pub, err := bps.NewPublisher(ctx, "pubsub://my-project-id/")
	if err != nil {
		panic(err.Error())
	}
	defer pub.Close()

	if err := pub.Topic("topic").Publish(ctx, &bps.PubMessage{Data: []byte("message")}); err != nil {
		panic(err.Error())
	}
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PubTopic

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

PubTopic wraps a pubsub topic.

func (*PubTopic) Publish

func (t *PubTopic) Publish(ctx context.Context, msg *bps.PubMessage) error

Publish implements the bps.Topic interface.

func (*PubTopic) Topic

func (t *PubTopic) Topic() *native.Topic

Topic returns the native pubsub Topic. Use at your own risk!

type Publisher

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

Publisher wraps a google pubsub client and implements the bps.Publisher interface.

func NewPublisher

func NewPublisher(ctx context.Context, projectID string, settings *native.PublishSettings, opts ...option.ClientOption) (*Publisher, error)

NewPublisher inits a publisher.

func (*Publisher) Client

func (p *Publisher) Client() *native.Client

Client exposes the native client. Use at your own risk!

func (*Publisher) Close

func (p *Publisher) Close() error

Close implements the bps.Publisher interface.

func (*Publisher) Topic

func (p *Publisher) Topic(name string) bps.PubTopic

Topic implements the bps.Publisher interface.

type Subscriber

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

Subscriber is a Google PubSub wrapper that implements bps.Subscriber interface.

func NewSubscriber

func NewSubscriber(ctx context.Context, projectID string) (*Subscriber, error)

NewSubscriber inits a subscriber. It starts handling from the newest available message (published after subscribing). Google PubSub may re-deliver successfully handled messages.

func (*Subscriber) Close

func (s *Subscriber) Close() error

Close closes the client.

func (*Subscriber) Topic

func (s *Subscriber) Topic(name string) bps.SubTopic

Topic returns a subcriber topic handle.

Source Files

Jump to

Keyboard shortcuts

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