use of io.camunda.zeebe.client.ZeebeClient in project zdb by Zelldon.
the class ZeebeTest method shouldOpenAndReadState.
@Test
public void shouldOpenAndReadState() {
// given
final ZeebeClient client = ZeebeClient.newClientBuilder().gatewayAddress(zeebeContainer.getExternalGatewayAddress()).usePlaintext().build();
final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().endEvent().done();
final DeploymentEvent deploymentEvent = client.newDeployCommand().addProcessModel(process, "process.bpmn").send().join();
// when
final var readonlyTransactionDb = ReadonlyTransactionDb.Companion.openReadonlyDb(ZeebePaths.Companion.getRuntimePath(tempDir, "1"));
var zeebeState = new ZeebeDbState(readonlyTransactionDb, readonlyTransactionDb.createContext());
// then
final var processState = zeebeState.getProcessState();
final var processes = processState.getProcesses();
assertThat(processes).hasSize(1);
final var deployedProcesses = new ArrayList<DeployedProcess>(processes);
final var deployedProcess = deployedProcesses.get(0);
assertThat(deployedProcess.getVersion()).isEqualTo(1);
assertThat(deployedProcess.getBpmnProcessId()).isEqualTo(BufferUtil.wrapString("process"));
assertThat(deployedProcess.getResourceName()).isEqualTo(BufferUtil.wrapString("process.bpmn"));
assertThat(deployedProcess.getKey()).isEqualTo(deploymentEvent.getProcesses().get(0).getProcessDefinitionKey());
}
use of io.camunda.zeebe.client.ZeebeClient in project zdb by Zelldon.
the class ZeebeTest method shouldRunProcessInstanceUntilEnd.
/**
* Just ot verify whether test container works with Zeebe Client.
*/
@Test
public void shouldRunProcessInstanceUntilEnd() {
// given
final ZeebeClient client = ZeebeClient.newClientBuilder().gatewayAddress(zeebeContainer.getExternalGatewayAddress()).usePlaintext().build();
final BpmnModelInstance process = Bpmn.createExecutableProcess("process").startEvent().endEvent().done();
// when
final DeploymentEvent deploymentEvent = client.newDeployCommand().addProcessModel(process, "process.bpmn").send().join();
// then
final ProcessInstanceResult processInstanceResult = client.newCreateInstanceCommand().bpmnProcessId("process").latestVersion().withResult().send().join();
assertThat(processInstanceResult.getProcessDefinitionKey()).isEqualTo(deploymentEvent.getProcesses().get(0).getProcessDefinitionKey());
}
use of io.camunda.zeebe.client.ZeebeClient in project zeebe-process-test by camunda.
the class EngineClientTest method shouldUseGatewayAddressToBuildClient.
@Test
void shouldUseGatewayAddressToBuildClient() {
// given
final ZeebeClient client = ZeebeClient.newClientBuilder().usePlaintext().gatewayAddress(zeebeEngine.getGatewayAddress()).build();
// when
final Topology topology = zeebeClient.newTopologyRequest().send().join();
client.close();
// then
assertThat(topology).isNotNull();
}
use of io.camunda.zeebe.client.ZeebeClient in project camunda-platform-get-started by camunda.
the class DeployAndStartInstance method main.
public static void main(String[] args) {
try (ZeebeClient client = ZeebeClientFactory.getZeebeClient()) {
client.newDeployResourceCommand().addResourceFromClasspath("send-email.bpmn").send().join();
final ProcessInstanceEvent event = client.newCreateInstanceCommand().bpmnProcessId("send-email").latestVersion().variables(Map.of("message_content", "Hello from the Java get started")).send().join();
LOG.info("Started instance for processDefinitionKey='{}', bpmnProcessId='{}', version='{}' with processInstanceKey='{}'", event.getProcessDefinitionKey(), event.getBpmnProcessId(), event.getVersion(), event.getProcessInstanceKey());
}
}
use of io.camunda.zeebe.client.ZeebeClient in project camunda-platform-get-started by camunda.
the class EmailWorker method main.
public static void main(String[] args) {
try (ZeebeClient client = ZeebeClientFactory.getZeebeClient()) {
client.newWorker().jobType("email").handler((jobClient, job) -> {
final String message_content = (String) job.getVariablesAsMap().get("message_content");
LOG.info("Sending email with message content: {}", message_content);
jobClient.newCompleteCommand(job.getKey()).send().whenComplete((result, exception) -> {
if (exception == null) {
LOG.info("Completed job successful with result:" + result);
} else {
LOG.error("Failed to complete job", exception);
}
});
}).open();
// run until System.in receives exit command
waitUntilSystemInput("exit");
}
}
Aggregations