This file contains hidden or 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
name := "phony" | |
version := "0.1" | |
scalaVersion := "2.12.6" | |
organization := "com.phony" | |
libraryDependencies += "com.googlecode.libphonenumber" % "libphonenumber" % "8.10.23" |
This file contains hidden or 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
(path("upload") & extractLog) { log => | |
post { | |
entity(as[Multipart.FormData]) { formdata => | |
val partsSource = formdata.parts | |
val partsFlow = Flow[Multipart.FormData.BodyPart].map { fileData => { | |
if (fileData.name == "myFile") { | |
val filename = "./data/" + fileData.filename.getOrElse("tempFile_" + System.currentTimeMillis()) | |
val file = new File(filename) | |
val fileContentsSource = fileData.entity.dataBytes | |
Left(fileContentsSource, file) |
This file contains hidden or 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
(pathEndOrSingleSlash & get) { | |
complete( | |
HttpEntity( | |
ContentTypes.`text/html(UTF-8)`, | |
""" | |
|<html> | |
| <body> | |
| <form action="/upload" method="post" enctype="multipart/form-data"> | |
| <input type="file" name="myFile"> | |
| <button type="submit">Upload</button> |
This file contains hidden or 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
object Run extends App | |
with JsonHelper{ | |
val queueName : String = "Support" | |
val redisHost : String = "localhost" | |
val redisPort : Int = 6379 | |
implicit val system : ActorSystem = ActorSystem() | |
implicit val timeout : Timeout = FiniteDuration(5,"seconds") |
This file contains hidden or 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
object MessagingService { | |
case class QueueElement[T](data : T , numRetry : Int = 1) | |
case class SendMessageRequest(phoneNumber : String, msg : String, enqueue : Boolean, queueName : String) | |
case class SendMessageResponse(status : Boolean) | |
} | |
trait MessagingService extends Actor | |
with ActorLogging | |
with JsonHelper // for Json Serialization | |
{ | |
val redisClient = getRedisClient.getRedisInstance |
This file contains hidden or 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
object QueueManager { | |
case object Start | |
def createSchedulers(schedulers : List[Props]) : Props = Props(new QueueManager(schedulers)) | |
} | |
private [Manager] class QueueManager(schedulers : List[Props]) extends Actor with ActorLogging { | |
import QueueManager._ | |
override def preStart(): Unit = | |
schedulers.foreach(context.actorOf(_)) | |
self ! Start |
This file contains hidden or 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
object Scheduler{ | |
case object Poll | |
def createScheduler( | |
worker : Props, | |
redis : RedisDbT, | |
maxNumDeq : Int, | |
queueName : String, | |
delay : FiniteDuration | |
) = { | |
Props(new Scheduler(worker,redis,maxNumDeq,queueName,delay)) |
This file contains hidden or 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
object Worker { | |
case class RedisElement(element : String) | |
def createWorker(useElement : String => Unit) : Props = Props(new Worker( | |
useElement | |
)) | |
} | |
private[worker] class Worker(useElement : String => Unit) extends Actor { | |
import Worker._ | |
override def receive: Receive = specificReceive orElse genericReceive |
This file contains hidden or 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 RedisDbT { | |
val host: String | |
val port: Int | |
val timeout: FiniteDuration | |
implicit val _system : ActorSystem | |
def getRedisInstance = _system.actorOf(Props(new RedisDbService(host,port,timeout))) | |
} |
This file contains hidden or 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
(messageGateway ? SendMessageToClientRequest ( | |
id = id, | |
phoneNumber = pNumber, | |
msg = message | |
)).mapTo[SendMessageToClientResponse] onComplete { | |
case Success(res) => res match { | |
case SendMessageToClientResponse(true) => | |
currentSender ! SendCustomMessageResponse(true) | |
case SendMessageToClientResponse(false) => | |
currentSender ! SendCustomMessageResponse(false) |