pubsub

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package pubsub provides a pubsub implementation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UUID

func UUID() string

UUID generates uuid.

Types

type Message

type Message struct {
	ID   string
	Data []byte
}

Message represents a Pub/Sub message.

type PubSub

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

PubSub is a Pub/Sub instance for a single project.

func New

func New(project string) *PubSub

New creates a new PubSub.

func (*PubSub) Name

func (p *PubSub) Name() string

Name returns the full name for the PubSub.

func (*PubSub) NewTopic

func (p *PubSub) NewTopic(name string, size int, numGoroutines int) (*Topic, error)

NewTopic creates a new Topic with the given name, size is the channel buffer size for topic message chan, numGoroutines is the number of goroutines it will spawn to push msg concurrently.

func (*PubSub) Topic

func (p *PubSub) Topic(name string) *Topic

Topic returns the topic by name.

func (*PubSub) Topics

func (p *PubSub) Topics() []string

Topics list all the topics in the PubSub.

type PublishError

type PublishError struct {
	Msg *Message
	Err error
}

PublishError is the error generated when it fails to publish a message.

func (PublishError) Error

func (pe PublishError) Error() string

type Subscription

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

Subscription represents a PubSub subscription.

func (*Subscription) Delete

func (s *Subscription) Delete()

Delete unsubscribes itself from topic.

func (*Subscription) Receive

func (s *Subscription) Receive(f func(*Message))

Receive receives message for this subscription.

type Topic

type Topic struct {

	// Errors is the error output channel back to the user. You MUST read from this
	// channel or the Publish will deadlock when the channel is full.
	Errors chan PublishError
	// contains filtered or unexported fields
}

Topic represents a PubSub topic.

func (*Topic) Delete

func (t *Topic) Delete()

Delete removes itself from PubSuband stop it.

func (*Topic) Name

func (t *Topic) Name() string

Name returns the full name for the topic.

func (*Topic) NewSubscription

func (t *Topic) NewSubscription(numGoroutines int) (*Subscription, error)

NewSubscription creates a new Subscription to this topic, numGoroutines is the number of goroutines it will spawn to pull msg concurrently.

func (*Topic) Publish

func (t *Topic) Publish(ctx context.Context, msg *Message) error

Publish publishes msg to the topic asynchronously.

func (*Topic) Stop

func (t *Topic) Stop()

Stop stops the topic.

func (*Topic) Subscription

func (t *Topic) Subscription(name string) *Subscription

Subscription returns the subscription by name..

func (*Topic) Subscriptions

func (t *Topic) Subscriptions() []string

Subscriptions list all the subscriptions to this topic.

Jump to

Keyboard shortcuts

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