dropwizard
play

Dropwizard A RESTful Love Story Ryan Kennedy (@rckenned) - PowerPoint PPT Presentation

Dropwizard A RESTful Love Story Ryan Kennedy (@rckenned) Core Services @ Yammer Dropwizard A RESTful Love Story Ryan Kennedy (@rckenned) Core


  1. Dropwizard ¡ A ¡RESTful ¡Love ¡Story ¡ ¡ Ryan ¡Kennedy ¡(@rckenned) ¡ Core ¡Services ¡@ ¡Yammer ¡

  2. Dropwizard ¡ A ¡RESTful ¡Love ¡Story ¡ ¡ Ryan ¡Kennedy ¡(@rckenned) ¡ Core ¡Services ¡@ ¡Yammer ¡+ ¡MicrosoE ¡

  3. What ¡on ¡earth ¡is ¡ Dropwizard? ¡

  4. Some ¡bearded ¡jerk ¡in ¡ ¡ a ¡pointy ¡hat… ¡

  5. or… ¡

  6. Started ¡at ¡Yammer ¡as ¡three ¡services ¡ with ¡largely ¡copy/pasted ¡code ¡

  7. By ¡service ¡number ¡three ¡we ¡ idenOfied ¡and ¡disOlled ¡the ¡paQern ¡

  8. What ¡was ¡the ¡paQern? ¡

  9. “Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

  10. “Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

  11. YAML ¡configuraOon ¡file ¡

  12. hQp: ¡ ¡ ¡port: ¡8080 ¡ ¡ ¡adminPort: ¡8081 ¡ ¡ # ¡a ¡string ¡ foo: ¡foo ¡value ¡ ¡ # ¡a ¡duraOon ¡ bar: ¡60 ¡seconds ¡ ¡ # ¡a ¡number ¡ baz: ¡10101 ¡

  13. ConfiguraOon ¡validaOon ¡

  14. public ¡class ¡MyAppConfiguraOon ¡ ¡ ¡ ¡extends ¡ConfiguraOon ¡{ ¡ ¡ ¡@NotBlank ¡ ¡ ¡private ¡String ¡foo; ¡ ¡ ¡ ¡@NotNull ¡ ¡ ¡private ¡DuraOon ¡bar ¡= ¡DuraOon.minutes(10); ¡ ¡ ¡ ¡@Min(1) ¡ ¡ ¡@Max(1024) ¡ ¡ ¡private ¡long ¡baz ¡= ¡1; ¡ } ¡

  15. “Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

  16. Gauges ¡ Metrics.newGauge(My.class, ¡“jobs", ¡ ¡ ¡new ¡Gauge<Integer>() ¡{ ¡ ¡ ¡ ¡ ¡ ¡@Override ¡ ¡ ¡ ¡ ¡ ¡public ¡Integer ¡value() ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡queue.size(); ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡} ¡ ); ¡

  17. Counters ¡ Counter ¡pendingJobs ¡= ¡Metrics.newCounter(My.class, ¡“jobs"); ¡ ¡ public ¡void ¡addJob(Job ¡job) ¡{ ¡ ¡ ¡ ¡ ¡pendingJobs.inc(); ¡ ¡ ¡ ¡ ¡queue.offer(job); ¡ } ¡ ¡ public ¡Job ¡takeJob() ¡{ ¡ ¡ ¡ ¡ ¡pendingJobs.dec(); ¡ ¡ ¡ ¡ ¡return ¡queue.take(); ¡ } ¡

  18. Meters ¡ Meter ¡requests ¡= ¡Metrics.newMeter( ¡ ¡ ¡My.class, ¡"requests", ¡ ¡ ¡ ¡"requests", ¡TimeUnit.SECONDS); ¡ ¡ public ¡void ¡handleRequest(Request ¡request, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Response ¡response) ¡{ ¡ ¡ ¡ ¡ ¡requests.mark(); ¡ ¡ ¡ ¡ ¡// ¡etc ¡ } ¡

  19. Histograms ¡ Histogram ¡responseSizes ¡= ¡Metrics.newHistogram( ¡ ¡ ¡My.class, ¡"response-­‑sizes"); ¡ ¡ public ¡void ¡handleRequest(Request ¡request, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡Response ¡response) ¡{ ¡ ¡ ¡ ¡ ¡// ¡etc ¡ ¡ ¡ ¡ ¡int ¡length ¡= ¡response.getContent().length; ¡ ¡ ¡ ¡ ¡responseSizes.update(length); ¡ } ¡

  20. Timers ¡ Timer ¡responses ¡= ¡Metrics.newTimer(My.class, ¡"responses", ¡ ¡ ¡ ¡TimeUnit.MILLISECONDS, ¡TimeUnit.SECONDS); ¡ ¡ public ¡String ¡handleRequest(Request ¡request, ¡Response ¡response) ¡{ ¡ ¡ ¡ ¡ ¡final ¡TimerContext ¡context ¡= ¡responses.Ome(); ¡ ¡ ¡ ¡ ¡try ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡// ¡etc; ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡"OK"; ¡ ¡ ¡ ¡ ¡} ¡finally ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡context.stop(); ¡ ¡ ¡ ¡ ¡} ¡ } ¡

  21. Health ¡Checks ¡ public ¡class ¡DatabaseHealthCheck ¡extends ¡HealthCheck ¡{ ¡ ¡ ¡ ¡ ¡@Override ¡ ¡ ¡ ¡ ¡public ¡Result ¡check() ¡throws ¡ExcepOon ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡if ¡(database.isConnected()) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡Result.healthy(); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡else ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡Result.unhealthy("Cannot ¡connect ¡to ¡db”); ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡ ¡} ¡ } ¡

  22. “Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

  23. JMX ¡ReporOng ¡

  24. HTTP ¡ReporOng ¡

  25. Metrics ¡ hQp://host:adminPort/metrics ¡

  26. Metrics ¡reporters ¡can ¡be ¡added ¡to ¡ adapt ¡dropwizard ¡metrics ¡to ¡your ¡ collecOon ¡system ¡of ¡choice ¡

  27. Health ¡Checks ¡ hQp://host:adminPort/healthcheck ¡

  28. Thread ¡Dumps ¡ hQp://hostname:adminPort/threads ¡

  29. Ping ¡ hQp://hostname:adminPort/ping ¡

  30. “Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

  31. Dropwizard ¡provides ¡its ¡own ¡ applicaOon ¡logging ¡abstracOon ¡

  32. HTTP ¡request ¡logging ¡is ¡ supported ¡as ¡well ¡

  33. Dropwizard ¡provides ¡log ¡file ¡ rotaOon ¡and ¡compression ¡

  34. “Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

  35. The ¡unbeatable ¡Jackson ¡

  36. “Dropwizard ¡has ¡out-­‑of-­‑the-­‑box ¡ support ¡for ¡sophisOcated ¡ configuraOon, ¡applicaOon ¡metrics, ¡ logging, ¡operaOonal ¡tools, ¡and ¡much ¡ more, ¡allowing ¡you ¡and ¡your ¡team ¡ to ¡ship ¡a ¡producOon-­‑quality ¡HTTP +JSON ¡web ¡service ¡…” ¡

  37. Dropwizard ¡embeds ¡JeQy ¡for ¡all ¡ your ¡HTTP ¡serving ¡needs ¡

  38. JAX-­‑RS ¡(JSR-­‑311) ¡for ¡all ¡your ¡ RESTful ¡needs ¡

  39. @Path(“/users/{id}”) ¡ public ¡class ¡UserResource ¡{ ¡ ¡ ¡ ¡ ¡@GET ¡ ¡ ¡ ¡ ¡public ¡User ¡get(@PathParam(“id”) ¡long ¡id) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡db.findUserById(id); ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡ ¡ ¡ ¡@PUT ¡ ¡ ¡ ¡ ¡public ¡User ¡update(@PathParam(“id”) ¡long ¡id, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡User ¡user) ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡return ¡db.updateUser(id, ¡user); ¡ ¡ ¡ ¡ ¡} ¡ } ¡

  40. How ¡Yammer ¡uses ¡Dropwizard ¡

  41. Lots ¡of ¡small ¡services…16 ¡and ¡ counOng ¡

  42. Maven ¡is ¡our ¡friend ¡

  43. SOck ¡the ¡code ¡in ¡GitHub ¡

  44. Shade ¡your ¡JARs ¡

  45. Get ¡yourself ¡some ¡conOnuous ¡ integraOon ¡

  46. Write ¡yourself ¡a ¡startup ¡script ¡

  47. Have ¡a ¡good ¡deploy ¡story ¡

  48. Over ¡Ome, ¡Dropwizard ¡has ¡ grown ¡a ¡few ¡appendages ¡

  49. Dropwizard ¡Client ¡ HQpClient ¡or ¡JerseyClient ¡flavors ¡

  50. Dropwizard ¡DB ¡ JDBI ¡as ¡a ¡service ¡

  51. Dropwizard ¡AuthenOcaOon ¡ Abstracted ¡authenOcaOon…providers ¡ for ¡OAuth ¡2 ¡and ¡Basic ¡Auth ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend