SlideShare uma empresa Scribd logo
1 de 40
Baixar para ler offline
PLAY IN PRACTICE/Will Sargent @will_sargent
PREAMBLE
This is going to be a broad talk.
USAGE
This talk does not attempt to be universal to all situations.
YMMV.
WHAT IS PLAY?
Play is a web application framework.
THESIS STATEMENT
Play is awesome.
WHY PLAY IS AWESOME?
Because Play is Simple.
HERE'S WHAT PLAY DOES:
Takes in an HTTP request.
Returns (or streams) a response.
HERE'S WHAT PLAY DOESN'T DO:
It doesn't tie an HTTP request to a thread.
It doesn't tie an HTTP session to memory.
It doesn't assume you want convenient but unsafe
practices.
It doesn't mandate a particular object relational
framework.
It doesn't mandate a particular template library.
It doesn't mandate a particular routing format.
HERE'S WHAT PLAY PROVIDES AS OPTIONS:
"Always-on" Build System
HTTP API
Templates
Form Handling
JSON support
BUILD SYSTEM
Modified SBT, recompiles pages on the fly in development
mode.
Type "play idea" or "play eclipse" to generate the files for
your IDE.
FRONT CONTROLLER
Routing API (with LangPathBindable and
QueryStringBindable)
Action: asynchronous and stateless by default.
Immutable HTTP: cookies, request, response, headers, etc.
Backed by Akka and Netty.
PRESENTATION
Compiled template language (Twirl, Scaml, Jade).
Built-in helpers for rendering forms.
Support for Twitter Bootstrap, LESS, jQuery, etc.
JSON
Formatting to JSON
Parsing of JSON objects
JsPath, automatic validation, read and write combinators
SO, WHY DOES THIS MATTER?
THE BUSINESS REQUEST
Make a website!
MAKE TWO WEBSITES!
Product
Admin
MAKE MORE WEBSITES!
Product
Admin
Customer Service
Business Analytics
Business Content
Jobs Queue
THE PROBLEM
In a complex web application, many different front ends need
to look at the same data, from different angles.
Touching the database directly is dangerous and messy.
THE SOLUTION
In complex applications, use loosely coupled, stateless,
composable services.
HOW?
Create a Play HTTP front end, backed by Akka.
Create a business domain services, backed by Akka.
Use Akka to pass messages between Play and the domain
services.
Present information using query services.
ALAN KAY ON OOP
“ I thought of objects being like biological cells
and/or individual computers on a network,
only able to communicate with messages (so
messaging came at the very beginning -- it
took a while to see how to do messaging in a
programming language efficiently enough to
be useful). ”
COMMAND / QUERY RESPONSIBILITY
SEGREGATION (CQRS)
Command: a message intending a change of state.
Event: a message indicating that state has changed.
Fault: a message indicating failure to execute a command.
CQRS MAPPED ONTO PLAY
Processing Commands using POST
Querying for Data with GET
Broadcasting Events with Streaming
PROCESSING COMMANDS
Validate all input.
where possible.
Be very careful when handling passwords and credit card
numbers.
Use value classes
COMMANDS
def sendCommand(command : Command) : Future[Either[Fault,Event]]
CQRS
COMMAND
trait Command extends Product
sealed abstract class AuthenticationCommand extends Command
case class AuthenticateWithPasswordCommand(email:Email,
password:String,
rememberMe:Boolean)
extends AuthenticationCommand {
override def toString = "AuthenticateWithPasswordCommand("
+ email + "," + rememberMe + ")"
}
EVENT
case class UserAuthenticatedEvent(userId: UserID,
series: Option[Long] = None,
token: Option[Long] = None)
extends AuthenticationEvent
FAULT
trait AuthenticationFault
case class InvalidSessionCookieFault() extends AuthenticationFault
QUERY
case class UserInfo(id: UUID, email: Email, fullName: String)
class UserInfoService {
def lookup(uuid: UUID)(implicit c:Credentials): Option[UserInfo]
def findByName(name: String)(implicit c:Credentials) : TraversableOnce[UserIn
}
QUERY PRACTICES:
Objects should be immutable
Return ranges or streams over unbounded lists.
Don't expose repository logic (i.e. HQL, CQL, etc)
Making a good query builder is hard; avoid yak shaving.
CONTEXT AND AUTHENTICATION
Use or to set up a
WrappedRequest context.
Pass the request context around implicitly in every
template.
The request context will contain all the state you need (i.e.
Credentials).
Make helpers take the context as an implicit as needed.
Sidenote: helpers are great for keeping logic out of
templates.
play2-rememberme SecureSocial
EXAMPLE TEMPLATE
@(u: UserInfo)(implicit ctx: Context)
@layout(title = "User Page") {
@ctx.me.map { u =>
<p>
This is your user page.
</p>
}
<p>
User page of @{u.fullName}.
</p>
}
STREAMING
You send an event.
Event goes through an Iteratee.
Iteratee broadcasts event using Socket and Hub model.
Play uses Server Sent Events to stream JSON to clients
Javascript picks up that JSON from SSE, handles display.
is the best reference.
Sidenote: also check out
lila
vert.x
EVERYTHING ELSE
Logging
Metrics
Testing
LOGGING
Play's internal logger isn't the greatest.
Fortunately, it's not hardcoded and you can ignore it.
Make your own wrapper over SF4LJ & Logback (or
grizzled, or typesafe logging).
METRICS
has a Scala option.
Map it through Global's onRequest method.
Metrics
TESTING
Unit testing a stateless app is very easy.
Swapping out services with mocks/stubs may be easier
with DI (I use Subcut).
Functional and integration testing with FakeRequest and
Fluentlenium almost painless.
LOAD TESTING
Use jconsole and .
Don't know how useful Typesafe Console is.
Apache JMeter
QUESTIONS?
There's an award!

Mais conteúdo relacionado

Mais procurados

How to Think Like the SQL Server Engine
How to Think Like the SQL Server EngineHow to Think Like the SQL Server Engine
How to Think Like the SQL Server EngineBrent Ozar
 
React & Redux JS
React & Redux JS React & Redux JS
React & Redux JS Hamed Farag
 
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 MinutesDjangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 MinutesNina Zakharenko
 
The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedykrivachy
 
Getting hooked on performance and clean code
Getting hooked on performance and clean codeGetting hooked on performance and clean code
Getting hooked on performance and clean codeSeven Peaks Speaks
 
Time to React!
Time to React!Time to React!
Time to React!STX Next
 
New and improved hacking oracle from web apps sumit sidharth
New and improved hacking oracle from web apps   sumit sidharthNew and improved hacking oracle from web apps   sumit sidharth
New and improved hacking oracle from web apps sumit sidharthowaspindia
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to AkkaKnoldus Inc.
 
Memory Management In Swift
Memory Management In SwiftMemory Management In Swift
Memory Management In SwiftHossam Ghareeb
 
Why you shouldn’t edit silver stripe core files (and how to do it anyway)
Why you shouldn’t edit silver stripe core files (and how to do it anyway)Why you shouldn’t edit silver stripe core files (and how to do it anyway)
Why you shouldn’t edit silver stripe core files (and how to do it anyway)Loz Calver
 
Reactive programming with akka
Reactive programming with akka Reactive programming with akka
Reactive programming with akka Sovon Nath
 
Automated testing with RSpec
Automated testing with RSpecAutomated testing with RSpec
Automated testing with RSpecNascenia IT
 
User Credential handling in Web Applications done right
User Credential handling in Web Applications done rightUser Credential handling in Web Applications done right
User Credential handling in Web Applications done righttladesignz
 
[143]Inside fuse deview 2016
[143]Inside fuse   deview 2016[143]Inside fuse   deview 2016
[143]Inside fuse deview 2016NAVER D2
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST FrameworkLoad Impact
 
Recipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendRecipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendKarsten Thoms
 

Mais procurados (20)

How to Think Like the SQL Server Engine
How to Think Like the SQL Server EngineHow to Think Like the SQL Server Engine
How to Think Like the SQL Server Engine
 
Go database/sql
Go database/sqlGo database/sql
Go database/sql
 
React & Redux JS
React & Redux JS React & Redux JS
React & Redux JS
 
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 MinutesDjangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
Djangocon 2014 - Django REST Framework - So Easy You Can Learn it in 25 Minutes
 
Memory management ARC
Memory management ARCMemory management ARC
Memory management ARC
 
The dark side of Akka and the remedy
The dark side of Akka and the remedyThe dark side of Akka and the remedy
The dark side of Akka and the remedy
 
Getting hooked on performance and clean code
Getting hooked on performance and clean codeGetting hooked on performance and clean code
Getting hooked on performance and clean code
 
Time to React!
Time to React!Time to React!
Time to React!
 
New and improved hacking oracle from web apps sumit sidharth
New and improved hacking oracle from web apps   sumit sidharthNew and improved hacking oracle from web apps   sumit sidharth
New and improved hacking oracle from web apps sumit sidharth
 
Introduction to Akka
Introduction to AkkaIntroduction to Akka
Introduction to Akka
 
Memory Management In Swift
Memory Management In SwiftMemory Management In Swift
Memory Management In Swift
 
Why you shouldn’t edit silver stripe core files (and how to do it anyway)
Why you shouldn’t edit silver stripe core files (and how to do it anyway)Why you shouldn’t edit silver stripe core files (and how to do it anyway)
Why you shouldn’t edit silver stripe core files (and how to do it anyway)
 
Reactive programming with akka
Reactive programming with akka Reactive programming with akka
Reactive programming with akka
 
Day 4 - Models
Day 4 - ModelsDay 4 - Models
Day 4 - Models
 
Automated testing with RSpec
Automated testing with RSpecAutomated testing with RSpec
Automated testing with RSpec
 
Orchestration
OrchestrationOrchestration
Orchestration
 
User Credential handling in Web Applications done right
User Credential handling in Web Applications done rightUser Credential handling in Web Applications done right
User Credential handling in Web Applications done right
 
[143]Inside fuse deview 2016
[143]Inside fuse   deview 2016[143]Inside fuse   deview 2016
[143]Inside fuse deview 2016
 
Django REST Framework
Django REST FrameworkDjango REST Framework
Django REST Framework
 
Recipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with XtendRecipes to build Code Generators for Non-Xtext Models with Xtend
Recipes to build Code Generators for Non-Xtext Models with Xtend
 

Semelhante a Play in practice

PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operationsgrim_radical
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And DesignYaroslav Tkachenko
 
Play framework productivity formula
Play framework   productivity formula Play framework   productivity formula
Play framework productivity formula Sorin Chiprian
 
[PASS Summit 2016] Blazing Fast, Planet-Scale Customer Scenarios with Azure D...
[PASS Summit 2016] Blazing Fast, Planet-Scale Customer Scenarios with Azure D...[PASS Summit 2016] Blazing Fast, Planet-Scale Customer Scenarios with Azure D...
[PASS Summit 2016] Blazing Fast, Planet-Scale Customer Scenarios with Azure D...Andrew Liu
 
Systems Bioinformatics Workshop Keynote
Systems Bioinformatics Workshop KeynoteSystems Bioinformatics Workshop Keynote
Systems Bioinformatics Workshop KeynoteDeepak Singh
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersoazabir
 
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingJava Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingTal Melamed
 
Data Streaming Technology Overview
Data Streaming Technology OverviewData Streaming Technology Overview
Data Streaming Technology OverviewDan Lynn
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojureJohn Stevenson
 
Taming Deployment With Smart Frog
Taming Deployment With Smart FrogTaming Deployment With Smart Frog
Taming Deployment With Smart FrogSteve Loughran
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneKonrad Malawski
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performanceAndrew Rota
 
XPages Blast - ILUG 2010
XPages Blast - ILUG 2010XPages Blast - ILUG 2010
XPages Blast - ILUG 2010Tim Clark
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaYevgeniy Brikman
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the wayOleg Podsechin
 

Semelhante a Play in practice (20)

PuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into OperationsPuppetDB: Sneaking Clojure into Operations
PuppetDB: Sneaking Clojure into Operations
 
Dev381.Pp
Dev381.PpDev381.Pp
Dev381.Pp
 
Akka Microservices Architecture And Design
Akka Microservices Architecture And DesignAkka Microservices Architecture And Design
Akka Microservices Architecture And Design
 
Play framework productivity formula
Play framework   productivity formula Play framework   productivity formula
Play framework productivity formula
 
[PASS Summit 2016] Blazing Fast, Planet-Scale Customer Scenarios with Azure D...
[PASS Summit 2016] Blazing Fast, Planet-Scale Customer Scenarios with Azure D...[PASS Summit 2016] Blazing Fast, Planet-Scale Customer Scenarios with Azure D...
[PASS Summit 2016] Blazing Fast, Planet-Scale Customer Scenarios with Azure D...
 
Systems Bioinformatics Workshop Keynote
Systems Bioinformatics Workshop KeynoteSystems Bioinformatics Workshop Keynote
Systems Bioinformatics Workshop Keynote
 
Scaling asp.net websites to millions of users
Scaling asp.net websites to millions of usersScaling asp.net websites to millions of users
Scaling asp.net websites to millions of users
 
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-TestingJava Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
Java Hurdling: Obstacles and Techniques in Java Client Penetration-Testing
 
MeteorJS Introduction
MeteorJS IntroductionMeteorJS Introduction
MeteorJS Introduction
 
Data Streaming Technology Overview
Data Streaming Technology OverviewData Streaming Technology Overview
Data Streaming Technology Overview
 
Functional web with clojure
Functional web with clojureFunctional web with clojure
Functional web with clojure
 
Play framework
Play frameworkPlay framework
Play framework
 
Taming Deployment With Smart Frog
Taming Deployment With Smart FrogTaming Deployment With Smart Frog
Taming Deployment With Smart Frog
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
 
Cloud Talk
Cloud TalkCloud Talk
Cloud Talk
 
Ten practical ways to improve front-end performance
Ten practical ways to improve front-end performanceTen practical ways to improve front-end performance
Ten practical ways to improve front-end performance
 
XPages Blast - ILUG 2010
XPages Blast - ILUG 2010XPages Blast - ILUG 2010
XPages Blast - ILUG 2010
 
Play Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and ScalaPlay Framework: async I/O with Java and Scala
Play Framework: async I/O with Java and Scala
 
Sling pipes
Sling pipesSling pipes
Sling pipes
 
Server side JavaScript: going all the way
Server side JavaScript: going all the wayServer side JavaScript: going all the way
Server side JavaScript: going all the way
 

Último

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DaySri Ambati
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 

Último (20)

SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo DayH2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
H2O.ai CEO/Founder: Sri Ambati Keynote at Wells Fargo Day
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 

Play in practice

  • 1. PLAY IN PRACTICE/Will Sargent @will_sargent
  • 2. PREAMBLE This is going to be a broad talk.
  • 3. USAGE This talk does not attempt to be universal to all situations. YMMV.
  • 4. WHAT IS PLAY? Play is a web application framework.
  • 6. WHY PLAY IS AWESOME? Because Play is Simple.
  • 7. HERE'S WHAT PLAY DOES: Takes in an HTTP request. Returns (or streams) a response.
  • 8. HERE'S WHAT PLAY DOESN'T DO: It doesn't tie an HTTP request to a thread. It doesn't tie an HTTP session to memory. It doesn't assume you want convenient but unsafe practices. It doesn't mandate a particular object relational framework. It doesn't mandate a particular template library. It doesn't mandate a particular routing format.
  • 9. HERE'S WHAT PLAY PROVIDES AS OPTIONS: "Always-on" Build System HTTP API Templates Form Handling JSON support
  • 10. BUILD SYSTEM Modified SBT, recompiles pages on the fly in development mode. Type "play idea" or "play eclipse" to generate the files for your IDE.
  • 11. FRONT CONTROLLER Routing API (with LangPathBindable and QueryStringBindable) Action: asynchronous and stateless by default. Immutable HTTP: cookies, request, response, headers, etc. Backed by Akka and Netty.
  • 12. PRESENTATION Compiled template language (Twirl, Scaml, Jade). Built-in helpers for rendering forms. Support for Twitter Bootstrap, LESS, jQuery, etc.
  • 13. JSON Formatting to JSON Parsing of JSON objects JsPath, automatic validation, read and write combinators
  • 14. SO, WHY DOES THIS MATTER?
  • 17. MAKE MORE WEBSITES! Product Admin Customer Service Business Analytics Business Content Jobs Queue
  • 18. THE PROBLEM In a complex web application, many different front ends need to look at the same data, from different angles. Touching the database directly is dangerous and messy.
  • 19. THE SOLUTION In complex applications, use loosely coupled, stateless, composable services.
  • 20. HOW? Create a Play HTTP front end, backed by Akka. Create a business domain services, backed by Akka. Use Akka to pass messages between Play and the domain services. Present information using query services.
  • 21. ALAN KAY ON OOP “ I thought of objects being like biological cells and/or individual computers on a network, only able to communicate with messages (so messaging came at the very beginning -- it took a while to see how to do messaging in a programming language efficiently enough to be useful). ”
  • 22. COMMAND / QUERY RESPONSIBILITY SEGREGATION (CQRS) Command: a message intending a change of state. Event: a message indicating that state has changed. Fault: a message indicating failure to execute a command.
  • 23. CQRS MAPPED ONTO PLAY Processing Commands using POST Querying for Data with GET Broadcasting Events with Streaming
  • 24. PROCESSING COMMANDS Validate all input. where possible. Be very careful when handling passwords and credit card numbers. Use value classes
  • 25. COMMANDS def sendCommand(command : Command) : Future[Either[Fault,Event]]
  • 26. CQRS
  • 27. COMMAND trait Command extends Product sealed abstract class AuthenticationCommand extends Command case class AuthenticateWithPasswordCommand(email:Email, password:String, rememberMe:Boolean) extends AuthenticationCommand { override def toString = "AuthenticateWithPasswordCommand(" + email + "," + rememberMe + ")" }
  • 28. EVENT case class UserAuthenticatedEvent(userId: UserID, series: Option[Long] = None, token: Option[Long] = None) extends AuthenticationEvent
  • 29. FAULT trait AuthenticationFault case class InvalidSessionCookieFault() extends AuthenticationFault
  • 30. QUERY case class UserInfo(id: UUID, email: Email, fullName: String) class UserInfoService { def lookup(uuid: UUID)(implicit c:Credentials): Option[UserInfo] def findByName(name: String)(implicit c:Credentials) : TraversableOnce[UserIn }
  • 31. QUERY PRACTICES: Objects should be immutable Return ranges or streams over unbounded lists. Don't expose repository logic (i.e. HQL, CQL, etc) Making a good query builder is hard; avoid yak shaving.
  • 32. CONTEXT AND AUTHENTICATION Use or to set up a WrappedRequest context. Pass the request context around implicitly in every template. The request context will contain all the state you need (i.e. Credentials). Make helpers take the context as an implicit as needed. Sidenote: helpers are great for keeping logic out of templates. play2-rememberme SecureSocial
  • 33. EXAMPLE TEMPLATE @(u: UserInfo)(implicit ctx: Context) @layout(title = "User Page") { @ctx.me.map { u => <p> This is your user page. </p> } <p> User page of @{u.fullName}. </p> }
  • 34. STREAMING You send an event. Event goes through an Iteratee. Iteratee broadcasts event using Socket and Hub model. Play uses Server Sent Events to stream JSON to clients Javascript picks up that JSON from SSE, handles display. is the best reference. Sidenote: also check out lila vert.x
  • 36. LOGGING Play's internal logger isn't the greatest. Fortunately, it's not hardcoded and you can ignore it. Make your own wrapper over SF4LJ & Logback (or grizzled, or typesafe logging).
  • 37. METRICS has a Scala option. Map it through Global's onRequest method. Metrics
  • 38. TESTING Unit testing a stateless app is very easy. Swapping out services with mocks/stubs may be easier with DI (I use Subcut). Functional and integration testing with FakeRequest and Fluentlenium almost painless.
  • 39. LOAD TESTING Use jconsole and . Don't know how useful Typesafe Console is. Apache JMeter