Jack
Jack

Reputation: 16708

HTTP messaging gateway with Scala

I'm developing a gateway that will be located between mobile web apps and web services on backend systems. The purpose of this gateway is to protect web apps against changes to backend web service api's, to introduce concurrency, transform messages, buffering, etc.

My proposed architecture is as follows:

The gateway is purely responsible passing, translation, aggregation, etc. of messages and does not need to keep state or do user authentication at this point - it's simply responsible for being a single interface that knows how to talk to mobile apps on the one side and one or more services on the other side.

I'm strongly considering using Scala as the development language because it seems well suited for this type of application, but what would be the correct architecture for such a Scala service? I looked at frameworks such as Lift and Play and also considered doing a simple "java" based web service and just use Scala as to implement my business logic. I believe strongly in keeping things as simple as possible. I'm wary of complicated setups and thousands of lines of dead code in frameworks that may never be used. On the other side, limiting oneself to a 'role your own' solution and creating a lot of work and having to maintain code that may have been part of existing solutions is also not ideal.

Some things to consider: I'm the architect and developer, but my knowledge of Scala is limited to the first half of "Programming in Scala, Second Edition". Also, my time is very limited. Still, I want to get this right the first time.

I'm hoping that some clever gent or dame will provide me with insights to this type of solution and maybe a link or two to get started quick. I really need to get going FAST, but hope that the experience or insights of another professional could help me avoid pitfalls along the way. Any insights to development environments and tools will also be helpful. I have to develop on Mac (company rules) but will be deploying on Ubuntu server. I'm currently juggling between installs of Eclipse or Idea as IDE's and the scala compiler or sbt for building.

UPDATE

Thanks for all the potential answers below. I had a look at each and every suggestion and all of them have merit. The problem is now to bet on the right horse. Spray is possibly the simplest solution to the problem, but I also found Finagle. It seams like a stunning solution to my problem. I'm a bit concerned that it is built on top of Netty instead of Akka. Does anyone see any problem with that. I was hoping to keep my solution as purely Scala as possible, but Finagle appears to be the most mature of the lot. Any ideas?

Upvotes: 1

Views: 1978

Answers (5)

mistertim
mistertim

Reputation: 5293

It might be worth taking a look at Akka, which provides a lightweight framework for writing concurrent, fault-tolerant applications on the JVM, as well as useful built-in abstractions for writing web services. In addition, the Spray project looks like it could be useful for your purposes, providing HTTP server and client libraries on top of Akka (Although, unlike Akka itself, I haven't used this so myself so can't vouch for it).

Upvotes: 3

Jestan Nirojan
Jestan Nirojan

Reputation: 2486

If your system is middle-ware and get the things done quickly, then Spray will be a best. Spray was developed on top of Akka. Akka has ZeroMQ support.

in future if you are going to add some other web like module along with your middle-ware, then choosing Lift + Akka will be better because, Lift also provides Spray like web service stuff + it will be easy to start developing other modules.

You can choose SBT as your build, there are some project templates, template generation tools available, so you can get the project build very quickly.

In my experience , SBT + InteliJ Idea works well, have a look on sbt-idea plugin

Spray Project Template
Lift Project Template Generator

Upvotes: 0

Will Sargent
Will Sargent

Reputation: 4396

If you're using a web service that is purely for other services, then an Akka based service like Spray or Blueeyes is probably your best bet. You can use Jerkson to do the JSON mapping to and from your case classes and use Akka-Camel to link to ZeroMQ.

Upvotes: 2

GClaramunt
GClaramunt

Reputation: 3158

Unfiltered is very interesting option if you want to keep it lightweight, as is not a full blown web framework.

To be honest, the documentation can use more detail, but to provide a web service you just write:

object MyService extends unfiltered.filter.Plan {
    def intent = {
            case req @ GET(Path ("/myendpoint")& Params(params)) => 
                                 for { 
                                    param1<-params("param1")
                                    param2<-params("param2") 
                                 } yield ResponseString(yourMethod(param1,param2))
          }

override def main(args:Array[String]) = unfiltered.jetty.Http.anylocal.filter(MyService).run(); 
}

Very useful if you don't want to use a framework and don't want to mix java/java annotations with Scala (otherwise, you have the usual java solutions)

Still, I would recommend to look into Akka if you think you think actors will fit your problem

Upvotes: 0

pr1001
pr1001

Reputation: 21962

As mistertim says, Akka is a good option. I'm biased, but I think Lift and its RestHelper is a fantastic way to go also (I've built several APIs for iPhone apps using Lift). Beyond those, I know several people who are very happy with Unfiltered.

Upvotes: 2

Related Questions