{"id":19506891,"url":"https://github.com/erikvanoosten/sentries","last_synced_at":"2025-04-26T02:33:02.624Z","repository":{"id":4015228,"uuid":"5114330","full_name":"erikvanoosten/sentries","owner":"erikvanoosten","description":"Sentries - For easy fault handling in Scala programs","archived":false,"fork":false,"pushed_at":"2021-05-02T06:55:42.000Z","size":230,"stargazers_count":61,"open_issues_count":0,"forks_count":5,"subscribers_count":13,"default_branch":"master","last_synced_at":"2023-07-28T10:30:25.810Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Scala","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/erikvanoosten.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-07-19T19:07:46.000Z","updated_at":"2023-04-15T16:19:15.000Z","dependencies_parsed_at":"2022-08-27T03:41:34.988Z","dependency_job_id":null,"html_url":"https://github.com/erikvanoosten/sentries","commit_stats":null,"previous_names":[],"tags_count":3,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikvanoosten%2Fsentries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikvanoosten%2Fsentries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikvanoosten%2Fsentries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/erikvanoosten%2Fsentries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/erikvanoosten","download_url":"https://codeload.github.com/erikvanoosten/sentries/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224023707,"owners_count":17242998,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-10T22:38:50.401Z","updated_at":"2024-11-10T22:38:51.458Z","avatar_url":"https://github.com/erikvanoosten.png","language":"Scala","funding_links":[],"categories":["容错组件"],"sub_categories":["微服务框架"],"readme":"[![No Maintenance Intended](http://unmaintained.tech/badge.svg)](http://unmaintained.tech/)\n\n*Update May 2021:* This project was started in 2012 for use in a completely synchronous environment.\nEven back then this was a questionable idea given the high load we had to deal with. Instead\nof using this project, I would recommend you to migrate to something more asynchronous such\nas Zio or Cats Effect. If that is out of the question, feel free to clone this project and\nmake it live on.\n\n-----\n\n# Sentries\n\nSentries is an out-of-your way Scala library that will handle all the fault-handling around calling resources like databases and remote services.\n\nSentries is located at: `\"nl.grons\" %% \"sentries\" % \"0.8.0\"`\n\n*Documentation*\n\n* [Download (Sbt, Maven)](docs/download.md)\n* [Available sentries](docs/sentries.md)\n* [Testing support](docs/testing.md)\n* [Advanced sentry chaining](docs/chaining.md)\n* [Sentries and Metrics](docs/metrics.md) TODO\n* [Writing you own Sentry](docs/writing-sentries.md) TODO\n* [Developing sentries](docs/developing-sentries.md)\n\n# Introduction\n\n\u003e **sentry** (pl. **sentries**) a soldier stationed to keep guard or to control access to a place.\n\nSentries 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.\n\nExample usage:\n```scala\nclass DoItAllService extends nl.grons.sentries.support.SentrySupport {\n\n  // withFailLimit == circuit breaker\n  val dbSentry = sentry(\"mysql:localhost:3366\").\n          withMetrics.\n          withFailLimit(failLimit = 5, retryDelay = 500 milliseconds)\n  val twitterApiSentry = sentry(\"twitter\").\n          withMetrics.\n          withConcurrencyLimit(3)\n\n  def loadTweetFromDb(id: Long): Tweet = dbSentry {\n    database.load(id)\n  }\n\n  def getFromTwitter(id: Long): Tweet = twitterApiSentry {\n    twitterApi.load(id)\n  }\n}\n```\n\nSee [Available sentries](docs/sentries.md) for more and [SentryExampleApp](/src/main/scala/nl/grons/sentries/examples/SentryExampleApp.scala) for a more elaborate example.\n\n## JMX\n\nJMX control is started with the following:\n\n```scala\nnew nl.grons.sentries.support.JmxReporter().start()\n```\n\n## Usage guidelines\n\n* Exceptions are always rethrown. (Retry will be an exception to this rule.)\n* When a sentry needs to throw an exception, it will throw a `NotAvailableException` or subtype.\n* Sentries ignore `NotAvailableException`s from other sentries.\n* Sentries assume that a `ControlThrowable` means success. (These are used by Scala to do flow control.)\n* Sentries are fully multi-thread safe. Coordination with other threads is kept to the minimum. In addition,\n  sentries will never block. If an operation can not be performed immediately, it will throw a `NotAvailableException`.\n* 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.\n* Building a sentry chain is easiest by mixing in `SentrySupport` and use method `sentry` as in the example above.\n* It is permitted to use the same sentry in multiple sentry chains.\n* 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.)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikvanoosten%2Fsentries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ferikvanoosten%2Fsentries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ferikvanoosten%2Fsentries/lists"}