Dropwizard and Friends
On a Twelve-factor Quest
Meetup April 2015Sydney MicroServices
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
WhyWhy
DemoDemo
DecisionsDecisions
CD + DockerCD + Docker
Why Dropwizard?
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
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?
Production ReadyProduction Ready
Ops Friend
Health Checks
Metrix
More so than most Enterprise Apps
Plays Well with OthersPlays Well with Others
More Modules at http://modules.dropwizard.io/
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
HighHigh
PerformancePerformance
techempower.com/benchmarks/
LowLow
LatencyLatency
techempower.com/benchmarks/
Compared to RailsCompared to Rails
- Yammer, April 2014Dropping Rails for Dropwizard?
Compared Spring BootCompared Spring Boot
- Takipi BlogJava BootStrap: Dropwizard vs SprintBoot
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
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
Build another "Hello World" App?Build another "Hello World" App?
DemoDemo
Let's build a
app using !
Dropwizard Turbo
LazyBones
12 Factors12 Factors
Design DecisionsDesign Decisions
Iron FistedIron Fisted
GradleGradle
Declare and isolate
Portable "gradlew" is great for CI & locks gradle version
More than just Dependency Management:
builds shadow
Dependencies (II)
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)
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
Swagger.IOSwagger.IO
Integration using our own code
New RelicNew Relic
Gist:
Register above listener, add newrelic.jar
NewRelicTimedApplicationListener
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
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
Continuous DeliveryContinuous Delivery
++
DockerDocker
Snap-CISnap-CI
Continuous Delivery enables:Continuous Delivery enables:
Strictly Separate
Reduced
Build, Release, Run (V)
Dev/prod parity (X)
ContractContractPactPact
{
"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
}
}
}
BinTray and Quay.ioBinTray and Quay.io
One Codebase, many deploys (I)
Small Base Image = quicker build time
Use (busybox based)
Only 159 mb
errordeveloper/oracle-jre
Build Docker ImagesBuild Docker Images
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=
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:
Running Containers in TutumRunning Containers in Tutum
https://docs.tutum.co/v2/api/
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

Dropwizard and Friends

  • 1.
    Dropwizard and Friends Ona Twelve-factor Quest Meetup April 2015Sydney MicroServices
  • 2.
    About MeAbout Me CompScience 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
  • 3.
  • 4.
  • 6.
    Standalone AppStandalone App publicstatic 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?WhoUses 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?
  • 8.
    Production ReadyProduction Ready OpsFriend Health Checks Metrix More so than most Enterprise Apps
  • 9.
    Plays Well withOthersPlays Well with Others More Modules at http://modules.dropwizard.io/
  • 10.
    Easy to dothe 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
  • 11.
  • 12.
  • 13.
    Compared to RailsComparedto Rails - Yammer, April 2014Dropping Rails for Dropwizard?
  • 14.
    Compared Spring BootComparedSpring Boot - Takipi BlogJava BootStrap: Dropwizard vs SprintBoot
  • 15.
    Compared to RatPackComparedto 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 forthe 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
  • 17.
    Build another "HelloWorld" App?Build another "Hello World" App? DemoDemo
  • 18.
    Let's build a appusing ! Dropwizard Turbo LazyBones
  • 19.
  • 21.
  • 22.
    GradleGradle Declare and isolate Portable"gradlew" is great for CI & locks gradle version More than just Dependency Management: builds shadow Dependencies (II)
  • 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
  • 25.
  • 26.
    New RelicNew Relic Gist: Registerabove listener, add newrelic.jar NewRelicTimedApplicationListener
  • 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 isNOT 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
  • 29.
  • 30.
    Snap-CISnap-CI Continuous Delivery enables:ContinuousDelivery enables: Strictly Separate Reduced Build, Release, Run (V) Dev/prod parity (X)
  • 31.
    ContractContractPactPact { "description": "request forgetting 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 } } }
  • 32.
    BinTray and Quay.ioBinTrayand Quay.io One Codebase, many deploys (I)
  • 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 Priorto 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 ContainerDeployDocker 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 inTutumRunning Containers in Tutum https://docs.tutum.co/v2/api/
  • 37.
    QuestionsQuestions Like us onGitHub! https://github.com/Trunkplatform/lazybones-dropwizard-turbo Dropwizard Links dropwizard.io https://github.com/dropwizard https://groups.google.com/forum/#!forum/dropwizard-user