Skip to content

Latest commit

 

History

History
285 lines (154 loc) · 6.06 KB

pubsub.md

File metadata and controls

285 lines (154 loc) · 6.06 KB

pubsub

import "github.com/andy2046/gopie/pkg/pubsub"

Package pubsub provides a pubsub implementation.

pubsub.go

func UUID() string

UUID generates uuid.

type Message struct {
    ID   string
    Data []byte
}

Message represents a Pub/Sub message.

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

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

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 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 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 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 (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 (t *Topic) Subscription(name string) *Subscription

Subscription returns the subscription by name..

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

Subscriptions list all the subscriptions to this topic.


Generated by godoc2md