Skip to content

DeltaArchitect/kit-pubsub

kit-pubsub

Go Report Card codecov Go Reference

A simplified, testable Pub/Sub V2 client wrapper for Go.

Installation

go get github.com/DeltaArchitect/kit-pubsub

Usage

Initialization

import "github.com/DeltaArchitect/kit-pubsub"

ctx := context.Background()
client, err := pubsub.NewClient(ctx, "your-project-id")
if err != nil {
    // handle error
}
defer client.Close()

Publishing Messages

topicID := "your-topic"
data := []byte("Hello, Pub/Sub!")
id, err := client.Publish(ctx, topicID, data)
if err != nil {
    // handle error
}
fmt.Printf("Published message with ID: %s\n", id)

Subscribing to Messages

subID := "your-subscription"
err := client.Subscribe(ctx, subID, func(ctx context.Context, msg *pubsub.Message) {
    fmt.Printf("Received message: %s\n", string(msg.Data))
    msg.Ack()
})
if err != nil {
    // handle error
}

Testing

This library includes helpers for testing your application code that uses Pub/Sub.

You can use pubsub.NewClient with option.WithGRPCConn(conn) to connect to a fake Pub/Sub server (like pstest).

About

A lightweight Go library for Google Cloud Pub/Sub V2 with simplified interfaces and built-in testing support

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages