Download - Переход на Scala: босиком по граблям
![Page 1: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/1.jpg)
Переход на Scala: босиком по граблям
![Page 2: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/2.jpg)
Data Processing Team
![Page 3: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/3.jpg)
Java / Scala / Clojure / Groovy / ?
JVM
![Page 4: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/4.jpg)
“Во-первых, это красиво…” *
Почему Scala?
![Page 5: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/5.jpg)
akka-http / spray / finagle / play
REST & HTTP
![Page 6: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/6.jpg)
Spray
![Page 7: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/7.jpg)
Implicits
![Page 8: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/8.jpg)
def strangeIdea(n: Int)(implicit s: String) = s * n
![Page 9: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/9.jpg)
package spray.routing
...
trait HttpServiceBase extends Directives {
/** * Supplies the actor behavior for executing the given route. */ def runRoute(route: Route)(implicit eh: ExceptionHandler, rh: RejectionHandler, ac: ActorContext, rs: RoutingSettings, log: LoggingContext): Actor.Receive = {...}
![Page 10: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/10.jpg)
def createOrUpdateCookieProfileRoute(): Route = post { pathPrefix(ApiVersion) { pathPrefix("cookies" / Segment) { cookieId => path("cookieProfiles" / IntNumber) { trackingSetupId => parameters('cookieSetTime.as[DateTime].?, 'cookieLastSeenTime.as[DateTime].?) { (cookieSetTime, cookieLastSeenTime) => entity(as[CookieProfile]) { cookieProfile => traceName("POST COOKIE PROFILE") { ctx => val serviceActor: ActorRef = newStorageServiceActor() val message = MergeCookieProfile(ctx, cookieProfile, cookieSetTime, cookieLastSeenTime) serviceActor.tell(message, ActorRef.noSender) } } } } } } }
![Page 11: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/11.jpg)
trait JsonSerializerSupport {
implicit val formats = DefaultFormats ++ BinaryTypeSerializers.all ++ JodaTimeSerializers.all}
![Page 12: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/12.jpg)
https://github.com/gettyimages/spray-swagger
Swagger
![Page 13: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/13.jpg)
@ApiOperation( httpMethod = "POST", value = "Create/Update CookieProfile by cookieId and trackingSetupId", notes = "Creates new CookieProfile if it doesn't exists or updates old one if it exists in storage.”) @ApiImplicitParams(Array( new ApiImplicitParam( name = Fields.CookieId, value = Description.CookieId, required = true, dataType = DataTypes.String, paramType = ParamType.Path), new ApiImplicitParam( name = Fields.TrackingSetupId, value = Description.TrackingSetupId, required = true, dataType = DataTypes.Integer, paramType = ParamType.Path), new ApiImplicitParam( name = Fields.CookieSetTime, value = Description.CookieSetTime, dataType = DataTypes.String, paramType = ParamType.Query), new ApiImplicitParam( name = Fields.CookieLastSeenTime, value = Description.CookieLastSeenTime, dataType = DataTypes.String, paramType = ParamType.Query), new ApiImplicitParam( name = Fields.Body, value = Description.Body, required = true, dataType = DataTypes.CookieProfile, paramType = ParamType.Body))) @ApiResponses(Array( new ApiResponse(code = 200, message = Responses.Ok, response = classOf[SuccessResponse]), new ApiResponse(code = 400, message = Responses.BadRequest, response = classOf[ErrorResponse]), new ApiResponse(code = 500, message = Responses.InternalError, response = classOf[ErrorResponse]), new ApiResponse(code = 503, message = Responses.ServiceUnavailable))) @Path("/{cookieId}/cookieProfiles/{trackingSetupId}")
![Page 14: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/14.jpg)
Akka
![Page 15: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/15.jpg)
“blocking problem”
![Page 16: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/16.jpg)
Shared state
![Page 17: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/17.jpg)
Как это тестировать?
![Page 18: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/18.jpg)
test("return 404 code for not existing cookie with cookieProfiles") { Get("/v1/cookies/777/cookieProfiles") ~> route ~> check { handled should be(right = true) response.status should be(StatusCodes.NotFound) } }
![Page 19: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/19.jpg)
http://gatling.io/
Нагрузочные тесты
![Page 20: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/20.jpg)
DevOps
![Page 21: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/21.jpg)
Отличное решение
Kamonhttp://kamon.io/
![Page 22: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/22.jpg)
Если вы сами готовы его допиливать
![Page 23: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/23.jpg)
ELK & Grafana
![Page 24: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/24.jpg)
Maven & sbt
![Page 25: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/25.jpg)
Что бы могло пойти не так?
Итак, вы решили перейти на Scala
![Page 26: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/26.jpg)
Сложность и академичность
![Page 27: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/27.jpg)
IDE
![Page 28: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/28.jpg)
OOP & FP
![Page 29: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/29.jpg)
Explicit is better than implicit
Много споров о стиле
![Page 30: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/30.jpg)
![Page 31: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/31.jpg)
Take it easy
![Page 32: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/32.jpg)
Плавный переход к Scala
![Page 33: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/33.jpg)
Инкрементальное внедрение языка
![Page 34: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/34.jpg)
Постоянное изучение
![Page 35: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/35.jpg)
“Технологии идеальны, а люди – *удаки” **
![Page 37: Переход на Scala: босиком по граблям](https://reader034.vdocuments.mx/reader034/viewer/2022042701/55a5c8a01a28abeb308b463c/html5/thumbnails/37.jpg)
* — Старый анекдот** — Baruch Sadogursky aka @jbaruch
Источники: