# Quick start

This is the five-minute version: two nodes — one Java, one Node.js — each exposing a tiny add action, calling each other across the language boundary.

You need a message broker running (the examples use NATS at nats://localhost:4222) and both projects wired up as shown in Setup — one cluster (the dependency and the broker configuration). Then follow the three steps below.

# 1. Define a service on each side

A Moleculer service is a named bag of actions. In Java a service extends Service and its actions are public Action fields (lambdas); in Node.js it is a plain object with an actions map.

    The two services are named mathNode and mathJava — an action is addressed as <serviceName>.<actionName>, so they expose mathNode.add and mathJava.add to the whole cluster.

    # 2. Start both nodes

    Each side creates a broker (configured as in Setup), registers its service and starts. Start them in either order — they find each other over the message bus.

      # 3. Call across the boundary

      Before the first call, wait for the remote service to be discovered, then call it. The call is identical whether the target is local or on the other language's node.

        Why two numbers on `waitForServices(10000, "mathNode").waitFor(12000)`?

        waitForServices(10000, …) returns a Promise and tells discovery to give up after 10 000 ms. .waitFor(12000) then blocks the current thread for up to 12 000 ms while that Promise resolves (the blocking form of await) — so keep the blocking timeout ≥ the discovery timeout. In Node.js this is simply await broker.waitForServices(["mathNode"], 10000); Java just separates the "how long to search" and "how long to block" parts.

        That is the whole loop: a Node.js process called a Java action and a Java process called a Node.js action, over one cluster, with no REST layer or shared database between them.

        # Where to go next

        • Call Java from Node.js — the Node-developer's view: discover and call Java services, send events.
        • Call Node.js from Java — the Java-developer's view: call Node.js actions, inspect and ping the remote node.
        • Data types & features — pass lists, nested objects, events, cached values, metadata and binary streams across the boundary.

        The add services and the calls above are taken verbatim (trimmed) from a runnable, test-verified integration demo — so they compile and run as shown.