Coder Social home page Coder Social logo

scala-consul's Introduction

scala-consul

Unmaintained

Codacy is not using consul at the moment and for that reason we are not developing this library any more. Feel free to fork this and keep your own code.

Alternatives

Codacy Badge Circle CI Maven Central

An asynchronous Scala (http://scala-lang.org/) client for Consul (https://consul.io/)

on an sbt project add this line to your build.sbt:

libraryDependencies += "com.codacy" %% "scala-consul" % "1.1.0"

import Consul

import consul.Consul

instanciate a consul supplying an ip and a port indicating a working consul agent:

val myConsul = new consul.Consul(CONSUL_IP, CONSUL_PORT, Option(CONSUL_ACL_TOKEN))
import myConsul.v1._

now you can use the consul API as indicated in the official documentation (http://www.consul.io/docs/agent/http.html)

Example - add a tuple to the Key/Value store:

kv.put("myKey","myValue")

Example - query the registered nodes:

catalog.nodes().map{ case nodes =>
    //do something with my nodes
}

Example - register a service with an http-check on the local node:

val myAddress = "127.0.0.1"
val myServicePort = 5000
val myServiceCheck = agent.service.httpCheck(s"http://localhost:$myServicePort/health","15s")
val myService = agent.service.LocalService(ServiceId("myServiceId"),ServiceType("myTypeOfService"),Set(ServiceTag("MyTag")),Some(myServicePort),Some(myServiceCheck),Some(Address(myAddress)))
agent.service.register(myService)

the check ID of the registered service-check is available via:

val myCheckId = myService.checkId

the other 2 types of checks are created with:

agent.service.ttlCheck

and

agent.service.scriptCheck

Error Handling:

All api methods return Futures that can fail. To parse Consul responses Play's Json library is used. In the unlikely case that the client cannot parse the response the Future will fail and you might want to access the JsError parsing resulted in. You can do so by recovering the Future:

import consul.v1.common.Types.ConsulResponseParseException
catalog.nodes().recover{
  case ConsulResponseParseException(jsError) =>  //do something with the JsError
  case NonFatal(otherException) => //something else
}

What is Codacy?

Codacy is an Automated Code Review Tool that monitors your technical debt, helps you improve your code quality, teaches best practices to your developers, and helps you save time in Code Reviews.

Among Codacy’s features:

  • Identify new Static Analysis issues
  • Commit and Pull Request Analysis with GitHub, BitBucket/Stash, GitLab (and also direct git repositories)
  • Auto-comments on Commits and Pull Requests
  • Integrations with Slack, HipChat, Jira, YouTrack
  • Track issues in Code Style, Security, Error Proneness, Performance, Unused Code and other categories

Codacy also helps keep track of Code Coverage, Code Duplication, and Code Complexity.

Codacy supports PHP, Python, Ruby, Java, JavaScript, and Scala, among others.

Free for Open Source

Codacy is free for Open Source projects.

Licence

This software is licensed under the Apache 2 license: http://www.apache.org/licenses/LICENSE-2.0

Copyright (C) 2014 Codacy (https://www.codacy.com)

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.