Overview of ReactiveMongo - an asynchronous driver for MongoDB written in Scala. Covers the basics of using the driver as well as the Play ReactiveMongo plugin via a sample application. Covers ReactiveMongo 0.9 and Play Framework 2.1.
'Reactive' - new buzzword • Progressive Stream Processing • No blocking/polling • Written on top of Akka • Driver is composed of an ActorSystem and various Actors • http://reactivemongo.org/
BSON • Core BSON Library for the project • Can be used separately - only dependency is Scala itself • ReactiveMongo BSON Macros • Uses compile-time macros to introspect your classes and generate your Readers/Writers on the fly • Similar to Play 2.1 JSON Macros • ReactiveMongo (core) • Plugin • Play-ReactiveMongo • Provides helpers for Play Applications • MongoController • Adds BSON -> JSON implicits • Provides JSONCollection
Clojure, JRuby, etc) • Created by Martin Odersky in 2004 • Martin was involved with evolution of Java (i.e. Generics) • Mostly had academic use until recently • Hybrid Language: Functional & Object Oriented • Under Direction of Typesafe (http://typesafe.com) • Includes Odersky himself, as well as Rod Johnson and James Gosling as board members/Advisors • Source Code: https://github.com/scala/scala
organizations/start ups in production today • Increased Developer Productivity • Scales Extremely Well • Twitter is best example • Easily Build Concurrent Code • Case Studies: http:// typesafe.com/company/ casestudies
Virtual Machine (JVM) • Easy Interop with Java (bi-directional) • Command-line REPL • Everything is an Object (including Functions!) • Statically Typed • Keywords to identify singletons and immutable variables (val vs var) • Modern syntax - similar to Java/C and other {}'s - but lacks the verbosity (unless you want it) • Modern Language Features (for comprehensions, options, futures, actors, lazy initialization, etc) • No interfaces - 'traits' instead • aka 'mix-in' • Pattern Matching • High Order Functions (easily compose new functions from existing - with type safety)
a Scala black-belt (yet) :) • Cheat Sheet for some core ideas you'll see tonight: • val • keyword that defined an immutable variable • map • function on 'collections' and other 'special' classes (Future, Option and Try) that allow you to convert the value(s) within the said 'collection' to something else • Option • Indicates a function returned either Some(x) or None (something or nothing) • Future • Contains a Promise that holds a reference to a value you're going to receive...eventually • Try • Indicates that the results of a function was either a Success(x) or Failure(exception) • '_' • Pattern matcher for anything, similar to '*' in other languages
Typesafe • Lightweight • No JEE here! • Built on Netty (future versions to be built on akka-io) • Command-line tools to generate project scaffolding and manage build/deploy • leverages sbt under the hood • Powerful, type-safe JSON library • Iteratee/Enumeratee
transform streams of data • All data sources are handled the same (files, websockets, etc) • Asynchronous/Non-blocking • Can be used w/o Play Framework (stand alone lib) • sbt: "play" %% "play-iteratees" % "2.1.3" • http://www.playframework.com/documentation/2.1.x/Iteratees
the way input will be consumed to produce a given value • ie. Iteratee[String,Int] - consumes a String and returns an Int • states • Cont - able to process input • Error - error state • Done - completed stream processing • Enumerator • Pushes data into the Iteratee; producer • Returns the state of the Iteratee when completed • Enumeratee • adapts and transforms stream of data • Enumeratee[From, To] • used by Iteratee
of the Core library (BSONDocuments, queries and use of an Iteratee to read results) • Play Plugin (https://gist.github.com/tdrozdowski/4451005fb1f31c730f75) • Configuration • How to set this up properly • MongoController • Demonstrates use of the JSONCollection • GridFS • Demonstrates use of the GridFS BodyParser • Tailable Cursor • Demonstrates use of Play's WebSocket support with ReactiveMongo's tailable cursor support. • GitHub Code: • reactivePlay ( https://github.com/tdrozdowski/reactivePlay ) • reactiveWeb ( https://github.com/tdrozdowski/reactiveWeb )
used in samples tonight • 0.10-SNAPSHOT is 'bleeding edge' • contains some API changes :( • Upgrade to Akka 2.2 • 1.0 • Performance Enhancements • Command Refactoring (make them more generic - like collections are) • Improved Authentication API • Bug Fixes • beyond... • remove Netty entirely and build upon Akka-io • Allow for integration with other 'useful' libraries such as: • Rogue • Casbah Query DSL