codacy / scala-consul

Consul API for scala




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.


Codacy Badge Circle CI Maven Central

An asynchronous Scala ( client for Consul (

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 (

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


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 = ""
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)))

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

val myCheckId = myService.checkId

the other 2 types of checks are created with:




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
  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.


This software is licensed under the Apache 2 license:

Copyright (C) 2014 Codacy (