services

package
v1.6.21 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type PubSubService

type PubSubService struct {
	Client *pubsub.Client
}

PubSubService represents a service for interacting with a Pub/Sub system.

func NewPubSubService

func NewPubSubService(client *pubsub.Client) *PubSubService

NewPubSubService creates a new instance of the PubSubService using the provided pubsub.Client.

func (*PubSubService) PublishMessage

func (p *PubSubService) PublishMessage(ctx context.Context, topicName string, data []byte) (string, error)

PublishMessage publishes a message to a specified topic in the Pub/Sub service. It takes a topicName string and data []byte as parameters and returns the message ID and an error (if any). If the topic doesn't exist, it creates a new topic with the given name. The function first checks if the topic exists, and if not, it creates the topic. Then, it sets the message data and publishes the message to the topic. The function returns the message ID if the message is successfully published, otherwise it returns an error.

func (*PubSubService) Subscribe

func (p *PubSubService) Subscribe(ctx context.Context, topicName string, subName string, handler func(context.Context, *pubsub.Message)) error

Subscribe creates a new subscription for a given topic and starts receiving messages. It takes the topic name, subscription name, and a message handler function as parameters. The message handler function is responsible for processing the received messages. It returns an error if there was a problem creating the subscription or receiving messages.

Jump to

Keyboard shortcuts

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