Sunday, February 8, 2015

Moving from Ratpack 0.9.12 to 0.9.13

one of the biggest and most appreciated change is the removal of LaunchConfig and introduction of ratpack-config.  it's not yet really documented, but you can find out how it works by looking at the commits in the book-example and java gradle example regarding the change.

so, now, you don't have the RatpackMain, and you've to build your own.  first thing to do is to set the mainClassname in the build.gradle.  this will tell the application plugin which is the main class (ratpack-java gradle plugin extends application plugin.)  and shadow plugin will automatically pull the value from the application plugin and set the manifest correctly.

here's what the main class could looks like.
it starts by composing ConfigData (ratpack-config) from a yaml file (you can also use property or json, or all of them), env (with prefix) and system properties (also with prefix).

then you can get the ServerConfig you'll need to start the RatpackServer from the ConfigData (and i put everything under "server")

here's how application.yaml looks like.

how, for your existing HandlerFactory, all you have to do is to add a constructor to pass in ConfigData and change the create method to Handler create(Registry registry).

note that i have a section "idol" in the yaml config.  to pass the configuration to the Idol module, all we have to do is get it from ConfigData, it'll populate IdolConfig, and then, set that to the registry.

To use it, just @Inject IdolConfig.

btw, i've also show here how to setup the hystrix sse.  :D

also, the ratpack-jackson used to bind the objectmapper instance directly, leaving us no way to extend it.  i've developed a jackson module to serialize an annotated pojo to HAL format.  in 0.9.12, i have to extend the JacksonModule and @Provides the ObjectMapper.  however, in 0.9.13, it's now configurable.  we can simply set the jackson module in the config!

there's a small change to the http client too.  gone are HttpClients to get an instance of HttpClient with LaunchConfig, just @Inject it!  

No comments:

Post a Comment