gopostgrespubsub

package module
v0.0.1-alpha.2 Latest Latest
Warning

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

Go to latest
Published: Jun 22, 2021 License: MIT Imports: 9 Imported by: 0

README

Postgres PUB/SUB Example

O projeto visa criar uma "camada fina" de integração com o sistema de Listen/Notify do Banco de Dados Postgres.

A ideia é permitir a integração com protocolos de comunicação que matém conexão bidirecional populares, como Websockets, Kafka servers, RTC, webRTC.

É desejada uma API simples e enxuta.

Referência

Postgres Config

https://ds0nt.com/postgres-streaming-listen-notify-go

Documentation

Index

Constants

View Source
const (
	PG_INSERT_OP = "INSERT"
	PG_UPDATE_OP = "UPDATE"
	PG_DELETE_OP = "DELETE"
)

* Descreve as operações

Variables

This section is empty.

Functions

func HandleEvent

func HandleEvent(ctx context.Context, eventDataChan chan eventbus.DataEvent, l *zap.SugaredLogger, evHandler EventHandler) <-chan eventbus.Topic

Types

type DefaultEventHandler

type DefaultEventHandler struct{}

DefaultEventHandler implementa gopostgrespubsub.EventHandler e por padrão é o handler do topico `event`.

Como usar: Use a Composição em Golang e sobreescreva o metodo Name() padrão pelo seu metodo Name().

type MyEventHandler struct {
	gopostgrespubsub.DefaultEventHandler // composition
}
func (myEventHandler *MyEventHandler) Name() string {
	return "anothertopic"
}

check if the type satisfies the interface `gopostgrespubsub.EventHandler` var _ gopostgrespubsub.EventHandler = (*MyEventHandler)(nil)

func (*DefaultEventHandler) HandleDelete

func (b *DefaultEventHandler) HandleDelete(payload string) (interface{}, error)

func (*DefaultEventHandler) HandleInsert

func (b *DefaultEventHandler) HandleInsert(payload string) (interface{}, error)

func (*DefaultEventHandler) HandleUpdate

func (b *DefaultEventHandler) HandleUpdate(payload string) (interface{}, error)

func (*DefaultEventHandler) HandlerUnknownOperation

func (b *DefaultEventHandler) HandlerUnknownOperation(payload string) (interface{}, error)

func (*DefaultEventHandler) Name

func (b *DefaultEventHandler) Name() string

type EventHandler

type EventHandler interface {
	Name() string // O nome retornado é o nome da tabela que é também o nome do topico
	// HandleInsert recebe uma string json do tipo chave=coluna_tabela e valor=valor_coluna_tabela
	HandleInsert(string) (interface{}, error)
	// HandleUpdate recebe uma string json do tipo chave=coluna_tabela e valor=valor_coluna_tabela
	HandleUpdate(string) (interface{}, error)
	// HandleDelete recebe uma string json do tipo chave=coluna_tabela e valor=valor_coluna_tabela
	HandleDelete(string) (interface{}, error)
	// HandlerUnknownOperation recebe uma string json do tipo chave=coluna_tabela e valor=valor_coluna_tabela
	HandlerUnknownOperation(string) (interface{}, error)
}

EventHandler é uma interface que deve ser atendida para acessar os triggers

type PostgresPubSub

type PostgresPubSub interface {
	StartServer(ctx context.Context) <-chan error
}

func NewPostgresPubSub

func NewPostgresPubSub(ctx context.Context, config PostgresPubSubConfig) (PostgresPubSub, error)

type PostgresPubSubConfig

type PostgresPubSubConfig struct {
	DbHost        string
	DbName        string
	DbUser        string
	DbPort        string
	DbPass        string
	ServerAddr    string
	EventHandlers []EventHandler
}

Directories

Path Synopsis
transport

Jump to

Keyboard shortcuts

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