An open API service indexing awesome lists of open source software.

https://github.com/teragrep/rlp_05

Go RELP library
https://github.com/teragrep/rlp_05

Last synced: about 2 months ago
JSON representation

Go RELP library

Awesome Lists containing this project

README

          

[#_rlp_05]
= 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.
[,go]
----
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

// Change the repository name in the issues link to match with your project's name

You can involve yourself with our project by https://github.com/teragrep/rlp_05/issues/new/choose[opening an issue] or submitting a pull request.

Contribution requirements:

. *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.
. Security checks must pass
. Pull requests must align with the principles and http://www.extremeprogramming.org/values.html[values] of extreme programming.
. Pull requests must follow the principles of Object Thinking and Elegant Objects (EO).

Read more in our https://github.com/teragrep/teragrep/blob/main/contributing.adoc[Contributing Guideline].

=== Contributor License Agreement

Contributors must sign https://github.com/teragrep/teragrep/blob/main/cla.adoc[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.