I want to open circuit as per below scenario:
public class SampleClass extends HystrixCommand {
@Override
void run() throws exception {
CallBack callback = new CallBack();
.
.
someMethod(callback);
// someMethod is an async call and it returns immediately. The async call has callback functionality. callback is a diffferent thread. hence i need a new object for each hystrix command.
// callback will have exceptions which can't be handled here. run() method should not wait for callback.
}
@Override
void getFallback() {
// fallback logic goes here.
}
public class CallBack {
void callback(Exception e) {
if (exception != null) {
getFallback() // call getFallback() explicitly.
}
}
}
}
Main Class:
public class Main {
public static void main(String[] args) {
while(someCondition) {
new SampleClass().execute()
}
}
}
Now whenever the callback has exceptions, I want to increment hystrix exceptions counter(just like the exceptions occurs in run method) so that hystrix can act upon and trip the circuit.
Since the execution of the run method is always a success, I should somehow tell hystrix that exceptions are occurring(just like run() method exceptions) and allow hystrix to trip the circuit.
Any help or comments or any suggestions is very much appreciated.
Thanks,
Suman
I think you're trying to shoehorn async work into a HystrixCommand. If you can convert your async work into an RxJava Observable, then you can just directly use a HystrixObservableCommand.
Hystrix doesn't support directly managing internal state outside of the library.
Closing due to inactivity, please re-open if there's more to discuss
Most helpful comment
I think you're trying to shoehorn async work into a
HystrixCommand. If you can convert your async work into an RxJavaObservable, then you can just directly use aHystrixObservableCommand.Hystrix doesn't support directly managing internal state outside of the library.