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
- Host: GitHub
- URL: https://github.com/teragrep/rlp_05
- Owner: teragrep
- License: apache-2.0
- Created: 2023-03-27T09:15:42.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-09T09:53:38.000Z (over 2 years ago)
- Last Synced: 2024-04-17T19:13:17.103Z (about 2 years ago)
- Language: Go
- Size: 3.98 MB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE
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.