Documentation ¶
Index ¶
- func WithAuth(user, password string) func(*Options)
- func WithBufferSize(bufferSize int) func(*Options)
- func WithGTID(gtid string) func(*Options)
- func WithLogger(logger logger) func(*Options)
- func WithTimeout(readTimeout, writeTimeout time.Duration) func(*Options)
- func WithUUID(uuid string) func(*Options)
- func WithVersion(version int) func(*Options)
- type Consumer
- type DataStream
- type Event
- type Options
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithBufferSize ¶
WithBufferSize sets the buffer size for the data stream.
func WithLogger ¶
func WithLogger(logger logger) func(*Options)
WithLogger sets the logger to report issues when processing the data stream.
func WithTimeout ¶
WithTimeout sets connection timeouts.
func WithVersion ¶ added in v1.0.1
WithVersion sets the binlog version to use.
Types ¶
type Consumer ¶
type Consumer struct {
// contains filtered or unexported fields
}
Consumer is a Go implementation of a MaxScale CDC consumer.
func NewConsumer ¶
NewConsumer creates a new Consumer instance.
func (*Consumer) Process ¶
Process starts consuming events and trigerring the callback function for each event.
func (*Consumer) Start ¶
func (g *Consumer) Start() (*DataStream, error)
Start connects to MaxScale and starts consuming events.
https://mariadb.com/kb/en/mariadb-maxscale-6-change-data-capture-cdc-protocol/
Example ¶
package main import ( "fmt" "log" "os" "os/signal" "syscall" "github.com/rafaeljusto/gomaxscale" ) func main() { consumer := gomaxscale.NewConsumer("127.0.0.1:4001", "database", "table", gomaxscale.WithAuth("maxuser", "maxpwd"), ) dataStream, err := consumer.Start() if err != nil { log.Fatal(err) } defer consumer.Close() fmt.Printf("started consuming events from database '%s' table '%s'\n", dataStream.Database, dataStream.Table) done := make(chan bool) go func() { consumer.Process(func(event gomaxscale.Event) { fmt.Printf("event '%s' detected\n", event.Type) }) done <- true }() signalChanel := make(chan os.Signal, 1) signal.Notify(signalChanel, syscall.SIGINT, syscall.SIGTERM) select { case <-signalChanel: case <-done: } fmt.Println("terminating") }
Output:
type DataStream ¶
type DataStream struct { Namespace string `json:"namespace"` Type string `json:"type"` Name string `json:"name"` Table string `json:"table"` Database string `json:"database"` Version int `json:"version"` GTID string `json:"gtid"` Fields []struct { Name string `json:"name"` Type interface{} `json:"type"` RealType string `json:"real_type"` Length int `json:"length"` Unsigned bool `json:"unsigned"` } `json:"fields"` }
DataStream is the first event response with the target table information.
Click to show internal directories.
Click to hide internal directories.