Last active
August 29, 2015 14:02
-
-
Save NiteshKant/c7a909e53030c76473b0 to your computer and use it in GitHub Desktop.
Ribbon proposed interaction model
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public @interface Hystrix { | |
String name(); | |
Class<? extends FallbackProvider<?>> fallback(); | |
// How do we represent the config? | |
interface FallbackProvider<T> extends Func1<HystrixCommand<T>, Observable<? extends T>> { | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyApplication { | |
public static void main(String[] args) { | |
Movie movie = Ribbon.createClient(MyService.class).getMovie("id1") | |
.flatMap(new Func1<Response<Movie>, Observable<? extends Movie>>() { | |
@Override | |
public Observable<? extends Movie> call( | |
Response<Movie> movieResponse) { | |
return movieResponse.value(); | |
} | |
}).toBlockingObservable().single(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface MyService { | |
@Get(uri = "/api/v1/movie/{id}") | |
@EVCache(name = "api-movie-cache", appName = "api", cacheKeyTemplate = "{custId}:{id1}", | |
enableZoneFallback = true, ttl = 36000) | |
@Hystrix(name = "movie-fallback", fallback = MovieFallback.class) | |
Observable<Response<Movie>> getMovie(@Var("id") String movieId); | |
@Get(uri = "/api/v1/mylist/") | |
@EVCache(name = "api-mylist-cache", appName = "api", cacheKeyTemplate = "{custId}", | |
enableZoneFallback = true, ttl = 36000) | |
@Hystrix(name = "movie-list-fallback", fallback = MyListFallback.class) | |
Observable<Response<List<Movie>>> getMyList(); | |
class MovieFallback implements Hystrix.FallbackProvider<Movie> { | |
@Override | |
public Observable<Movie> call(HystrixCommand<Movie> movieHystrixCommand) { | |
// TODO: Auto-generated method stub | |
return null; | |
} | |
} | |
class MyListFallback implements Hystrix.FallbackProvider<List<Movie>> { | |
@Override | |
public Observable<List<Movie>> call(HystrixCommand<List<Movie>> movieHystrixCommand) { | |
// TODO: Auto-generated method stub | |
return null; | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface Response<T> { | |
/*TODO: In order to provide some type safety of value, we may think about providing a Dictionary construcs as opposed to Map here.*/ | |
Observable<Map<String, Object>> asDictionary(); | |
Observable<T> value(); | |
// Any other generic method we would want to put here? | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class Ribbon { | |
private Ribbon() { | |
} | |
@SuppressWarnings("unchecked") | |
public static <T> T createClient(Class<T> contract) { | |
return (T) Proxy.newProxyInstance(Ribbon.class.getClassLoader(), | |
new Class[] {contract}, new InvocationHandler() { | |
@Override | |
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { | |
// TODO: Auto-generated method stub | |
return null; | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Review Comments: