import "github.com/andy2046/gopie/pkg/pubsub"
Package pubsub provides a pubsub implementation.
- func UUID() string
- type Message
- type PubSub
- type PublishError
- type Subscription
- type Topic
- func (t *Topic) Delete()
- func (t *Topic) Name() string
- func (t *Topic) NewSubscription(numGoroutines int) (*Subscription, error)
- func (t *Topic) Publish(ctx context.Context, msg *Message) error
- func (t *Topic) Stop()
- func (t *Topic) Subscription(name string) *Subscription
- func (t *Topic) Subscriptions() []string
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 (p *PubSub) Name() string
Name returns the full name for the PubSub.
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 (p *PubSub) Topic(name string) *Topic
Topic returns the topic by name.
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 (pe PublishError) Error() string
type Subscription struct {
// contains filtered or unexported fields
}
Subscription represents a PubSub subscription.
func (s *Subscription) Delete()
Delete unsubscribes itself from topic.
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 (t *Topic) Delete()
Delete removes itself from PubSuband stop it.
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 (t *Topic) Publish(ctx context.Context, msg *Message) error
Publish publishes msg to the topic asynchronously.
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.
Generated by godoc2md