pubsub

package module
v1.2.3 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 3 Imported by: 2

README

PubSub - lightweight pub/sub messaging

PkgGoDev Build Status Go Report Card Coverage Status GitHub issues Release

Installation

To install the package, run:

go get github.com/go-zoox/pubsub

Getting Started

Subscribe
import (
  "github.com/go-zoox/pubsub"
)

func main(t *testing.T) {
	ps := pubsub.New(&pubsub.Config{
		RedisHost:     <RedisHost>,
		RedisPort:     <RedisPort>,
		RedisUsername: <RedisUsername>,
		RedisPassword: <RedisPassword>,
		RedisDB:       <RedisDB>,
	})

	ps.Subscribe(context.TODO(), "default", func(msg *pubsub.Message) error {
				logger.Infof("received message: %s", string(msg.Body))
				return nil
			})
}
Publish
import (
  "github.com/go-zoox/pubsub"
)

func main(t *testing.T) {
	ps := pubsub.New(&pubsub.Config{
		RedisHost:     <RedisHost>,
		RedisPort:     <RedisPort>,
		RedisUsername: <RedisUsername>,
		RedisPassword: <RedisPassword>,
		RedisDB:       <RedisDB>,
	})

	ps.Publish(context.TODO(), &pubsub.Message{
				Topic: "default",
				Body:  []byte("hello world"),
			})
}

License

GoZoox is released under the MIT License.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Version = "1.2.3"

Version is the current version of the package.

Functions

This section is empty.

Types

type Config added in v1.2.0

type Config struct {
	RedisHost     string
	RedisPort     int
	RedisUsername string
	RedisPassword string
	RedisDB       int
}

Config is the config for a pubsub.

type Handler added in v1.2.0

type Handler func(msg *Message) error

Handler is a pubsub handler.

type Message added in v1.2.0

type Message struct {
	Topic string
	Body  []byte
}

Message is a pubsub message.

type PubSub

type PubSub interface {
	Publish(ctx context.Context, msg *Message) error
	Subscribe(ctx context.Context, topic string, handler Handler) error
}

PubSub is a simple pubsub.

func New

func New(cfg *Config) PubSub

New creates a new pubsub.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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