As I'm getting familiar with http://akka.io/, I can't figure out how to do server-push.
After a client connects to a server, how can the server push messages to the client? For example, if a client subscribed to receive stock quotes from a quote server. Or if the server routes chat messages from one chat client to another.
WRONG IDEA: I realize that the client can pass a message to the server with the client's IP/port and then the server can initiate a new connection back to the client and push messages. This won't work, since the client could be behin开发者_如何学Cd firewall. The server needs to send messages back to the client over the socket connection that the client initiated.
The AKKA documentation isn't helpful, and my google searches have not been fruitful.
Anyone figure out how to do this?
A handful of solutions, if you'd like to make your life more difficult but oh so geeky.
Well, I've been thinking for a bit on how finagle and akka will intertwine. There's some overlap, but my feeling is that while Akka is much richer for writing application logic, as a service glue/communications layer it's lacking, in part because of the need to work everything into the actor model. I see finagle as node.js on steroids (or at least with static typing :) More specifically, finagle looks to be a great framework for handling layer 5 to low layer 7.
If finagle gains any traction, I would think apis around web sockets will grow to mirror what was done with socket.io for node.js, but it looks to be straightforward. I'm looking for an excuse to do this myself :)
Anyway, if you were careful about how you adapted to the actor model, you could stay entirely in Scala.
But as Viktor suggested you should think about using websockets (which I'm 99% sure that Lift would help you with), Comet if going over http. More generally webhooks is a nice style for pub sub on the web, though obviously even that will require the firewalls to accept incoming connections.
Personally I've been wishing for a couple years that Mark Nottingham's brilliantly elegant Cache Channels to do pub sub just using http to become a standard, but one could create a decent approximation if you controlled both client and server code.
Akka 2.0 will support reusing the inbound channel for outbound messages, which will give you what you request, until then you'll need to either accept that it doesn't work well with firewalls or just use another transport, Comet, WebSockets or perhaps Camel.
精彩评论