SlideShare a Scribd company logo
ElasticMQ
a fully async, Akka-based
Amazon SQS server
Adam Warski
SoftwareMill

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
What is Amazon SQS?

• MQ-as-a-service
• Send, Receive, Delete
• At-least-once delivery

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
How to test SQS apps?

1. Don’t?

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
How to test SQS apps?

2. Just use SQS?

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
How to test SQS apps?

3. Use a local SQS server

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
ElasticMQ

• (relevant) subset of SQS
• In-memory
• Lightweight

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Stand-alone
$	
  java	
  -­‐jar	
  elasticmq-­‐server-­‐0.7.1.jar
[main]	
  INFO	
  	
  org.elasticmq.server.Main$	
  -­‐	
  Starting	
  ElasticMQ	
  
server	
  (0.7.1)	
  ...
[main]	
  INFO	
  	
  o.e.rest.sqs.TheSQSRestServerBuilder	
  -­‐	
  Started	
  SQS	
  
rest	
  server,	
  bind	
  address	
  0.0.0.0:9324,	
  visible	
  server	
  address	
  
http://localhost:9324
[main]	
  INFO	
  	
  org.elasticmq.server.Main$	
  -­‐	
  ===	
  ElasticMQ	
  server	
  
(0.7.1)	
  started	
  in	
  1444	
  ms	
  ===
#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Using ElasticMQ
import	
  com.amazonaws.auth.BasicAWSCredentials
import	
  com.amazonaws.services.sqs.AmazonSQSClient
client	
  =	
  new	
  AmazonSQSClient(new	
  BasicAWSCredentials("x",	
  "x"))
client.setEndpoint("http://localhost:9324")
val	
  queueUrl	
  =	
  client.createQueue(
new	
  CreateQueueRequest("testQueue1"))
client.sendMessage(new	
  SendMessageRequest(queueUrl,	
  "Hello!"))

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Embedded
<dependency>
	
  	
  	
  <groupId>org.elasticmq</groupId>
	
  	
  	
  <artifactId>elasticmq-­‐rest-­‐sqs_2.10</artifactId>
	
  	
  	
  <version>0.7.1</version>
</dependency>
val	
  server	
  =	
  SQSRestServerBuilder
	
  	
  	
  .withPort(9325)
	
  	
  	
  .withInterface("localhost")
	
  	
  	
  .start()
//	
  ...	
  use	
  ...
server.stopAndWait()
#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
That’s all!
Thanks!
#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Technologies

• Scala
• Akka
• Spray

#DV13 #elasticmq
Wednesday 13 November 13

➡ reactive

@adamwarski
Asynchronous: why?

• Traditional model could work well?
• Long polling

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Receive message walk-through
import	
  spray.routing.SimpleRoutingApp
val	
  routes	
  =	
  sendMessage	
  ~	
  receiveMessage	
  ~	
  createQueue	
  ~	
  ...
val	
  app	
  =	
  new	
  SimpleRoutingApp	
  {}
app.startServer(interface,	
  port,	
  "...")	
  {
	
  	
  	
  routes
}

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Receive message walk-through
val	
  receiveMessage	
  =
	
  	
  action("ReceiveMessage")	
  {	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  //	
  path("")	
  and	
  param()
	
  	
  	
  	
  param("VisibilityTimeout".as[Int]?,	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  "WaitTimeSeconds".as[Long]?)	
  {
	
  	
  	
  	
  	
  	
  (visibilityTimeout,	
  waitTimeSeconds)	
  =>
	
  	
  
	
  	
  	
  	
  	
  	
  respondWithMediaType(MediaTypes.`text/xml`)	
  {
	
  	
  	
  	
  	
  	
  	
  	
  //	
  inner	
  route:	
  RequestContext	
  =>	
  Unit	
  	
  	
  	
  	
  	
  
	
  	
  	
  	
  	
  	
  }
	
  	
  	
  	
  }
	
  	
  }
#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Receive message walk-through
//	
  inner	
  route:	
  RequestContext	
  =>	
  Unit
ctx:	
  RequestContext	
  =>
	
  	
  val	
  actorMsg	
  =	
  ReceiveMessages(visibilityTimeout,	
  	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  waitTimeSeconds)
	
  	
  val	
  msgs:	
  Future[List[Message]]	
  =	
  queueActor	
  ?	
  actorMsg
	
  	
  msgs.map	
  {	
  msgs	
  =>
	
  	
  	
  	
  ctx.complete(
	
  	
  	
  	
  	
  	
  <ReceiveMessageResponse>
	
  	
  	
  	
  	
  	
  	
  	
  ...
	
  	
  	
  	
  	
  	
  </ReceiveMessageResponse>	
  
	
  	
  	
  	
  )	
  }
#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Receive message walk-through
import	
  akka.actor.{Actor,	
  ActorRef}
class	
  QueueActor	
  extends	
  Actor	
  {
	
  	
  val	
  messageQueue	
  =	
  mutable.PriorityQueue[InternalMessage]()
	
  	
  val	
  awaiting	
  =	
  mutable.PriorityQueue[ActorRef]()
	
  	
  def	
  receive	
  =	
  {
	
  	
  	
  	
  case	
  ReceiveMessages(...)	
  =>	
  {
	
  	
  	
  	
  	
  	
  //	
  if	
  there	
  are	
  messages,	
  reply
	
  	
  	
  	
  	
  	
  //	
  otherwise	
  put	
  the	
  sender	
  aside
	
  	
  	
  	
  	
  //	
  schedule	
  a	
  timeout	
  in	
  20	
  seconds
	
  	
  }	
  }	
  }
#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Dataflow

• Write async code as if it
was sync!

• Many Futures, if-s =>
trouble

• Alternative: Scala Async
#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Dataflow
val	
  result:	
  Future[ActorRef]	
  =	
  flow	
  {
	
  (queueManager	
  ?	
  Lookup(name)).apply()	
  match	
  {
	
  	
  	
  case	
  Some(queueActor)	
  =>	
  queueActor
	
  	
  	
  case	
  None	
  =>	
  
	
  	
  	
  	
  	
  val	
  createFuture	
  =	
  queueManager	
  ?	
  Create(name)
	
  	
  	
  	
  	
  createFuture.apply()
	
  }
}

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Links

• http://github.com/adamw/elasticmq
• http://akka.io/
• http://spray.io/
• http://warski.org

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
There’s more!

• “The ideal module system
and the harsh reality”

• Today, 17:50, Room 9

#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski
Thank you; Come & get a sticker

http://codebrag.com/devoxx/
#DV13 #elasticmq
Wednesday 13 November 13

@adamwarski

More Related Content

PDF
Scala Macros
PDF
Realm database
PDF
Angular - Chapter 2 - TypeScript Programming
PDF
Java, what's next?
PPTX
Speaking Scala: Refactoring for Fun and Profit (Workshop)
PDF
Introduction to Scala
PDF
Advanced realm in swift
KEY
Wider than rails
Scala Macros
Realm database
Angular - Chapter 2 - TypeScript Programming
Java, what's next?
Speaking Scala: Refactoring for Fun and Profit (Workshop)
Introduction to Scala
Advanced realm in swift
Wider than rails

What's hot (20)

PDF
camel-scala.pdf
PPTX
Javascript asynchronous
ODP
10 Things I Hate About Scala
PDF
Elm dev front-end
PPTX
TypeScript
PDF
Introduction to Scala : Clueda
PDF
Mini Rails Framework
PPT
AS3Commons Introduction
PDF
Elm kyivfprog 2015
PPTX
Introduction to es6
PDF
Introduction to Elm
PPT
JavaScript - An Introduction
PDF
[Start] Scala
PPTX
002. Introducere in type script
PDF
Scala : language of the future
PDF
SE 20016 - programming languages landscape.
PDF
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
PDF
Connect.Tech- Swift Memory Management
PDF
Elixir and Phoenix for Rubyists
PPTX
Javascript Basics by Bonny
camel-scala.pdf
Javascript asynchronous
10 Things I Hate About Scala
Elm dev front-end
TypeScript
Introduction to Scala : Clueda
Mini Rails Framework
AS3Commons Introduction
Elm kyivfprog 2015
Introduction to es6
Introduction to Elm
JavaScript - An Introduction
[Start] Scala
002. Introducere in type script
Scala : language of the future
SE 20016 - programming languages landscape.
Connect.Tech- Enhancing Your Workflow With Xcode Source Editor Extensions
Connect.Tech- Swift Memory Management
Elixir and Phoenix for Rubyists
Javascript Basics by Bonny
Ad

Viewers also liked (6)

PDF
Revitalizing Walmart's Aging Architecture for Web Scale
PDF
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...
PDF
Microservices, Monoliths, SOA and How We Got Here
PDF
Real-Time Anomaly Detection with Spark MLlib, Akka and Cassandra
PDF
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
PDF
Streaming Analytics with Spark, Kafka, Cassandra and Akka
Revitalizing Walmart's Aging Architecture for Web Scale
Akka Revealed: A JVM Architect's Journey From Resilient Actors To Scalable Cl...
Microservices, Monoliths, SOA and How We Got Here
Real-Time Anomaly Detection with Spark MLlib, Akka and Cassandra
Lambda Architecture with Spark, Spark Streaming, Kafka, Cassandra, Akka and S...
Streaming Analytics with Spark, Kafka, Cassandra and Akka
Ad

Similar to ElasticMQ: a fully asynchronous, Akka-based SQS server (20)

PDF
Scaling with Scala: refactoring a back-end service into the mobile age
PPTX
Introduction to EMQ X Enterprise
 
PDF
IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...
PDF
Messaging with RabbitMQ and AMQP
PDF
ElasticMQ : Server for Local SQS
PDF
Evaluating persistent, replicated message queues
PDF
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
PDF
The Future of Messaging: RabbitMQ and AMQP
PDF
Reactive programming with akka
PDF
Reactive Programming in Akka
PDF
VerneMQ @ Paris Erlang User Group June 29th 2015
PDF
Verne mq @ paris erlang user group
PDF
From polling to real time: Scala, Akka, and Websockets from scratch
PDF
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
ODP
Scala.io 2013 - Scala and ZeroMQ: Events beyond the JVM
PDF
Microservices in Scala: Play Framework
PDF
Activator and Reactive at Play NYC meetup
PDF
Scaling out eclipse hono
PPT
Easy enterprise application integration with RabbitMQ and AMQP
PDF
Zeromq Messaging For Many Applications Pieter Hintjens
Scaling with Scala: refactoring a back-end service into the mobile age
Introduction to EMQ X Enterprise
 
IBM IMPACT 2014 - AMC-1882 Building a Scalable & Continuously Available IBM M...
Messaging with RabbitMQ and AMQP
ElasticMQ : Server for Local SQS
Evaluating persistent, replicated message queues
Architecture | The Future of Messaging: RabbitMQ and AMQP | Eberhard Wolff
The Future of Messaging: RabbitMQ and AMQP
Reactive programming with akka
Reactive Programming in Akka
VerneMQ @ Paris Erlang User Group June 29th 2015
Verne mq @ paris erlang user group
From polling to real time: Scala, Akka, and Websockets from scratch
Alvaro Videla, Building a Distributed Data Ingestion System with RabbitMQ
Scala.io 2013 - Scala and ZeroMQ: Events beyond the JVM
Microservices in Scala: Play Framework
Activator and Reactive at Play NYC meetup
Scaling out eclipse hono
Easy enterprise application integration with RabbitMQ and AMQP
Zeromq Messaging For Many Applications Pieter Hintjens

More from Adam Warski (7)

PDF
What have the annotations done to us?
PPT
Hejdyk maleńka część mazur
PDF
Slick eventsourcing
PDF
The no-framework Scala Dependency Injection Framework
PDF
The ideal module system and the harsh reality
PDF
Recommendation systems with Mahout: introduction
PDF
CDI Portable Extensions
What have the annotations done to us?
Hejdyk maleńka część mazur
Slick eventsourcing
The no-framework Scala Dependency Injection Framework
The ideal module system and the harsh reality
Recommendation systems with Mahout: introduction
CDI Portable Extensions

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Approach and Philosophy of On baking technology
PDF
Encapsulation theory and applications.pdf
PDF
Electronic commerce courselecture one. Pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPT
Teaching material agriculture food technology
NewMind AI Weekly Chronicles - August'25 Week I
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Empathic Computing: Creating Shared Understanding
Unlocking AI with Model Context Protocol (MCP)
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Approach and Philosophy of On baking technology
Encapsulation theory and applications.pdf
Electronic commerce courselecture one. Pdf
cuic standard and advanced reporting.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
sap open course for s4hana steps from ECC to s4
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
MIND Revenue Release Quarter 2 2025 Press Release
Advanced methodologies resolving dimensionality complications for autism neur...
Teaching material agriculture food technology

ElasticMQ: a fully asynchronous, Akka-based SQS server

  • 1. ElasticMQ a fully async, Akka-based Amazon SQS server Adam Warski SoftwareMill #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 2. What is Amazon SQS? • MQ-as-a-service • Send, Receive, Delete • At-least-once delivery #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 3. How to test SQS apps? 1. Don’t? #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 4. How to test SQS apps? 2. Just use SQS? #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 5. How to test SQS apps? 3. Use a local SQS server #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 6. ElasticMQ • (relevant) subset of SQS • In-memory • Lightweight #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 7. Stand-alone $  java  -­‐jar  elasticmq-­‐server-­‐0.7.1.jar [main]  INFO    org.elasticmq.server.Main$  -­‐  Starting  ElasticMQ   server  (0.7.1)  ... [main]  INFO    o.e.rest.sqs.TheSQSRestServerBuilder  -­‐  Started  SQS   rest  server,  bind  address  0.0.0.0:9324,  visible  server  address   http://localhost:9324 [main]  INFO    org.elasticmq.server.Main$  -­‐  ===  ElasticMQ  server   (0.7.1)  started  in  1444  ms  === #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 8. Using ElasticMQ import  com.amazonaws.auth.BasicAWSCredentials import  com.amazonaws.services.sqs.AmazonSQSClient client  =  new  AmazonSQSClient(new  BasicAWSCredentials("x",  "x")) client.setEndpoint("http://localhost:9324") val  queueUrl  =  client.createQueue( new  CreateQueueRequest("testQueue1")) client.sendMessage(new  SendMessageRequest(queueUrl,  "Hello!")) #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 9. Embedded <dependency>      <groupId>org.elasticmq</groupId>      <artifactId>elasticmq-­‐rest-­‐sqs_2.10</artifactId>      <version>0.7.1</version> </dependency> val  server  =  SQSRestServerBuilder      .withPort(9325)      .withInterface("localhost")      .start() //  ...  use  ... server.stopAndWait() #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 11. #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 12. Technologies • Scala • Akka • Spray #DV13 #elasticmq Wednesday 13 November 13 ➡ reactive @adamwarski
  • 13. Asynchronous: why? • Traditional model could work well? • Long polling #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 14. Receive message walk-through import  spray.routing.SimpleRoutingApp val  routes  =  sendMessage  ~  receiveMessage  ~  createQueue  ~  ... val  app  =  new  SimpleRoutingApp  {} app.startServer(interface,  port,  "...")  {      routes } #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 15. Receive message walk-through val  receiveMessage  =    action("ReceiveMessage")  {                        //  path("")  and  param()        param("VisibilityTimeout".as[Int]?,                        "WaitTimeSeconds".as[Long]?)  {            (visibilityTimeout,  waitTimeSeconds)  =>                respondWithMediaType(MediaTypes.`text/xml`)  {                //  inner  route:  RequestContext  =>  Unit                        }        }    } #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 16. Receive message walk-through //  inner  route:  RequestContext  =>  Unit ctx:  RequestContext  =>    val  actorMsg  =  ReceiveMessages(visibilityTimeout,                                                                      waitTimeSeconds)    val  msgs:  Future[List[Message]]  =  queueActor  ?  actorMsg    msgs.map  {  msgs  =>        ctx.complete(            <ReceiveMessageResponse>                ...            </ReceiveMessageResponse>          )  } #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 17. Receive message walk-through import  akka.actor.{Actor,  ActorRef} class  QueueActor  extends  Actor  {    val  messageQueue  =  mutable.PriorityQueue[InternalMessage]()    val  awaiting  =  mutable.PriorityQueue[ActorRef]()    def  receive  =  {        case  ReceiveMessages(...)  =>  {            //  if  there  are  messages,  reply            //  otherwise  put  the  sender  aside          //  schedule  a  timeout  in  20  seconds    }  }  } #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 18. Dataflow • Write async code as if it was sync! • Many Futures, if-s => trouble • Alternative: Scala Async #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 19. Dataflow val  result:  Future[ActorRef]  =  flow  {  (queueManager  ?  Lookup(name)).apply()  match  {      case  Some(queueActor)  =>  queueActor      case  None  =>            val  createFuture  =  queueManager  ?  Create(name)          createFuture.apply()  } } #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 20. Links • http://github.com/adamw/elasticmq • http://akka.io/ • http://spray.io/ • http://warski.org #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 21. There’s more! • “The ideal module system and the harsh reality” • Today, 17:50, Room 9 #DV13 #elasticmq Wednesday 13 November 13 @adamwarski
  • 22. Thank you; Come & get a sticker http://codebrag.com/devoxx/ #DV13 #elasticmq Wednesday 13 November 13 @adamwarski