yunspace
yunzhilin
yunspace.com
public static void main(String[] args) throws Exception {
new LazyCatApplication().run(args);
}
java -jar build/awesome_api.jar server awesome_api.yml
No War Files, No App Servers
Builds and runs a Fat Jar
Start Application in a simple Main() method
Because:
and you should
Surely Java without App Server is unstable?
More so than most Enterprise Apps
More Modules at http://modules.dropwizard.io/
Dropwizard makes it easy to do the right thing, allowing you to concentrate on the essential complexity of a problem rather than the plumbing
We agree
techempower.com/benchmarks/
techempower.com/benchmarks/
Dropping Rails for Dropwizard? - Yammer, April 2014
Java BootStrap: Dropwizard vs SprintBoot - Takipi Blog
public class FooBarFactory implements HandlerFactory {
@Override
public Handler create(LaunchConfig launchConfig) throws Exception {
return Guice.builder(launchConfig)
.bindings(bindingsSpec -> bindingsSpec.add(new MyModule()))
.build(chain -> chain
.handler("foo", context -> context.render("from the foo handler"))
.handler("bar", context -> context.render("from the bar handler")));
}
}
public class FooBarApplication extends Application<FooBarConfig> {
public static void main(String[] args) throws Exception {
new FooBarApplication().run(args);
}
@Override
public void run(final FooBarApplication configuration, final Environment environment) throws Exception {
environment.register(FooResource.class);
environment.register(BarResrouce.class);
}
}
@Path("/foo")
@Consumes(APPLICATION_JSON) @Produces(APPLICATION_JSON)
public class FooResource {
@GET
public String getFoo() {
return "from the foo handler";
}
}
Declare and isolate Dependencies (II)
Portable "gradlew" is great for CI & locks gradle version
More than just Dependency Management:
java \
-Ddw.dataSource.driverClass=$DATABASE_DRIVER -Ddw.dataSource.url=$DATABASE_URL \
-Ddw.dataSource.user=$DATABASE_USER -Ddw.dataSource.password=$DATABASE_PASSWORD \
-jar build/application.jar server config.yml
1. Replace config.yml variables in run command (messy):
dataSource:
driverClass: ${env.HIBERNATE_DRIVER!'org.h2.Driver'}
user: ${env.HIBERNATE_USER!'sa'}
password: ${env.HIBERNATE_PASSWORD!'sa'}
url: ${env.HIBERNATE_URL!'jdbc:h2:./build/h2db'}
2. Use Dropwizard-Template-Config to add ${env} in config.yml:
java -jar build/application.jar server config.yml
Used by lazybones-dropwizard-turbo
Integration using our own code
FROM errordeveloper/oracle-jre
ENV HOME /root/
WORKDIR /app/
# newrelic
RUN curl -L --silent --retry 3 \
https://download.newrelic.com/newrelic/java-agent/newrelic-agent/current/newrelic-java.zip -o newrelic-java.zip
RUN unzip newrelic-java.zip && \
rm newrelic/*.xml newrelic/*.xsd newrelic/*.yml newrelic/newrelic-api*.jar
ADD newrelic/newrelic.yml /app/newrelic/newrelic.yml
# plamasphere
ADD platmasphere-services.yml /app/
ENV PLATMA_VERSION latest
ADD build/platmasphere-services.jar /app/platmasphere-services.jar
# run
EXPOSE 9090
ENTRYPOINT [ "java" ]
CMD ["-javaagent:newrelic/newrelic.jar", "-jar", "platmasphere-services.jar", "server", "platmasphere-services.yml"]
compile "org.jadira.usertype:usertype.extended:3.2.0.GA"
compile("com.netflix.governator:governator:${governatorVersion}") {
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'commons-lang'
}
{
"description": "request for getting property 80 CLARENCE ST",
"provider_state": "property 80 CLARENCE ST exists",
"request": {
"method": "get",
"path": "/properties/1",
"headers": {
"Tenant": "trunk",
"Authorization": "Bearer valid_token"
}
},
"response": {
"status": 200,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "origin, content-type, accept, authorization, tenant",
"Access-Control-Allow-Credentials": "true",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS, HEAD",
"Access-Control-Max-Age": "43200"
},
"body": {
"id": 1,
"addressLine": "80 CLARENCE ST",
"postcode": "2000",
"state": "NSW",
"suburb": "SYDNEY",
"streamId": 1
}
}
}
Prior to deploying to a Environment, we run DB Migration as Once off Admin Processes (XII)
./gradlew dbMigrate -Pdb_schema=
./gradlew dbTag -Pdb_schema=
Docker Containers takes care of:
Like us on GitHub!