Documentation
¶
Overview ¶
The ezpubsub library is a set of higher-level abstractions over the Go library for Google Cloud Pub/Sub. It's built for convenience and intended to cover the vast majority of use cases with minimal fuss. If your use case isn'topic covered, You're advised to use official library.
Index ¶
- Variables
- func SimpleAckListener(msg *pubsub.Message)
- type Admin
- func (a *Admin) DeleteSubscription(subscription string) error
- func (a *Admin) DeleteSubscriptions(subscriptions ...string) error
- func (a *Admin) DeleteTopic(topicName string) error
- func (a *Admin) ListSubscriptions() ([]string, error)
- func (a *Admin) ListTopics() ([]string, error)
- func (a *Admin) SubscriptionExists(subscriptionName string) (bool, error)
- func (a *Admin) TopicExists(topicName string) (bool, error)
- type ErrorHandler
- type Listener
- type Publisher
- type PublisherConfig
- type ServerIdHandler
- type Subscriber
- type SubscriberConfig
Examples ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func SimpleAckListener ¶
A subscriber listener function that does nothing but ack each message. Useful in such situations where you need to "wind through" outstanding messages without processing them.
Types ¶
type Admin ¶
type Admin struct {
// contains filtered or unexported fields
}
A simple administrative interface for Pub/Sub projects.
Example ¶
admin, err := NewAdmin("my-project")
if err != nil {
// handle error
}
topics, err := admin.ListTopics()
if err != nil {
// handle error
}
fmt.Println("Listing topics:")
for _, topic := range topics {
fmt.Println(topic)
}
func (*Admin) DeleteSubscription ¶
Deletes a specified subscription.
func (*Admin) DeleteSubscriptions ¶
Deletes multiple subscriptions.
func (*Admin) DeleteTopic ¶
Deletes the specified topic.
func (*Admin) ListSubscriptions ¶
Lists all current subscriptions.
func (*Admin) ListTopics ¶
List all current topics under the specified project.
func (*Admin) SubscriptionExists ¶
Checks if a subscription exists.
type ErrorHandler ¶
type ErrorHandler = func(error)
A function that determines how errors are handled.
type Publisher ¶
type Publisher struct {
// contains filtered or unexported fields
}
Publishers publish messages on a specified Pub/Sub topic.
Example ¶
publisherConfig := &PublisherConfig{
Project: "...",
Topic: "...",
}
publisher, err := NewPublisher(publisherConfig)
if err != nil {
log.Fatalf("Publisher creation error: %s", err)
}
msg := []byte("Hello world")
publisher.Publish(msg)
func NewPublisher ¶
func NewPublisher(config *PublisherConfig) (*Publisher, error)
Create a new Publisher from a PublisherConfig.
func (*Publisher) PublishBatchSync ¶
Synchronously publish a batch of message payloads, preserving message order.
func (*Publisher) PublishObject ¶
Publish a JSON-serializable object on the Publisher's topic and throw an error if JSON marshalling is unsuccessful.
func (*Publisher) PublishString ¶
Publish a string on the Publisher's topic.
type PublisherConfig ¶
type PublisherConfig struct {
Project string
Topic string
ErrorHandler ErrorHandler
ServerIdHandler ServerIdHandler
}
Publisher configuration. All fields except Notifier are mandatory.
Example ¶
serverIdHandler := func(id string) {
log.Printf("Message with ID %s published", id)
}
errHandler := func(err error) {
log.Printf("Publisher error: %v", err)
}
publisherConfig := &PublisherConfig{
Project: "some-project",
Topic: "some-topic",
ServerIdHandler: serverIdHandler,
ErrorHandler: errHandler,
}
publisher, err := NewPublisher(publisherConfig)
if err != nil {
log.Fatalf("Publisher creation error: %s", err)
}
publisher.Publish([]byte("Hello world"))
type ServerIdHandler ¶
type ServerIdHandler = func(string)
A handler for the server ID returned when publishing a message.
type Subscriber ¶
type Subscriber struct {
// contains filtered or unexported fields
}
Subscribers subscribe to a specified Pub/Sub topic and process each incoming message in accordance with the supplied Listener function.
Example ¶
subscriberConfig := &SubscriberConfig{
Project: "...",
Topic: "...",
Subscription: "...",
Listener: func(msg *pubsub.Message) {
log.Printf("Message received (id: %s, payload: %s)", msg.Data, string(msg.Data))
msg.Ack()
},
ErrorHandler: func(err error) {
log.Printf("Publisher error: %v", err)
},
}
subscriber, err := NewSubscriber(subscriberConfig)
if err != nil {
log.Fatalf("Subscriber creation error: %s", err)
}
subscriber.Start()
func NewSubscriber ¶
func NewSubscriber(config *SubscriberConfig) (*Subscriber, error)
Create a new Subscriber from a SubscriberConfig.
func (*Subscriber) Start ¶
func (s *Subscriber) Start()
Start the Publisher. When started, the Publisher listens on its topic and applies the Listener function to each incoming message and the ErrorHandler function to errors.
type SubscriberConfig ¶
type SubscriberConfig struct {
Project string
Topic string
Subscription string
PushEndpoint string
Listener Listener
ErrorHandler ErrorHandler
}
Subscriber configuration. A Project, Topic, and Subscription are mandatory; errors are thrown if these are not provided. A Listener function is optional; if none is provided, a defaultListener is used that for each message received logs a simple string and acks the message. An ErrorHandler function is also optional; if none is provided, errors are logged to stderr.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
admin
command
|
|
|
advanced-subscriber
command
|
|
|
publisher
command
|
|
|
subscriber
command
|