# ActorRef and ServiceKey references

**URL:** <https://discuss.akka.io/t/actorref-and-servicekey-references/6344>\
**Category:** Akka Libraries\
**Created:** [April 23, 2020, 6:35am UTC](https://discuss.akka.io/t/actorref-and-servicekey-references/6344 "2020-04-23T06:35:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dharmeshbk](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dharmeshbk](https://discuss.akka.io/u/dharmeshbk)\
**Post date:** [April 23, 2020, 6:35am UTC](https://discuss.akka.io/t/actorref-and-servicekey-references/6344/1 "2020-04-23T06:35:29Z")

</div>

How to get ActorSystem reference from non actor classes. In addition, how to get ActorRef or ServiceKey reference from non actor class.

---

<div class="post-metadata">

**Author:** ![patriknw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/patriknw/32/89_2.png) [@patriknw](https://discuss.akka.io/u/patriknw)\
**Post date:** [April 23, 2020, 2:12pm UTC](https://discuss.akka.io/t/actorref-and-servicekey-references/6344/2 "2020-04-23T14:12:32Z")

</div>

Somewhere you start the `ActorSystem`. Reference to that instance must be passed in to where you need it.

There is no global reference to started `ActorSystem` in Akka, because it’s allowed to start and stop many systems in the same JVM. That is useful for testing.

---

<div class="post-metadata">

**Author:** ![dharmeshbk](https://avatars.discourse-cdn.com/v4/letter/d/f1d935/32.png) [@dharmeshbk](https://discuss.akka.io/u/dharmeshbk)\
**Post date:** [April 23, 2020, 2:31pm UTC](https://discuss.akka.io/t/actorref-and-servicekey-references/6344/3 "2020-04-23T14:31:51Z")

</div>

Thanks Patrick. So I did register the worker router and service router to receptionist.

```auto
ActorRef<ClusterTaskService.Command> service = context.spawn(ClusterTaskService.create(workerRouter), "TaskService");
   context.getSystem().receptionist().tell(Receptionist.register(TASK_SERVICE_KEY, service.narrow()));

 boolean preferLocalRoutees=true;
   ActorRef<EngineComputeWorker.RunRequestCommand> workerRouter = context.spawn(Routers.group(TASK_WORKER_KEY).withRoundRobinRouting(preferLocalRoutees), "WorkerRouter");   

```

I registered the Service to receptionist so how can I get reference when I need to use it from receptionist, I couldn’t find API to get ActorRef Service from Receptionist

---

<div class="post-metadata">

**Author:** ![patriknw](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.akka.io/patriknw/32/89_2.png) [@patriknw](https://discuss.akka.io/u/patriknw)\
**Post date:** [April 23, 2020, 3:00pm UTC](https://discuss.akka.io/t/actorref-and-servicekey-references/6344/4 "2020-04-23T15:00:00Z")

</div>

With `Receptionist.Find` message as described in [https://doc.akka.io/docs/akka/current/typed/actor-discovery.html](https://doc.akka.io/docs/akka/current/typed/actor-discovery.html)

However, if you are using a [group router](https://doc.akka.io/docs/akka/current/typed/routers.html#group-router) you can send messages directly to the `ActorRef` of the router, the `ActorRef<ClusterTaskService.Command> service` in your example.
