-
Notifications
You must be signed in to change notification settings - Fork 8
Short examples
public interface TodoRepo {
Promise<List<Todo>> loadTodos();
...
}
todoRep.loadTodos()
.then(todos -> {
logger.info("list todos");
returnPromise.resolve(todos);
})
.catchError(error -> {
logger.error("Unable to add todo to repo", error);
returnPromise.reject("Unable to add todo to repo");
})
.invoke();
reactor.runTaskAfter(Duration.ofSeconds(60), () -> {
logger.info("Registering health check and recovery for repo");
reactor.addRepeatingTask(Duration.ofSeconds(30), this::circuitBreakerTest);
});
//Connect to repo.
connect().catchError(error -> {
notConnectedCount++;
logger.error("Not connected to repo " + notConnectedCount, error);
...
}).thenSafe(connected -> {
...
notConnectedCount = 0;
}).invokeWithReactor(reactor);
private Breaker<Session> sessionBreaker =
Breaker.opened();
reactor.runTaskAfter(Duration.ofSeconds(60), () -> {
logger.info("Registering health check and recovery for repo");
reactor.addRepeatingTask(Duration.ofSeconds(30), this::circuitBreakerTest);
});
private void circuitBreakerTest() {
sessionBreaker.ifBroken(() -> {
serviceMgmt.increment("repo.breaker.broken");
//Clean up the old session.
sessionBreaker.cleanup(session -> {
try {
if (!session.isClosed()) { session.close(); }
} catch (Exception ex) { logger.warn("unable to clean up old session", ex); }
});
//Connect to repo.
connect().catchError(error -> {
notConnectedCount++;
logger.error("Not connected to repo " + notConnectedCount, error);
...
if (notConnectedCount > 10) {
logger.error("Attempts to reconnect to Repo failed. Mark it.");
serviceMgmt.increment("repo.connect.error.fatal");
serviceMgmt.setFailingWithError(error);
}
}).thenSafe(connected -> {
if (serviceMgmt.isFailing()) {
serviceMgmt.increment("repo.connect.recover");
serviceMgmt.recover();
}
notConnectedCount = 0;
}).invokeWithReactor(reactor);
});
}
The circuitBreakerTest
runs every 30 seconds.
reactor.runTaskAfter(Duration.ofSeconds(60), () -> {
reactor.addRepeatingTask(Duration.ofSeconds(30),
this::circuitBreakerTest);
});
sessionBreaker = Breaker.operational(session, 10,
theSession ->
!theSession.isClosed()
&& criticalRepoErrors.get() > 25
);
@Override
public Promise<Boolean> addTodo(final Todo todo) {
logger.info("Add Todo called");
return invokablePromise(promise -> sessionBreaker
.ifBroken(() -> {
final String message = "Not connected to repo while adding todo";
promise.reject(message);
logger.error(message);
serviceMgmt.increment("repo.breaker.broken");
})
.ifOperational(session ->
doAddTodo(todo, promise, session)
)
);
}
Java Promises
- Promise
- Promise then*() and catchError()
- Promise thenMap()
- Promise all()
- Promise any()
- Blocking Promise
- Invokable Promise
- Reactor Replay Promises
Reactor, Stream, Results
- QBit Reactive Microservices
- Reakt Reactive Java
- Reakt Guava Bridge
- QBit Extensions
- Elekt Consul Leadership election
- Elekt Leadership election
- Reactive Microservices
What is Microservices Architecture?
QBit Java Micorservices lib tutorials
The Java microservice lib. QBit is a reactive programming lib for building microservices - JSON, HTTP, WebSocket, and REST. QBit uses reactive programming to build elastic REST, and WebSockets based cloud friendly, web services. SOA evolved for mobile and cloud. ServiceDiscovery, Health, reactive StatService, events, Java idiomatic reactive programming for Microservices.
Reactive Programming, Java Microservices, Rick Hightower
Java Microservices Architecture
[Microservice Service Discovery with Consul] (http://www.mammatustech.com/Microservice-Service-Discovery-with-Consul)
Microservices Service Discovery Tutorial with Consul
[Reactive Microservices] (http://www.mammatustech.com/reactive-microservices)
[High Speed Microservices] (http://www.mammatustech.com/high-speed-microservices)
Reactive Microservices Tutorial, using the Reactor
QBit is mentioned in the Restlet blog
All code is written using JetBrains Idea - the best IDE ever!
Kafka training, Kafka consulting, Cassandra training, Cassandra consulting, Spark training, Spark consulting
Java Promises
- Promise
- Promise then*() and catchError()
- Promise thenMap()
- Promise all()
- Promise any()
- Blocking Promise
- Invokable Promise
- Reactor Replay Promises
Callback, and async Results
Reactor, Stream and Stream Result
Expected & Circuit Breaker
Scala Akka and Reakt