Created
June 22, 2016 14:15
-
-
Save devnoo/7b11c7cd54db569aac5dcd14b8c6b7f3 to your computer and use it in GitHub Desktop.
CommandGateway that returns observable/single instead of CommandCallback
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
import org.axonframework.commandhandling.CommandCallback; | |
import org.axonframework.commandhandling.gateway.CommandGateway; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import rx.Observable; | |
import rx.Single; | |
import rx.Subscriber; | |
public class DefaultObservableCommandGateway implements ObservableCommandGateway { | |
@Autowired | |
private CommandGateway commandGateway; | |
@Override | |
public <R> Single<R> send(Object command) { | |
return Observable.create(new Observable.OnSubscribe<R>() { | |
@Override | |
public void call(Subscriber<? super R> subscriber) { | |
commandGateway.send(command, new CommandCallback<R>() { | |
@Override | |
public void onSuccess(R result) { | |
if (!subscriber.isUnsubscribed()) { | |
subscriber.onNext(result); | |
subscriber.onCompleted(); | |
} | |
} | |
@Override | |
public void onFailure(Throwable cause) { | |
if (!subscriber.isUnsubscribed()) { | |
subscriber.onError(cause); | |
} | |
} | |
}); | |
} | |
}).toSingle(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
works great with https://github.com/jmnarloch/rxjava-spring-boot-starter
to have async request with spring controller and axon.