Skip to main content

Handle variables as POJO

Prerequisites​

  1. Run the Zeebe broker with endpoint localhost:26500 (default).
  2. Run the deploy a process example.

HandleVariablesAsPojo.java​

Source on GitHub

    ...
try (final ZeebeClient client = clientBuilder.build()) {
final Order order = new Order();
order.setOrderId(31243);

client
.newCreateInstanceCommand()
.bpmnProcessId("demoProcess")
.latestVersion()
.variables(order)
.send()
.join();

client.newWorker().jobType("foo").handler(new DemoJobHandler()).open();

// run until System.in receives exit command
waitUntilSystemInput("exit");
}
}

public static class Order {
private long orderId;
private double totalPrice;

public long getOrderId() {
return orderId;
}

public void setOrderId(final long orderId) {
this.orderId = orderId;
}

public double getTotalPrice() {
return totalPrice;
}

public void setTotalPrice(final double totalPrice) {
this.totalPrice = totalPrice;
}
}

private static class DemoJobHandler implements JobHandler {
@Override
public void handle(final JobClient client, final ActivatedJob job) {
// read the variables of the job
final Order order = job.getVariablesAsType(Order.class);
System.out.println("new job with orderId: " + order.getOrderId());

// update the variables and complete the job
order.setTotalPrice(46.50);

client.newCompleteCommand(job.getKey()).variables(order).send();
}
}