ProductPromotion
Logo

Scala

made by https://0x3d.site

GitHub - mingchuno/etcd4s: Scala etcd client implementing V3 APIs
Scala etcd client implementing V3 APIs. Contribute to mingchuno/etcd4s development by creating an account on GitHub.
Visit Site

GitHub - mingchuno/etcd4s: Scala etcd client implementing V3 APIs

GitHub - mingchuno/etcd4s: Scala etcd client implementing V3 APIs

etcd4s

Build Status

A Scala etcd client implementing V3 API using gRPC and ScalaPB with optional Akka Stream support. This project is in beta stage with basic test coverage and usable APIs.

Overview

This repo is a client library of etcd implementing V3 APIs using gRPC under the hood with optional Akka Stream support for stream APIs. This library implement the complete set of the APIs in the V3 protoal. More information about the APIs can be found here:

Note that this library do not support gRPC json gateway and use raw gRPC call instead (underlying is java-grpc). This project cross build against Scala 2.12 and 2.13 and also tested against etcd 3.2.x, 3.3.x but fail under 3.4.x.

Getting Started

The core lib

libraryDependencies += "com.github.mingchuno" %% "etcd4s-core" % "0.4.0"

To include akka stream support for stream API

libraryDependencies += "com.github.mingchuno" %% "etcd4s-akka-stream" % "0.4.0"

Usage

import org.etcd4s.{Etcd4sClientConfig, Etcd4sClient}
import org.etcd4s.implicits._
import org.etcd4s.formats._
import org.etcd4s.pb.etcdserverpb._

import scala.concurrent.ExecutionContext.Implicits.global

// create the client
val config = Etcd4sClientConfig(
  address = "127.0.0.1",
  port = 2379
)
val client = Etcd4sClient.newClient(config)

// set a key
client.setKey("foo", "bar") // return a Future

// get a key
client.getKey("foo").foreach { result =>
  assert(result == Some("bar"))
}

// delete a key
client.deleteKey("foo").foreach { result =>
  assert(result == 1)
}

// set more key
client.setKey("foo/bar", "Hello")
client.setKey("foo/baz", "World")

// get keys with range
client.getRange("foo/").foreach { result =>
  assert(result.count == 2)
}

// remember to shutdown the client
client.shutdown()

The above is wrapper for simplified APIs. If you want to access all underlying APIs with full options. You can use the corresponding api instance to have more control.

client.kvApi.range(...)
client.kvApi.put(...)
client.leaseApi.leaseGrant(...)
client.electionApi.leader(...)

If you want the Akka Stream support for the stream APIs, you should add the etcd4s-akka-stream depns into your build.sbt

import org.etcd4s.akkasupport._
import org.etcd4s.implicits._
import org.etcd4s.pb.etcdserverpb._
import akka.NotUsed

// assume you have the implicit value and client needed in the scope
val flow: Flow[WatchRequest, WatchResponse, NotUsed] = client.watchApi.watchFlow
val request: WatchRequest = WatchRequest().withCreateRequest(WatchCreateRequest().withKey("foo"))
Source.single(request)
  .via(flow)
  .runForeach { resp =>
    println(resp)
  }

More example usage under the test dir in the repo.

Development

Requirment

  • Java 8+, Scala 12.12.X+, sbt and docker
# to start a background etcd for development
docker-compose up -d

How to start?

Simple! Just sbt test

Publish

This is to remind me how to publish and may switch to sbt-release later

  1. make sure you have ~/.sbt/gpg/ ready with pub/sec key paris
  2. make sure you have ~/.sbt/1.0/sonatype.sbt ready with credentials
  3. sbt "+clean" "+compile"
  4. sbt "+publishSigned"
  5. sbt sonatypeReleaseAll

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory