Skip to content

Instantly share code, notes, and snippets.

View krasserm's full-sized avatar

Martin Krasser krasserm

View GitHub Profile
// ###########################################################
//
// Demonstrates how to supervise an Akka consumer actor.
//
// The consumer consumes messages from a file endpoint:
// - successful message processing by the consumer will
// positively acknowledge the message receipt, causing
// the file endpoint to delete the file.
// - an exception during message processing will cause a
// supervisor to restart the consumer. Before restart,
@krasserm
krasserm / PromiseEither.scala
Created February 22, 2011 16:59
Composition of concurrent functions that may fail
import scalaz._
import Scalaz._
import scalaz.concurrent._
/**
* Result type of concurrent functions that may fail.
*/
case class PromiseEither[A, B](value: Promise[Either[A, B]]) extends NewType[Promise[Either[A, B]]]
/**
@krasserm
krasserm / CorrelationIdentifier.scala
Created February 28, 2011 06:36
Akka producer actors best practices - Part 2
httpProducer ! Message("test", Map(Message.MessageExchangeId -> 123))
@krasserm
krasserm / CamelContextManager.scala
Created February 28, 2011 06:29
Akka producer actors best practices - Part 1
CamelContextManager.init
CamelContextManager.start
@krasserm
krasserm / scalaz-camel-0.3.patch
Created April 14, 2011 15:54
Downgrade to Akka 1.0 and Scala 2.8.1
Index: project/build/Project.scala
===================================================================
--- project/build/Project.scala (date 1302329914000)
+++ project/build/Project.scala (revision )
@@ -3,9 +3,9 @@
class Project(info: ProjectInfo) extends DefaultProject(info) with IdeaProject with AkkaProject {
val ScalazVersion = "5.0"
val CamelVersion = "2.7.0"
- val AkkaVersion = "1.1-M1"
+ val AkkaVersion = "1.0"
@krasserm
krasserm / GCAuthExample.scala
Created July 5, 2011 17:53
GAE client login example
import org.apache.http.client.methods.HttpPost
import org.apache.http.client.params.ClientPNames._
import org.apache.http.client.HttpClient
import org.apache.http.entity.StringEntity
// other imports omitted ...
object GCAuthExample {
def main(args:Array[String]) {
@krasserm
krasserm / domain-01.scala
Created November 29, 2011 11:55
Building an event-sourced web application with Akka - Part 1
case class InvoiceAddress(street: String, city: String, country: String)
case class InvoiceItem(description: String, count: Int, amount: BigDecimal)
case class Invoice(
id: String,
items: List[InvoiceItem] = Nil,
discount: Option[BigDecimal] = None,
sentTo: Option[InvoiceAddress] = None) extends EventSourced[InvoiceEvent, Invoice] {
def addItem(item: InvoiceItem): Update[InvoiceEvent, Invoice] = ...
@krasserm
krasserm / service-01.scala
Created November 29, 2011 12:03
Building an event-sourced web application with Akka - Part 1
class InvoiceService {
val invoicesRef = Ref(Map.empty[String, Invoice]) // naive approach
// ...
}
@krasserm
krasserm / service-01.scala
Created January 20, 2012 16:52
Building an event-sourced web application with Akka - Part 2
import akka.actor._
import akka.dispatch._
import akka.stm._
import scalaz._
trait Projection[S, A] {
def initialState: S
def currentState: S
def project: PartialFunction[(S, A), S]
@krasserm
krasserm / jaxb-01.scala
Created February 23, 2012 08:23
JAXB-based XML and JSON APIs
import javax.xml.bind.annotation._
@XmlRootElement(name = "person")
@XmlAccessorType(XmlAccessType.FIELD)
case class Person(fullname: String, username: Option[String], age: Int)