golang

module
v0.0.0-...-4778dc5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2024 License: Apache-2.0

README

Pravega Golang client.

This project provides a way to interact with Pravega using Golang client.

Pravega is an open source distributed storage service implementing Streams. It offers Stream as the main primitive for the foundation of reliable storage systems: a high-performance, durable, elastic, and unlimited append-only byte stream with strict ordering and consistency.

Build and Run examples

# build dynamic library & generate header
cd golang
cargo build --release

# test go code
go build examples/main.go
./main

How to use pravega go client

  1. build rust dynamic library cd golang cargo build --release cd .. # cd to rust project root directory mv ./target/release/libpravega_client_c.so /usr/lib

  2. import to your project with go get

go get github.com/pravega/pravega-client-rust/golang@latest

or you can replace the dependence with local version

go mod edit -replace github.com/pravega/pravega-client-rust/golang=/root/go/src/your_golang_code_path
  1. Write your application with the reference to example code or bench_test code. As for how to set the clientConfig and streamConfig, you can read rust document as reference ClientConfig,StreamConfig
  2. Lets Write a sample application by using the go client step by step. Add import in your go application like this
import (
client "github.com/pravega/pravega-client-rust/golang/pkg"
)
  1. Create ClientConfig
config := client.NewClientConfig()
config.ControllerUri = "127.0.0.1:9090"
  1. Create new Stream Manager
manager, _ := client.NewStreamManager(config)
defer manager.Close()
  1. Create Scope and stream
scope := "scope"
stream := "stream"
res, _ := manager.CreateScope(scope)

streamConfig := client.NewStreamConfiguration(scope, stream)
streamConfig.Scale.MinSegments = 3
res, _ = manager.CreateStream(streamConfig)
  1. Create Writer and write some events
writer, _ := manager.CreateWriter(scope, stream)
defer writer.Close()
writer.WriteEvent([]byte("hello"))
_ = writer.Flush()
  1. Create ReaderGroup and reader and read the written events
rg, _ := manager.CreateReaderGroup(rgName, scope, stream, false)
defer rg.Close()

reader, _ := rg.CreateReader("reader1")
defer reader.Close()
slice, _ := reader.GetSegmentSlice()
defer slice.Close()
event, _ := slice.Next()

Close resources and handle errors appropriately in your application to ensure proper cleanup and error handling.

For more detailed usage and configuration options, refer to the Rust documentation for ClientConfig and StreamConfig.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL