HTTP ingress to ActorRef

Hi,

I’ve picked through and grasped most of the IOT example and the HTTP examples and I’m trying to put them together in practice.

I’m looking for a concise example of how - in the http setup, or elsewhere - to get an ActorRef to the DeviceManager in order to send a temp update or read values for the mentioned dashboard.

The HttpServerActorInteractionExample uses classic actorOf which I think spawns a new actor.

I need to get an ActorRef to the existing DeviceManager because it has the state of all the groups.

Presumably Receptionist is the way to go? But how to query it when the HTTP layer of code is not an actor,

Or do I query for it everytime when the code is on the actor context.

Of course I want to Patterns.ask(deviceMangerRef, … ) for Http req/resp to this.

Thanks

Rob

The Java Akka HTTP quickstart could be good inspiration, it is currently using the new typed actor APIs: https://github.com/akka/akka-http-quickstart-java.g8/tree/10.1.x/src/main/g8/src/main/java/%24package%24
but if you go back a bit in history you’ll find the classic Actor API used: https://github.com/akka/akka-http-quickstart-java.g8/tree/027cdfdcdcb6093e48b7cdff900c4158382d441a/src/main/g8/src/main/java/%24package%24

Ah, interesting, Thank you Johan.

So, starting the HTTP server as the root behaviour brings it into the Actor context, OK.

Thanks for your help

R

I would rather call it starting it from the root behavior, in typed that is the right place to bootstrap the parts of your application and possibly inject them into each other, in that sample it starts the user actor and then injects the actor ref of it to the HTTP routes. That way you can for example use the routes in a test but give it a dummy or “TestProbe” actor to be able to test only the HTTP routes.

In Akka classic you will often instead do that same bootstrapping in your applications main method.

1 Like