Use AWS SQS in Scala Play 2.4 reactive project

141 views
Skip to first unread message

Tianhao Li

unread,
Feb 8, 2016, 10:52:56 PM2/8/16
to play-framework

I want to use AWS SQS in my Play 2.4 project.


There are two options at moment:

  1. 1. There is a SQS wrapper called https://github.com/kifi/franz which supports reactive way of using that. But it seems not quite popular on Github not sure how mature it is? Whether the developers will continue to maintain it.

  2. 2. There is Java SQS SDK, but it doesn't support Scala Future (reactive way). If I want to make it non-blocking, could I use Akka or?

  3. Thanks.

Mariot Chauvin

unread,
Feb 9, 2016, 5:20:13 AM2/9/16
to play-fr...@googlegroups.com
Hi,

Have a look to this piece of code to transform async operation from AWS SDK to a scala future:

import java.util.concurrent.{Future => JuncFuture}

def futureOf[X <: AmazonWebServiceRequest, T](call: (X,AsyncHandler[X, T]) => JuncFuture[T], req: X): Future[T] = {
val p = Promise[T]()
val h = new AsyncHandler[X, T] {
def onError(exception: Exception) { p.complete(Failure(exception)) }
def onSuccess(request: X, result: T) { p.complete(Success(result)) }
}
call(req, h)
p.future
}

Hope this help,

Mariot


--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/71a17867-15b8-4e68-a7e9-ece490a81a5d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



This e-mail and all attachments are confidential and may also be privileged. If you are not the named recipient, please notify the sender and delete the e-mail and all attachments immediately. Do not disclose the contents to another person. You may not use the information for any purpose, or store, or copy, it in any way.  Guardian News & Media Limited is not liable for any computer viruses or other material transmitted with or as part of this e-mail. You should employ virus checking software.
 
Guardian News & Media Limited is a member of Guardian Media Group plc. Registered Office: PO Box 68164, Kings Place, 90 York Way, London, N1P 2AP.  Registered in England Number 908396


Christian Schmitt

unread,
Feb 9, 2016, 5:50:56 AM2/9/16
to play-framework
Actually it's way easier when AWS SDK returns a java future you could just use:

import scala-java8-compat and import FutureConverts._
then you could just upgrade via .toScala

Tianhao Li

unread,
Feb 9, 2016, 6:16:51 AM2/9/16
to play-framework
Thanks for this. Will evaluate it and compare with the reactive library.
Reply all
Reply to author
Forward
0 new messages