Skip to content

eemhu/rlp_05

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%