moleculer-java

Moleculer for Java

Moleculer for Java is a JVM implementation of the Moleculer microservices framework. It is wire-compatible with the Node.js version, so Java and Node.js nodes can join the same cluster and call each other’s services as if they were local. The whole stack is non-blocking and Promise-based, and built around the universal Tree data type, so the same code scales from a single process to a distributed system.

Highlights

Documentation

Documentation

Download

<dependency>
    <groupId>com.github.berkesa</groupId>
    <artifactId>moleculer-java</artifactId>
    <version>2.0.0</version>
</dependency>

Quick start

A node is a ServiceBroker. Register a service, start the broker, and call an action — every call returns a non-blocking Promise:

ServiceBroker broker = new ServiceBroker("node-1");

// A service with one callable action
broker.createService(new Service("math") {
    public Action add = ctx ->
        ctx.params.get("a").asInteger() + ctx.params.get("b").asInteger();
});

broker.start();

Tree params = new Tree();
params.put("a", 5);
params.put("b", 3);

broker.call("math.add", params).then(rsp -> {
    System.out.println("Result = " + rsp.asInteger());   // 8
});

Add a Transporter (NATS, Redis, TCP, …) and the very same math.add action becomes callable from any other node in the cluster — including Node.js nodes.

Requirements

Java 17 or newer.

License

Moleculer for Java is available under the MIT license.