How to write Lagom managed service that don't expose REST endpoints?

Use case

I have an lagom event sourcing/CQRS employee service that publishes events to a Kafka topic named employee-kafka-events. I need to write a mail-notification service that would subscribe to this kafka topic and sends mail notifications for certain events on that topic.

Question

How do I write this mail-notification service as a Lagom managed service? Clearly, this mail-notification service doesn’t have a use case of exposing any REST endpoint. Is it possible to write a service in Lagom as a managed service that doesn’t expose any REST endpoint? If yes, how would we define the ApplicationLoader of such a service? If not, then how could I make use of Lagom Message Broker API? If it’s not even possible to use Lagom’s message broker API then what libraries can I use from Lighbend stack to implement the mail-notification service?

Since Lagom is an opinionated framework, what opinion does it holds for such a use case???

Hi @codingkapoor,

You need to have a “dummy” service trait to implement.
It is “dummy” in the sense that service trait descriptor only defines named("my-service") without any calls or topics.
This trait can also be in your IMPL project (so API project is not needed).

Check Subscriber-only-Services.

Hope this helps.

Br,
Alan

2 Likes

Your suggestion seemed to have worked. Thanks.

But I have a follow up question: This approach seems to start a service as a REST service assigning it a port (which probably is never needed) with 0 APIs defined. This seems kind of a hack to me.

Why Lagom chooses such a limitation when it comes to defining services that don’t need to expose any API? Why not provide a graceful approach to defining such services? I am sure you would agree that such use cases are also important and inevitable.

Hi @codingkapoor,

I agree that this solutions is not completely optimal but a port bind is not such of a big overhead. You do not need to expose the port in the k8s service endpoints.

Lagom’s service call endpoint is a “first class citizen” explaining why a port bind is expected.
Lagom was not designed as an only stream processing service.

It is also questionable if this kind of a use case will be covered by Lagom in the future taking in mind that there are other Lightbend frameworks emerging with stronger focus on stream processing (stateless and stateful).

That is my personal opinion.

Br,
Alan

1 Like