/rlp_05

Go RELP library

Primary LanguageGoApache License 2.0Apache-2.0

rlp_05

Golang RELP library, allows the use of the RELP protocol in Golang.

Tested with Go v1.19.

Basic usage

Initializes an unencrypted RELP connection, and verifies each batch.

func main() {
    relpSess := RelpConnection{RelpDialer: &RelpPlainDialer{}}
    // OR: use RelpTLSDialer as the RelpDialer, and configure...
    relpSess.Init()
    // ...using relpSess.tlsConfig = &tls.Config{}
    batch := RelpBatch{}
    batch.Init()
    batch.PutRequest(&RelpFrameTX{
        RelpFrame{
            cmd:        "syslog",
            dataLength: len([]byte("HelloWorld")),
            data:       []byte("HelloWorld"),
        },
    })

    retry(&relpSess)

    notDone := true
    for notDone {
        commitErr := relpSess.Commit(&batch)
        if commitErr != nil {
            log.Printf("Error committing batch: '%v'\n", commitErr.Error())
        }

        if !batch.VerifyTransactionAll() {
            batch.RetryAllFailed()
            retry(&relpSess)
        } else {
            notDone = false
        }
    }

    relpSess.Disconnect()

    fmt.Println(">>DONE<<")
    // await for input, so the program doesn't exit
    a := 0.0
    fmt.Scanf("%f", &a)
}

func retry(relpSess *RelpConnection) {
    relpSess.TearDown()
    var cSuccess bool
    var cErr error
    cSuccess, cErr = relpSess.Connect("127.0.0.1", 1601)
    for !cSuccess || cErr != nil {
        relpSess.TearDown()
        time.Sleep(5 * time.Second)
        cSuccess, cErr = relpSess.Connect("127.0.0.1", 1601)
    }
}

Interface

Method or field Information

RelpConnection.Connect(hostname, port)

Initializes a TCP connection to the provided hostname:port address.

RelpConnection.RelpDialer

Specifies whether to use RelpPlainDialer or RelpTLSDialer. Configure the TLS dialer with RelpConnection.tlsConfig (after RelpConnection.Init() call as the init call uses a blank config)

RelpConnection.ackTimeoutDuration

Duration, which the connection waits for a new ACK. Timeout will return error to RelpConnection.Commit() call. Default is 30 seconds.

RelpConnection.writeTimeoutDuration

Duration, which the connection waits for a new write. Timeout will return error to RelpConnection.Commit() call. Default is 30 seconds.

RelpConnection.Commit(batch)

Sends the RelpBatch given as the argument to the established RELP connection.

RelpConnection.Disconnect()

Gracefully disconnects from the server.

RelpConnection.TearDown()

Forcefully disconnects from the server.

RelpBatch.PutRequest(RelpFrameTX)

Inserts a relp frame to the batch

RelpBatch.VerifyTransactionAll()

Verifies that all transactions got acknowledged by the server. Returns boolean.

RelpBatch.RetryAllFailed()

Adds all transactions back to the working queue. Restart the connection with tearDown+connect to try again.

Contributing

You can involve yourself with our project by opening an issue or submitting a pull request.

Contribution requirements:

  1. All changes must be accompanied by a new or changed test. If you think testing is not required in your pull request, include a sufficient explanation as why you think so.

  2. Security checks must pass

  3. Pull requests must align with the principles and values of extreme programming.

  4. Pull requests must follow the principles of Object Thinking and Elegant Objects (EO).

Read more in our Contributing Guideline.

Contributor License Agreement

Contributors must sign Teragrep Contributor License Agreement before a pull request is accepted to organization’s repositories.

You need to submit the CLA only once. After submitting the CLA you can contribute to all Teragrep’s repositories.