Deepak Mehra
Deepak Mehra

Reputation: 31

New Micro Service to Lagom Framework

How to add a new Micro Service to the Lagom Framework. I have a Lagom project with default Micro-Services hello. I would like to add more Microservices using Maven build tool.

Upvotes: 2

Views: 439

Answers (1)

Tompey
Tompey

Reputation: 334

First define your new api, starting with a new pom file. If you want a service called foo, it would look something like this:

<project>
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>me.lagom.test</groupId>
        <artifactId>myproject</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>

    <artifactId>foo-api</artifactId>

    <packaging>jar</packaging>

     <dependencies>
        <dependency>
            <groupId>com.lightbend.lagom</groupId>
            <artifactId>lagom-javadsl-api_2.11</artifactId>
        </dependency>
        <!-- Your dependencies for the other services in here -->
        <dependency>
            <groupId>${project.groupId}</groupId>
            <artifactId>hello-api</artifactId>
        <version>${project.version}</version>
    </dependency>
    </dependencies>
</project>

Then you need to add that module to your root pom like this:

 <modules>
    <module>hello-api</module>
    <module>hello-impl</module>
    <module>foo-api</module> <!-- <- your new module -->
</modules>

Finally, define your service. Something like this in FooService.java:

public interface FooService extends Service {
    ServiceCall<NotUsed, String> getFoo();

    @Override
    default Descriptor descriptor() {
        return named("foo").withCalls(
            pathCall("/api/foo",  this::getFoo)
        );
    }
}

Upvotes: 4

Related Questions