9

I have an application frontend, implemented on angularjs + nodejs + express + socket.io. There's also a feature in a separate service. This service is written on akka.

Here's the way of how the entire communication pipeline may look:

[user enters a value] -> [angularjs gets the value and send it to nodejs server thru socket.io] -> [nodejs receives the value and channel it to akka] -> [akka performs some calculation and return a response] -> [nodejs receive the response and channel it to angularapp].

One possible solution would be to introduce a MQ middleware and use it for the interaction, but such "message driven approach" seems like an overhead for something that clearly looks like an RPC call. What is the best way to build up such type of communication between nodejs and akka?

theocat
  • 113
  • 1
  • 5
  • http://stackoverflow.com/questions/4729013/can-i-call-java-from-node-js-via-jni-and-how may help – George Simms Jun 06 '15 at 21:59
  • You could use edge.js and akka.net though – George Simms Jun 06 '15 at 22:02
  • I don't understand what you're asking. If the msgs come from the client via socket.io, then you just define message handlers in your server-side socket.io code that then calls your akka service appropriately whenever a a message destined for that service is received. That is the method that is consistent with the architecture you seem to have chosen. Of course, nothing says you have to do this through nodejs if it doesn't really play a role in this data at all. The browser could communicate directly via socket.io or ajax to your service over a different port. – jfriend00 Jun 06 '15 at 22:03
  • @jfriend00 that's right. The question is how to call akka. One approach that immediately comes to my mind is to simply publish a message to some MQ and eventually get a response from another queue, but this doesn't seem to be effective - since we'll have to define two queues just for doing request / response.... is there any other approach, that may be more effective? – theocat Jun 06 '15 at 23:57

2 Answers2

10

Since Akka speaks HTTP itself you can just make a RESTful call from Node to the Akka service. Pipelining is supported so you can make this very efficient. Within the Akka HTTP server flow you use the ask pattern to get the calculated value back from your actor.

Roland Kuhn
  • 15,412
  • 2
  • 36
  • 45
  • Sounds as a great idea. Thank you – theocat Jun 07 '15 at 14:35
  • Hello Roland. What do you mean by pipelining? Does not this solution have a performance penalty for marshalling/unmarshalling the http request? Thanks! – naaka Mar 07 '16 at 10:32
6

The cleanest way would to be to skip node.js/socket.io for the messaging layer and instead use websockets over spray.io directly. Typesafe has an activator template for just the scenario of websockets to akka actors: Spray and Websocket interfaces to actors

Otherwise you would be looking at some kind of RPC middleware, maybe Thrift or ZeroMQ.

Arne Claassen
  • 14,088
  • 5
  • 67
  • 106