Using Akka to spawn server/clients

36 views
Skip to first unread message

M Ahsan

unread,
Jun 27, 2016, 3:26:01 AM6/27/16
to Akka User List
First off, I was wondering if it is a correct design decision to run a Netty websocket server inside an Akka actor. I want to be able to receive messages on the actor, and send them to the clients connected to the Netty WS server. Netty has its own thread pools and whatnot, so is it ok to spawn a Netty server inside an Akka actor, or is there a better way to approach this?

Second, my Akka application spawns several WebSocket clients to other services. When I get data from the service, I want to publish that data to various actors. The WebSocket client I use (async-http-client) uses a callback to respond to incoming messages. I'm doing something along these lines right now:


Is this correct usage, or is there a better way to approach this as well?

My real concern here is what I can/can't do in an actor, because I feel like these are some common things developers would use in their apps. If anybody can clear these issues, that would be great. Thanks!

Patrik Nordwall

unread,
Jul 1, 2016, 10:01:15 AM7/1/16
to akka...@googlegroups.com
On Sun, Jun 26, 2016 at 8:59 AM, M Ahsan <ag...@jantox.com> wrote:
First off, I was wondering if it is a correct design decision to run a Netty websocket server inside an Akka actor. I want to be able to receive messages on the actor, and send them to the clients connected to the Netty WS server. Netty has its own thread pools and whatnot, so is it ok to spawn a Netty server inside an Akka actor, or is there a better way to approach this?

You can do that, no problem. Be careful to not use the actor's mutable state from callbacks running on other threads, though. Perhaps better to start the Netty server outside of the actor. You have to interact with the actor using messages anyway.


 

Second, my Akka application spawns several WebSocket clients to other services. When I get data from the service, I want to publish that data to various actors. The WebSocket client I use (async-http-client) uses a callback to respond to incoming messages. I'm doing something along these lines right now:


Is this correct usage, or is there a better way to approach this as well?

That is alright. Same comment here, be careful to not close over the actor's state.

 

My real concern here is what I can/can't do in an actor, because I feel like these are some common things developers would use in their apps. If anybody can clear these issues, that would be great. Thanks!

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Akka Tech Lead
Lightbend -  Reactive apps on the JVM
Twitter: @patriknw

Reply all
Reply to author
Forward
0 new messages