This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chunkedresponses | |
import akka.actor.ActorRef | |
import akka.util.Timeout | |
import akka.pattern.ask | |
import play.api.libs.iteratee.{Done, Step, Input, Iteratee} | |
import spray.http.HttpData | |
import scala.concurrent.duration._ | |
import scala.concurrent.{ExecutionContext, Future} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chunkedresponses | |
import akka.actor.{Actor, ActorRef} | |
import spray.http.HttpHeaders.RawHeader | |
import spray.http._ | |
object ChunkedResponder { | |
case class Chunk(data: HttpData) | |
case object Shutdown | |
case object Ack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.{ActorContext, ActorRefFactory, Props} | |
import play.api.libs.iteratee.Enumerator | |
import spray.http.{HttpData, ContentType} | |
import spray.routing.RequestContext | |
import scala.concurrent.ExecutionContext | |
package object chunkedresponses { | |
implicit class ChunkedRequestContext(requestContext: RequestContext) { | |
def completeChunked(contentType: ContentType, enumerator: Enumerator[HttpData]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.ActorSystem | |
import akka.stream.ActorFlowMaterializer | |
import akka.stream.scaladsl.{Flow, Sink, Source} | |
import scala.collection.immutable | |
import scala.util.Random | |
object InputCustomer { | |
def random():InputCustomer = { | |
InputCustomer(s"FirstName${Random.nextInt(1000)} LastName${Random.nextInt(1000)}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait UserStore { | |
def find(userId: UserId): Option[User] | |
def save(user: User): User | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait UserAddressStore { | |
def find(userId: UserId): Option[Address] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait UserStoreTests extends FreeSpec { | |
def userStore: UserStore | |
“find” - { | |
“should return a User when it exists in the store” in { | |
val user = User() // Let's ignore the details of what a user looks like or how it is constructed. | |
userStore.save(user) | |
val result = userStore.find(user.id) | |
assert(result === user) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MigratingUserStore(origin: UserStore, destination: UserStore) extends UserStore { | |
def find(userId: UserId): Option[User] = { | |
destination.find(userId) match { | |
case None => | |
origin.find(userId) | |
case result => | |
result.map(user => destination.save(user)) | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.typed.ScalaDSL._ | |
case class Message(value: String) | |
val behavior = Static[Message] { | |
case Message(value) => println(value) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.typed._ | |
val system = ActorSystem("MySystem", Props(behavior)) | |
system ! Message("Hello World") | |
system.terminate() |
OlderNewer