Code Monkey home page Code Monkey logo

etcd4s's Introduction

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

etcd4s's People

Contributors

bbenchen avatar mingchuno avatar phisgr avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

etcd4s's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
sbt
project/Dependencies.scala
  • org.scalatest:scalatest 3.2.11
  • com.typesafe.akka:akka-stream 2.6.14
  • com.typesafe.akka:akka-stream-testkit 2.6.14
  • com.typesafe.akka:akka-testkit 2.6.14
project/build.properties
  • sbt/sbt 1.3.7
project/build.scala
  • scala 2.13.8
project/plugins.sbt
  • org.scalameta:sbt-scalafmt 2.4.2
project/project.sbt
  • org.scoverage:sbt-scoverage 1.6.1
  • org.xerial.sbt:sbt-sonatype 3.9.7
  • com.jsuereth:sbt-pgp 2.1.1
project/protoc.sbt
  • com.thesamet:sbt-protoc 0.99.34
  • com.thesamet.scalapb:compilerplugin 0.11.1
scalafmt
.scalafmt.conf
  • scalafmt 2.3.2

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.