import com.netflix.hystrix.HystrixCommand; import com.netflix.hystrix.HystrixCommandGroupKey; public class RemoteServiceCommand extends HystrixCommand<String> { private final String url; public RemoteServiceCommand(String url) { super(HystrixCommandGroupKey.Factory.asKey("RemoteService")); this.url = url; } @Override protected String run() throws Exception { return invokeRemoteService(url); } @Override protected String getFallback() { return "Fallback response"; } } public class UserDetailsServiceCommand extends HystrixCommand<UserDetails> { private final Long userId; public UserDetailsServiceCommand(Long userId) { super(HystrixCommandGroupKey.Factory.asKey("UserDetailsService")); this.userId = userId; } @Override protected UserDetails run() throws Exception { UserDetails userDetails = invokeUserDetailsService(userId); if (userDetails == null) { throw new Exception("User details not found"); } return userDetails; } @Override protected UserDetails getFallback() { return new UserDetails("Default User", "default_avatar.jpg"); } }


上一篇:
下一篇:
切换中文