ctx := context.Background()
// Initiailze a driver for Google Cloud Pub/Sub
driver, err := cloudpubsub.CreateDriver(
ctx, "my-gcp-project", "your-topic",
cloudpubsub.WithCreateTopicIfNeeded(), // Create a topic when it does not exist
cloudpubsub.WithDeleteTopicOnClose(), // Delete the topic on close the publisher
)
if err != nil {
// ...
}
// Initialize a new publisher instance
publisher := pubee.New(driver,
pubee.WithJSON(), // publish messages as JSON
pubee.WithMetadata("content_type", "json"),
pubee.WithInterceptors(
// ...
),
pubee.WithOnFailPublish(func(msg *pubee.Message, err error) {
// This function is called when failed to publish a message.
}),
)
defer publisher.Close(ctx)
type Book struct {
Title string `json:"title"`
}
// Publish a message!
publisher.Publish(ctx, &Book{Title: "The Go Programming Language"})
-
Notifications
You must be signed in to change notification settings - Fork 1
Pluggable Pub/Sub Publisher
License
izumin5210/pubee
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
About
Pluggable Pub/Sub Publisher
Resources
License
Stars
Watchers
Forks
Packages 0
No packages published