18. Traditionally there is a temporal disconnect between
calling an async function and getting its response.
public void asyncDbCall(Long productId, Consumer callback) {
Product product = ... async db call + future + wait for future
callback.apply(product);
}
19. Bad things happen!
final List products = new ArrayList();
Long productId = request.pathTokens.productId;
db.asyncDbCall(productId, product -> products.add(product));
Long nextProductId = productId+1;
db.asyncDbCall(nextProductId, product -> products.add(product));
response.send(products);
20. There is no guarantee as to what order async calls will
be executed!
final List products = new ArrayList();
String productId = request.pathTokens.productId;
db.asyncDbCall(productId, product -> products.add(product)); // call may return first, maybe not!
String nextProductId = productId+1;
db.asyncDbCall(nextProductId, product -> products.add(product)); // call may return second, may not!
response.send(products); // what even is the value of `products` here!
36. CAN BE BACKED BY ANY COMPONENT-
PROVIDING SYSTEM
SPRING BOOT AND GUICE NATIVELY SUPPORTED
37. Can quickly prototype without any DI system
public static void main(String[] args) throws Exception {
RatpackServer.start(spec -> spec
.registryOf(r -> r.add(new MyAsyncDbService())) // bind my service in the registry
.handlers(chain -> chain
.get(ctx -> {
MyAsyncDbService db = ctx.get(MyAsyncDbService.class); // retrieve it later
// ...
})
)
);
}
38. Integrate with Spring Boot when you're ready!
@SpringBootApplication // Spring Boot!!
public class Main {
@Bean
public MyAsyncDbService myAsyncDbService() { // bind it as a bean!
return new MyAsyncDbService();
}
public static void main(String[] args) {
// turn Spring Boot into a Ratpack registry!
Registry registry = ratpack.spring.Spring.spring(Main.class);
RatpackServer.start(spec -> spec
.registry(registry)
.handlers(chain -> chain
.get(ctx -> {
MyAsyncDbService db = ctx.get(MyAsyncDbService.class); // retrieve your service!
// ...
})
)
)
}
}
39. Architect your application using all the helpful aspects
of Spring Boot, while using Ratpack under the hood for
high throughput, reactive, async, non-blocking
processing
46. Unrealistic.
Modern performance testing needs to be about how much
burst traffic can be sustained, without your service
falling over, before you can horizontally scale it.