Skip to main content

Nexus Development Walkthrough - Java SDK

View Markdown
caution

This walkthrough covers Nexus SDK V2, which is pre-release. APIs are experimental and may change in backwards-incompatible ways.

Please do NOT review the documents under this page past the high level structure. Once we agree on the structure and form I will be working on the docs to match. For now those subpage contents should be considered placeholder text.

This walkthrough builds one Nexus Service from nothing to a complete API, adding a single Nexus capability at each step.

Nexus

A Nexus Service is a contract that one team publishes and other teams call, across Namespace boundaries, without sharing code or a deployment.

A sample problem

A purchase request needs approval before it can proceed.

Approval is slow and human-driven: someone has to look at the request and decide. The system needs to survive that wait, which may be minutes or weeks. While a request is pending, other systems need to nudge the approver and check on progress. Eventually a decision arrives, and the requesting system needs the outcome.

Concretely, the Service needs to:

  • Start an approval and, eventually, return APPROVED or DENIED
  • Accept a nudge that asks the approver again, and count how many have been sent
  • Report progress while the approval is still pending
  • Accept a decision from the caller and confirm it was recorded
  • Send a notification when the decision is final

Each of those maps onto a different Nexus capability, which is what makes it a useful walkthrough. By the end, this sample service will exercise a Workflow-backed Operation, a Signal, a Query, an Update, and an Activity-backed Operation.

One contract, every language

The walkthrough begins with the data contract, before any implementation, and that ordering is the point.

The equivalent sample for each language is written against the same contract. Because the contract is the only thing the two sides share, any caller can call any handler: the Go sample walkthrough caller can drive this Java handler for example, and the Java caller here can drive the handler from each other language's Nexus Development Walkthrough. Handler and caller do not need to agree on a language, only on the contract.

info

The idea is that we write a sample repo for each language that implements this project. Then we should be able to run the client from any sample project against the handler from any sample project.

The Nexus Client Code Generator makes this easy. It takes the contract and emits typed models, runtime validators, and Service definitions for Go, Java, Python, and TypeScript, so neither side hand-writes the types and neither side can drift from the contract.

Steps

  1. Define the data contract
  2. Generate code from the contract
  3. Choose the backing implementation
  4. Implement the Service
  5. Publish in Nexus
  6. Call the Service
  7. Add messaging
  8. Send messages
  9. Add a Standalone Activity
  10. Call the Standalone Activity

Then: Debugging, common pitfalls, and tips.

Before you start

You need two Namespaces, one for the handler and one for the caller, so the walkthrough crosses a real Namespace boundary. A local development server with two Namespaces is enough for steps 1 through 4; step 5 covers both the development server and Temporal Cloud.

If you have not used Nexus before, read Nexus Services and Nexus Operations first, or work through the shorter Nexus quickstart.