Microservices. Streaming data. Event Sourcing and CQRS. Concurrency, routing, self-healing, persistence, clustering...learn how Akka enables Java developers to do all this out of the box! Brought to you in partnership with Lightbend.

So, you want to integrate an unmanaged service in Lagom using Scala.

Let’s first understand what an unmanaged service is first, and then we will see how we can integrate an unmanaged service with our Lagom service.

What Is an Unmanaged Service?

An unmanaged service is basically an external service that exposes some data over HTTP. Any external REST API that will be used in a Lagom-based service is an unmanaged service.

For example, there's integrating Google Maps, Openweather, or any other kind of service for that matter.

Communicating With External (Unmanaged) Services in Lagom

It is possible to enable communication between the Lagom services defined in your build and an unbounded number of external services (which could either be running locally or on a different machine).

To do this, we need to register the API as an external service in the Service Locator, which allows services to discover and communicate with each other.

The first thing you will have to do is to register each external service in the Service Locator. Assume we want to register an external service named weather that is running on http://localhost:3333. Here is what we would add to the build.lagomUnmanagedServices in ThisBuild := Map(“weather” -> “http://localhost:3333”;)

The above ensures that the Service Locator knows about the weather service. Then, if you need a Lagom service to communicate with it, simply @Inject the ServiceLocator and use it to either locate the weather service’s URI or perform some arbitrary work with it.

Now let’s see how we can consume data from the unmanaged service.

Consume Data From Unmanaged Service

Step 1: Create a new ‘trait’ for the external service, which will have the exact same route as the external service has.

Alright, that was it. We are done writing our service, which will consume data from an external (unmanaged) service.

If you find any challenge, do let me know in the comments. If you enjoyed this post, I’d be very grateful if you’d help it spread. Keep smiling, keep coding!

Microservices. Streaming data. Event Sourcing and CQRS. Concurrency, routing, self-healing, persistence, clustering...learn how Akka enables Java developers to do all this out of the box! Brought to you in partnership with Lightbend.