Skip to content

Commit

Permalink
Experimental Clojure bindings for Hystrix
Browse files Browse the repository at this point in the history
  • Loading branch information
daveray committed Feb 8, 2013
1 parent 3eba593 commit 5541933
Show file tree
Hide file tree
Showing 7 changed files with 984 additions and 0 deletions.
60 changes: 60 additions & 0 deletions hystrix-contrib/hystrix-clj/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Hystrix Clojure Bindings

This module contains idiomatic Clojure bindings for Hystrix.

# Binaries

Binaries and dependency information for Maven, Ivy, Gradle and others can be found at [http://search.maven.org](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22hystrix-clj%22).

Example for Maven:

```xml
<dependency>
<groupId>com.netflix.hystrix</groupId>
<artifactId>hystrix-clj</artifactId>
<version>x.y.z</version>
</dependency>
```

and for Ivy:

```xml
<dependency org="com.netflix.hystrix" name="hystrix-clj" rev="x.y.z" />
```

and for Leiningen:

```clojure
[com.netflix.hystrix/hystrix-clj "x.y.z"]
```

# Usage

Please see the docstrings in src/com/netflix/hystrix/core.clj for extensive usage info.

## TL;DR
You have a function that interacts with an untrusted dependency:

```clojure
(defn make-request
[arg]
... make the request ...)

; execute the request
(make-request \"baz\")
```

and you want to make it a Hystrix dependency command. Do this:

```clojure
(defcommand make-request
[arg]
... make the request ...)

; execute the request
(make-request \"baz\")

; or queue for async execution
(queue #'make-request \"baz\")
```

37 changes: 37 additions & 0 deletions hystrix-contrib/hystrix-clj/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
buildscript {
repositories {
mavenRepo name: 'clojars', url: 'http://clojars.org/repo'
}
dependencies {
classpath 'clojuresque:clojuresque:1.5.5'
}
}
apply plugin: 'clojure'

repositories {
mavenCentral()
clojarsRepo()
}

dependencies {
compile project(':hystrix-core')
compile 'org.clojure:clojure:1.4.0'
}

// This is a bit of a hack to get a copy of the classpath so I can use
// Leiningen to get a nrepl server going. One day Clojuresque might support it.
task outputClasspath {
def outputFile = new File('runtimeClasspath')
dependsOn classes
// This task is fast, so always running it is ok.
//inputs.files sourceSets.main.runtimeClasspath
//outputs.file outputFile
doFirst {
outputFile.withWriter {
it.write sourceSets.main.runtimeClasspath.asPath
}
}
}
build.dependsOn outputClasspath

// vim:ft=groovy
22 changes: 22 additions & 0 deletions hystrix-contrib/hystrix-clj/project.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
; This is a dummy lein project for using nrepl, vimclojure, etc.
(defproject hystrix-clj "0.0.0"
:description ""
:url ""
:license {:name ""
:url "http://netflix.com"}

; No dependencies here because we rely on Ivy and the :resoure-paths hack below
:dependencies []
:warn-on-reflection true

:profiles {
:dev {
:jvm-opts [ ]
:source-paths ["src/main/clojure" "src/test/clojure"]

; runtimeClasspath is generated by build.gradle
:resource-paths ~(-> "runtimeClasspath"
slurp
(.split ":")
vec) }})

Loading

0 comments on commit 5541933

Please sign in to comment.