wal

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2023 License: MIT Imports: 10 Imported by: 0

README

WAL-Notifier 0.2

The notifier is used for processing INSERTED records into the Postgres table.

Returning an error from the handler is only necessary as a guarantee that processing will continue from that event after the notifiers crash. All error handling should be done on the handler side, since events will continue to arrive despite the returned error.

Creating a new notifier:


    defaultOpts := &wal.Options{
        DBAddr:       "postgres://[user]:[password]@127.0.0.1:5432/[db]?replication=database",
        TableName:    "[table_name]",
        PubName:      "pub",
        SlotName:     "replication_slot",
        OutputPlugin: "pgoutput",
    }

    // create new instance of WAL-Notifier
    n, err := wal.NewNotifier(defaultOpts)

    // handler for processing record data.
    handler := func(ctx context.Context, table string, values map[string][]byte) error {
        // "values" is a map of fields of DB record: [column_name]:[data]
        ...
    }

    // run notifier
    err = n.Listen(context.TODO(), handler)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Validator = validator.New()

Functions

This section is empty.

Types

type Handler

type Handler func(ctx context.Context, table string, values map[string][]byte) error

Handler is processing function for handling inserted records

type LogicalMessage

type LogicalMessage struct {
	Message    pglogrepl.Message
	Relations  map[uint32]*pglogrepl.RelationMessage
	WALPointer pglogrepl.LSN
}

LogicalMessage is used as an argument to handlers

type Notifier

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

func NewNotifier

func NewNotifier(opts *Options) (*Notifier, error)

NewNotifier creates new notifier

func (*Notifier) Listen

func (n *Notifier) Listen(ctx context.Context, handler Handler) error

Listen connects to Posgres and starts to listen to table events

type Options

type Options struct {
	DBAddr       string `validate:"required"`
	TableName    string `validate:"required"`
	PubName      string
	SlotName     string
	OutputPlugin string
}

Jump to

Keyboard shortcuts

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