I am starting a project which is supposed to provide both:
- simple http API and
- some other functionality (including some low-level networking).
This is why I would like to integrate the “other functionality” with a (new) Play framework project and make use of it’s on-the fly compilation and other benefits. The majority of the application (both in terms of business logic and server load) will be in the non-web part of the project.
So my question is: how do I go about packing both those modules into one Scala application?
The best approach I think I found is treating the non-web part as a plugin for the Play project. I am not sure however if this is the right approach, considering the majority of the application might end up in such a “plugin”.
I thought about deploying the two parts as separate applications, but I doubt it would work for me: I would like the applications to share (among others) cache, config and db connections, and I shouldn’t really separate them.
I’m not yet experienced with either Scala or Play, so I will very much appreciate your input.
I would recommend using Akka actor systems to integrate your existing business logic and networking services. You can easily add multiple Akka actor systems and integrate them into a complete system in your Play application. Play also comes with an internal actor system that you can take advantage of.
So, you can wrap your existing logic into an actor system in itself or you can build small actor systems that takes care of the integration with the existing systems and start up those connectors as actor systems when the Play application loads.
Here is an example how you can load the internal actor system when the Play application loads.
You can also load new actor systems within the application if needed, doing something like this.
You can read more about Play Akka integration here. Play also has built in functionality where you can take advantage of the built in actor system with features such as the ScalaAsync etc. So if your external services are mainly HTTP based services that approach might work best for you. If you build actor systems for your external services you can access then as remote actors as explained here Akka Remoting