Categorygithub.com/netrixframework/go-clientlibrary
modulepackage
0.1.7
Repository: https://github.com/netrixframework/go-clientlibrary.git
Documentation: pkg.go.dev

# README

go-replicaclient

API Reference

Netrix client to be run on each replica. Uses the Netrix API to send/receive messages. Refer here for Netrix documentation.

Installation

Fetch and install library using go get,

go get github.com/netrixframework/go-replicaclient

Usage

Define a directive handler to handle Directive messages from Netrix. For example,

type Replica struct {
    ...
}

func (n *Replica) Start() error {}

func (n *Replica) Stop() error {}

func (n *Replica) Restart() error {}

To initialize the client, pass the ID, directive handler and optionally a logger that the client can use to log debug messages.

import (
    "github.com/netrixframework/go-replicaclient"
    "github.com/netrixframework/netrix/types"
)

func main() {

    replica := NewReplica()
    ...
    err := replicaclient.Init(&replicaclient.Config{
        ReplicaID: types.ReplicaID(Replica.ID),
        NetrixAddr: "<netrix_addr>",
        ClientServerAddr: "localhost:7074",
    }, replica, logger)
    if err != nil {
        ...
    }
}

The library maintains a single instance of ReplicaClient which can be used to send/receive messages or publish events

client, _ := replicaclient.GetClient()
client.SendMessage(type, to, data, true)
...
message, ok := client.ReceiveMessage()
...

client.PublishEvent("Commit", map[string]string{
    "param1": "val1",
})

Configuration

Init accepts a Config instance as the first argument which is defined as,

type Config struct {
    ReplicaID        types.ReplicaID
    NetrixAddr       string
    ClientServerAddr string
    ClientAdvAddr    string
    Info             map[string]interface{}
}

# Functions

GetController returns the global controller if initialized.
Init initializes the global controller.
No description provided by the author
NewMessageQueue returns an empty MessageQueue.
NewReplicaClient creates a ClientController It requires a DirectiveHandler which is used to perform directive actions such as start, stop and restart.

# Variables

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

No description provided by the author
No description provided by the author
MessageQueue datastructure to store the messages in a FIFO queue.
ReplicaClient should be used as a transport to send messages between replicas.

# Interfaces

DirectiveHandler is used to perform action on the current replica such as start, stop or restart the replica.
Logger interface for logging information.
TimeoutInfo encapsulates the timeout information that needs to be scheduled.