pubsub

package
v0.7.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

README

Pub/Sub Utilities Package

This package provides utilities for interacting with Google Cloud Pub/Sub.

Purpose

To provide a simple, interface-based way to send messages to Pub/Sub topics, facilitating testing and decoupling from the concrete Pub/Sub client.

Files

  • pubsub.go: Defines the Messenger interface and the PubSubMessenger struct that implements it. It handles client initialization and message publishing with a configurable timeout.
  • pubsub_test.go: Unit tests for the Pub/Sub messenger.

Design Patterns

  • Interface-based Design: Defines the Messenger interface, allowing other packages (like webhook) to depend on an abstraction rather than a concrete implementation, making testing easier with mocks.
  • Wrapper Pattern: Wraps the official cloud.google.com/go/pubsub client to provide a focused Send method.

Documentation

Overview

Package pubsub contains tools for interacting with GCP pub/sub

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Messenger

type Messenger interface {
	Send(ctx context.Context, msg []byte, attrs map[string]string) error
}

Messenger defines the interface for sending messages to a relay destination.

func NewPubSubMessenger

func NewPubSubMessenger(ctx context.Context, projectID, topicID string, timeout time.Duration, opts ...option.ClientOption) (Messenger, error)

NewPubSubMessenger creates a new instance of the PubSubMessenger.

type PubSubMessenger

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

PubSubMessenger implements the Messenger interface for Google Cloud pubsub.

func (*PubSubMessenger) Send

func (p *PubSubMessenger) Send(ctx context.Context, msg []byte, attrs map[string]string) error

Send sends a message to a Google Cloud pubsub topic.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL