Search in sources :

Example 1 with ZeebeClient

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());
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) ArrayList(java.util.ArrayList) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) ZeebeDbState(io.camunda.zeebe.engine.state.ZeebeDbState) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) Test(org.junit.jupiter.api.Test)

Example 2 with ZeebeClient

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());
}
Also used : ProcessInstanceResult(io.camunda.zeebe.client.api.response.ProcessInstanceResult) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) BpmnModelInstance(io.camunda.zeebe.model.bpmn.BpmnModelInstance) DeploymentEvent(io.camunda.zeebe.client.api.response.DeploymentEvent) Test(org.junit.jupiter.api.Test)

Example 3 with ZeebeClient

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();
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Topology(io.camunda.zeebe.client.api.response.Topology) Test(org.junit.jupiter.api.Test)

Example 4 with ZeebeClient

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());
    }
}
Also used : ZeebeClient(io.camunda.zeebe.client.ZeebeClient) ProcessInstanceEvent(io.camunda.zeebe.client.api.response.ProcessInstanceEvent)

Example 5 with ZeebeClient

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");
    }
}
Also used : Logger(org.apache.logging.log4j.Logger) ZeebeClient(io.camunda.zeebe.client.ZeebeClient) Scanner(java.util.Scanner) LogManager(org.apache.logging.log4j.LogManager) ZeebeClient(io.camunda.zeebe.client.ZeebeClient)

Aggregations

ZeebeClient (io.camunda.zeebe.client.ZeebeClient)90 ZeebeClientBuilder (io.camunda.zeebe.client.ZeebeClientBuilder)27 Test (org.junit.jupiter.api.Test)23 Topology (io.camunda.zeebe.client.api.response.Topology)16 ProcessInstanceEvent (io.camunda.zeebe.client.api.response.ProcessInstanceEvent)13 JobWorker (io.camunda.zeebe.client.api.worker.JobWorker)13 BpmnModelInstance (io.camunda.zeebe.model.bpmn.BpmnModelInstance)13 Test (org.junit.Test)12 Timeout (org.junit.jupiter.api.Timeout)11 Duration (java.time.Duration)10 DeploymentEvent (io.camunda.zeebe.client.api.response.DeploymentEvent)9 Bpmn (io.camunda.zeebe.model.bpmn.Bpmn)9 Awaitility (org.awaitility.Awaitility)8 Map (java.util.Map)7 BrokerInfo (io.camunda.zeebe.client.api.response.BrokerInfo)6 HashMap (java.util.HashMap)6 List (java.util.List)6 Optional (java.util.Optional)6 ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)6 Future (java.util.concurrent.Future)6