2. About MeAbout Me
Comp Science Bachelor UNSW
Applied Finance PostGrad at Macquarie Uni
ESB driver at Accenture, BGI/BlackRock, Macquarie Group
Now Microservicing Trunk Platform
yunspace yunzhilin yunspace.com
My opinions does not reflect the view of the company
Shout out if you have questions, or answers
6. Standalone AppStandalone App
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:
Application Servers are Dead
and you should
Stop Wasting Money on Application Servers
7. Who Uses Dropwizard?Who Uses Dropwizard?
Sky -
Datasift - dropwizard extra, scala, zeromq
HubSpot - dropwizard-guice
Gilt -
airbnb -
Riot Games -
Bloom Health -
Fault Tolerant Microservices
Production Ready Web Services with Dropwizard
Introducing Airpal
How we built a Cloud Platform at Riot
Games using NetflixOSS
Micro-services with Dropwizard
Surely Java without App Server is unstable?
9. Plays Well with OthersPlays Well with Others
More Modules at http://modules.dropwizard.io/
10. Easy to do the Right ThingEasy to do the Right Thing
Dropwizard makes it easy to do the right thing,
allowing you to concentrate on the essential
complexity of a problem rather than the plumbing
ThoughtWorks Technology Radar
We agree
15. Compared to RatPackCompared to RatPack
public class FooBarFactory implements HandlerFacto
@Override
public Handler create(LaunchConfig launchConfig)
return Guice.builder(launchConfig)
.bindings(bindingsSpec -> bindingsSpec.add(n
.build(chain -> chain
.handler("foo", context -> context.render(
.handler("bar", context -> context.render(
}
}
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 Exc
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";
}
}
Dropwizard is more opinionated and explicit
16. Right Tool for the Right JobRight Tool for the Right Job
Not a silver bullet
We also use Rails to leverage neat Gems
And AngularJs on HarpJs for Static Sites
23. ConfigurationConfiguration
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'}
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
2. Use to add ${env} in config.yml:Dropwizard-Template-Config
java -jar build/application.jar server config.yml
1. Replace config.yml variables in run command (messy):
Attach with no code change
Configuration using Environment Variables (III)
Backing Services (IV)
24. ModulesModules
Dropwizard version 0.8.0: major update.
We are active contributors, get in contact if you have
any issues
Jersey2
github.com/dropwizard/dropwizard-java8
github.com/hubspot/dropwizard-guice
Used by lazybones-dropwizard-turbo
27. DockerfileDockerfile
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 n
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", "platmasphe
28. TipsTips
Joda DateTime is NOT equivalent to JSR-310
LocalDateTime. Use ZonedDateTime or OffsetDateTime
compile "org.jadira.usertype:usertype.extended:3.2.0.GA"
Use Governator @LazySingleton if you have issue with
Guice eager @Singleton
compile("com.netflix.governator:governator:${governatorVersion}") {
exclude group: 'com.google.guava', module: 'guava'
exclude group: 'commons-lang'
}
Multiple Database Schema Support: have a look here
for Hibernate JSR-310 supportJadira UserType Extended
33. Small Base Image = quicker build time
Use (busybox based)
Only 159 mb
errordeveloper/oracle-jre
Build Docker ImagesBuild Docker Images
34. Database MigrationDatabase Migration
Prior to deploying to a Environment, we run DB
Migration as Once off Admin Processes (XII)
./gradlew dbMigrate -Pdb_schema=
./gradlew dbTag -Pdb_schema=
35. Deploy Docker ContainerDeploy Docker Container
Isolation of and
Containers are and
to LogSpout
Stateless Processes (VI) Port
binding (VII)
Disposable(IX) Concurrent(VIII)
Stream Logs (XI)
Docker Containers takes care of:
36. Running Containers in TutumRunning Containers in Tutum
https://docs.tutum.co/v2/api/
37. QuestionsQuestions
Like us on GitHub!
https://github.com/Trunkplatform/lazybones-dropwizard-turbo
Dropwizard Links
dropwizard.io
https://github.com/dropwizard
https://groups.google.com/forum/#!forum/dropwizard-user