Skip to content
Documentation

Build with Java

Get started with Java

Run a worker with configuration and business stages, then submit and inspect a typed pipeline.

On this pageBefore you startInstall the current SDK from sourceOpen the example projectBuild and start the workerSubmit and observeSend a different orderConnect one real operationIf the first run does not completeCreate the project yourselfAdditional CLI checks

Run the supplied orders worker, submit an order and inspect its validation and recording stages. Then send another order and find its input and result in the dashboard. The demonstration records recorded=true in workflow context; it does not write to a business database or charge a customer.

Download the runnable Java demo. It includes the files below plus independent-producer, retry and schedule recipes. The matching SDK source supplies the local packages used by every example on these pages.

Before you start

You need JDK 17 or 21 and a running Pipelogiq 0.5.0 server with its migrations applied. For another server release, check versions and compatibility.

  • Existing server: ask its administrator for the external API URL, a test application's API key, the dashboard URL and a dashboard account assigned to that application.
  • New local server: follow installation, then continue with this guide. The local external API is http://localhost:8081; the dashboard is http://localhost:3300. Use the application key and dashboard account created during installation.

Configure the SDK with the external API URL and application key, not the dashboard URL or login credentials. Use the same application's key in both terminals. Use the Bash commands on macOS/Linux or the PowerShell commands on Windows.

No Spring, broker URL or model provider is needed for the first run. HTTP is the default transport. Java package names start with io.pipelogiq.sdk; the Maven group is com.pipelogiq.

Install the current SDK from source

Extract the matching source archive, open its root directory containing mvnw and pom.xml, and run:

sh
export PIPELOGIQ_SDK_DIR="$PWD"
chmod +x mvnw
./mvnw -B -pl sdk-runtime -am install -DskipTests

This builds the recommended pipelogiq-sdk artifact and its dependencies into your local Maven repository. The wrapper downloads Maven automatically. This guide works without requiring version 0.5.0 to be available from Maven Central.

On Windows PowerShell, from that same SDK source root:

powershell
$env:PIPELOGIQ_SDK_DIR = (Get-Location).Path
.\mvnw.cmd -B -pl sdk-runtime -am install -DskipTests

Open the example project

Extract the Java demo and open pipelogiq-java-demo. It contains the project, configuration, worker and producer files. Keep PIPELOGIQ_SDK_DIR pointing to the SDK source root; you will use its Maven wrapper to build the demo.

Build and start the worker

From pipelogiq-java-demo, build once:

sh
"$PIPELOGIQ_SDK_DIR/mvnw" -q compile dependency:copy-dependencies
export PIPELOGIQ_API_URL='http://localhost:8081'
export PIPELOGIQ_API_KEY='your-application-api-key'
java -cp 'target/classes:target/dependency/*' example.OrdersExample

Keep Terminal A running. The worker executes handlers when Pipelogiq sends it work; starting it does not submit an order. With administrator access, you can also check that worker orders-java is online in your application's dashboard. The completed order in the next step confirms the worker ran your handlers.

For Windows PowerShell, run these commands from the demo root:

powershell
& "$env:PIPELOGIQ_SDK_DIR\mvnw.cmd" -q compile dependency:copy-dependencies
$env:PIPELOGIQ_API_URL = "http://localhost:8081"
$env:PIPELOGIQ_API_KEY = "your-application-api-key"
java -cp 'target/classes;target/dependency/*' example.OrdersExample

The remaining Java commands use the macOS/Linux : classpath separator. Use ; on Windows. In a new terminal, set the API settings again. Set PIPELOGIQ_SDK_DIR again only if you need another build.

Submit and observe

In Terminal B, open the same demo directory, set the same API URL and key, then run the producer:

sh
java -cp 'target/classes:target/dependency/*' example.CreateOrder

It submits the order and waits up to 60 seconds. Expect:

text
Pipeline <id>: COMPLETED
Recorded: true

Open your dashboard, choose Pipelines, and find the pipeline ID printed by the producer:

  1. In Stages, check that ValidateOrder and RecordOrder completed. The recording stage's output is Recorded demo order intro-123.
  2. In Context, find validatedOrder with order ID intro-123 and amount 42.50, plus recorded: true.
  3. In Logs, find the Order validated message.

ValidateOrder checks the submitted ID and amount, then writes validatedOrder. RecordOrder reads that value and records the demonstration outcome.

The producer submits the definition; the worker executes these two handlers; Pipelogiq schedules and records their results. The producer and worker are separate processes in this example. Running CreateOrder again returns the existing pipeline because it reuses the fixed demo-order-intro-123 creation key.

Send a different order

Keep the worker running. In Terminal B, use the included CLI to submit order order-002 with amount 85.00:

sh
java -cp 'target/classes:target/dependency/*' example.CreatePipelineExample submit order-002 85.00

It prints a new pipeline ID. Open that run in the dashboard and wait for both stages to complete. Confirm that the input and validatedOrder context contain order-002 and amount 85.00; the recording stage's output should be Recorded demo order order-002.

The CLI derives its creation key from the order ID. Choose a fresh ID for another order; repeating the same ID is a retry of that submission. If you edit CreateOrder.java instead, change its business ID and idempotency key together when creating a new order.

Stop the worker with Ctrl+C when finished. You can also run the inventory retry recipe from this same download to see a temporary failure, its retry and an appended audit stage.

Connect one real operation

Replace the demonstration body of RecordOrder.execute with a call to an existing application service. Set recorded: true and return success only after that operation succeeds; return a failure result when it rejects the request. Use the worker registration guide when the handler needs service dependencies.

Give each stage a descriptive name and use context.put to record a non-sensitive business reference, such as the order ID. Retain the example's stable creation-key pattern for retries of the same business request.

Keep independently recoverable actions in separate stages: a CRM retry should not resubmit a successful payment. Make external writes safe to repeat; a pipeline creation key does not deduplicate those writes. See payment and reconciliation for these boundaries and Java workflows for implementation. The sections below cover troubleshooting, the original example's files and optional CLI checks.

If the first run does not complete

SymptomFirst check
Dependency cannot be resolvedInstall the matching source into the same local Maven repository.
Missing API keyExport the key in each terminal or service environment.
Configuration file not foundRun from the demo root containing pipelogiq.yml.
Readiness failureVerify API URL, authentication and transport reachability.
Pipeline stays pendingKeep a worker online with the same application key and matching stage names.
Previous result appears againReusing an order ID reuses its idempotency key.

For failed or waiting runs, use the dashboard guide to inspect their recorded state.

Create the project yourself

The download already contains these files. Use this alternative to recreate its worker and basic producer, or to read how the example works.

pom.xml:

xml
<project xmlns="http://maven.apache.org/POM/4.0.0">
  <modelVersion>4.0.0</modelVersion>
  <groupId>example</groupId>
  <artifactId>pipelogiq-java-demo</artifactId>
  <version>1.0.0</version>
  <properties>
    <maven.compiler.release>17</maven.compiler.release>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>com.pipelogiq</groupId>
      <artifactId>pipelogiq-sdk</artifactId>
      <version>0.5.0</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.16.0</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <version>3.8.1</version>
      </plugin>
    </plugins>
  </build>
</project>

pipelogiq.yml in the demo's root directory:

yaml
pipelogiq:
  api-url: ${PIPELOGIQ_API_URL:http://localhost:8081}
  api-key: ${PIPELOGIQ_API_KEY}
  worker-name: orders-java
  environment: development
  transport: ${PIPELOGIQ_TRANSPORT:http}
  max-concurrency: 4

Write the worker and client

Create the following five files under src/main/java/example/. They are included in the download, along with a separate inspection and testing CLI.

Order.java

java
package example;

import java.math.BigDecimal;

public record Order(String orderId, BigDecimal amount) {}

ValidateOrder.java

java
package example;

import io.pipelogiq.sdk.core.execution.*;

@Stage("ValidateOrder")
public final class ValidateOrder implements StageHandler<Order> {
  @Override
  public StageResult execute(Order order, StageContext context) {
    context.throwIfCancelled();
    if (order.orderId() == null || order.orderId().isBlank()) {
      return StageResult.validationError("Order ID is required");
    }
    if (order.amount() == null || order.amount().signum() <= 0) {
      return StageResult.validationError("Amount must be positive");
    }
    context.put("validatedOrder", order);
    context.logInfo("Order validated");
    return StageResult.success();
  }
}

RecordOrder.java

java
package example;

import io.pipelogiq.sdk.core.execution.*;

@Stage("RecordOrder")
public final class RecordOrder implements NoInputStageHandler {
  @Override
  public StageResult execute(StageContext context) {
    Order order = context.require("validatedOrder", Order.class);
    context.put("recorded", true);
    return StageResult.success("Recorded demo order " + order.orderId());
  }
}

@Stage supplies a stable wire name. The SDK infers the input type from StageHandler<Order>; NoInputStageHandler reads required context without a dummy input argument. context.require classifies missing or incompatible data for you.

OrdersExample.java

java
package example;

import io.pipelogiq.sdk.Pipelogiq;

/** Run from the examples directory; the SDK owns startup, readiness and SIGTERM shutdown. */
public final class OrdersExample {
  public static void main(String[] args) {
    Pipelogiq.worker().config("pipelogiq.yml").stages(ValidateOrder.class, RecordOrder.class).run();
  }
}

The SDK owns client creation, transport selection, registration, readiness, leases, input conversion, result delivery and shutdown. Deploy this entry point as its own continuously running service. Worker startup does not submit a pipeline.

CreateOrder.java

java
package example;

import io.pipelogiq.sdk.Pipelogiq;
import java.math.BigDecimal;
import java.time.Duration;

/** Run with OrdersExample (or SpringOrdersApplication) already listening. */
public final class CreateOrder {
  public static void main(String[] args) {
    try (var client = Pipelogiq.connect("pipelogiq.yml")) {
      var created = client.pipeline("Process order")
          .idempotencyKey("demo-order-intro-123")
          .stage(ValidateOrder.class, new Order("intro-123", new BigDecimal("42.50")))
          .stage(RecordOrder.class)
          .send();
      var completed = client.pipelines()
          .waitForCompletion(created.id(), Duration.ofSeconds(60));
      System.out.println("Pipeline " + completed.id() + ": " + completed.status());
      System.out.println("Recorded: " + completed.context("recorded", Boolean.class));
    }
  }
}

The producer owns one typed client for its operation. Pipeline drafts do not open separate connections and do not need their own close(). There is no application polling loop: waitForCompletion is bounded by the timeout supplied to it.

Build and run these files using the commands above.

Additional CLI checks

The downloadable project also includes CreatePipelineExample, a utility for submitting different orders, inspecting status, and exercising failures and idempotency. It is not required by the five-file application above. If you created those files manually, obtain this optional utility from the demo download before running these commands:

sh
java -cp 'target/classes:target/dependency/*' example.CreatePipelineExample submit order-001 42.50

It prints Pipeline ID: <id>. Replace 123 below with that ID:

sh
java -cp 'target/classes:target/dependency/*' example.CreatePipelineExample get 123
java -cp 'target/classes:target/dependency/*' example.CreatePipelineExample wait 123 60

get reads a snapshot, which may still be pending or running. wait prints COMPLETED, Recorded: true and the statuses of ValidateOrder and RecordOrder. This utility uses demo-order-<orderId> as its idempotency key; choose a fresh order ID for a new request.

Try the two expected-behavior checks:

sh
java -cp 'target/classes:target/dependency/*' example.CreatePipelineExample validate-failure rejected-001
java -cp 'target/classes:target/dependency/*' example.CreatePipelineExample idempotency repeated-001

The first prints a FAILED pipeline with VALIDATION_ERROR and Recorded: false. The second prints equal IDs and Same pipeline: true, then observes completion. A local wait timeout does not cancel server work; inspect or wait again using the same ID.

Press Ctrl+C in the worker terminal to stop gracefully. To repeat the experiment over AMQP, set PIPELOGIQ_TRANSPORT=amqp before starting the worker and use a new order ID. Broker settings come from server bootstrap; see configuration.

The workflow recipes, schedules, Spring Boot guide and agent guide build on this connection. For more failure symptoms, use troubleshooting.

Start here, or search all 43 pages

↑ ↓ to select · Enter to open · Esc to close