Git Product home page Git Product logo

sentries's Introduction

Sentries

Sentries is an out-of-your way Scala library that will handle all the fault-handling around calling resources like databases and remote services.

Sentries is located at: "nl.grons" %% "sentries" % "0.8.0"

Documentation

Introduction

sentry (pl. sentries) a soldier stationed to keep guard or to control access to a place.

Sentries provides known techniques such as the Circuit Breaker, rate limiting, slow ramp up, load balancing (not yet stable) and retries (todo). You select what you need by composing several sentries in a new sentry, a sentry chain. By combining this with metrics and JMX control, Sentries is the ideal wrapper for invoking databases, remote services, etc.

Example usage:

class DoItAllService extends nl.grons.sentries.support.SentrySupport {

  // withFailLimit == circuit breaker
  val dbSentry = sentry("mysql:localhost:3366").
          withMetrics.
          withFailLimit(failLimit = 5, retryDelay = 500 milliseconds)
  val twitterApiSentry = sentry("twitter").
          withMetrics.
          withConcurrencyLimit(3)

  def loadTweetFromDb(id: Long): Tweet = dbSentry {
    database.load(id)
  }

  def getFromTwitter(id: Long): Tweet = twitterApiSentry {
    twitterApi.load(id)
  }
}

See Available sentries for more and SentryExampleApp for a more elaborate example.

JMX

JMX control is started with the following:

new nl.grons.sentries.support.JmxReporter().start()

Usage guidelines

  • Exceptions are always rethrown. (Retry will be an exception to this rule.)
  • When a sentry needs to throw an exception, it will throw a NotAvailableException or subtype.
  • Sentries ignore NotAvailableExceptions from other sentries.
  • Sentries assume that a ControlThrowable means success. (These are used by Scala to do flow control.)
  • Sentries are fully multi-thread safe. Coordination with other threads is kept to the minimum. In addition, sentries will never block. If an operation can not be performed immediately, it will throw a NotAvailableException.
  • Sentries are singletons, the builder checks each sentry against the registry before usage. The registry stores sentries by owner type, resource name and sentry type.
  • Building a sentry chain is easiest by mixing in SentrySupport and use method sentry as in the example above.
  • It is permitted to use the same sentry in multiple sentry chains.
  • The sentry that limits durations should NOT be used from a Future or from an Actor. Futures and actors have other mechanisms to deal with timeouts that are more suited. (If possible this will be resolved in a later version.)

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.