HTTP ingress to ActorRef


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.



The Java Akka HTTP quickstart could be good inspiration, it is currently using the new typed actor APIs:
but if you go back a bit in history you’ll find the classic Actor API used:

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


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