Search in sources :

Example 1 with ClientCommandRejectedException

use of io.zeebe.client.cmd.ClientCommandRejectedException in project zeebe by zeebe-io.

the class NonBlockingTaskCreator method main.

public static void main(String[] args) {
    final int tasks = 1_000_000;
    final Properties properties = System.getProperties();
    ClientProperties.setDefaults(properties);
    properties.putIfAbsent(SAMPLE_NUMBER_OF_REQUESTS, String.valueOf(tasks));
    properties.putIfAbsent(SAMPLE_MAX_CONCURRENT_REQUESTS, "128");
    properties.put(ClientProperties.CLIENT_MAXREQUESTS, "128");
    printProperties(properties);
    final int numOfRequests = Integer.parseInt(properties.getProperty(SAMPLE_NUMBER_OF_REQUESTS));
    final int maxConcurrentRequests = Integer.parseInt(properties.getProperty(SAMPLE_MAX_CONCURRENT_REQUESTS));
    final String topicName = "default-topic";
    try (ZeebeClient client = ZeebeClient.create(properties)) {
        try {
            // try to create default topic if it not exists already
            client.topics().create(topicName, 4).execute();
        } catch (final ClientCommandRejectedException e) {
        // topic already exists
        }
        final TasksClient asyncTaskService = client.tasks();
        final String payload = "{}";
        final long time = System.currentTimeMillis();
        long tasksCreated = 0;
        final List<Future<TaskEvent>> inFlightRequests = new LinkedList<>();
        while (tasksCreated < numOfRequests) {
            if (inFlightRequests.size() < maxConcurrentRequests) {
                final CreateTaskCommand cmd = asyncTaskService.create(topicName, "greeting").addCustomHeader("some", "value").payload(payload);
                inFlightRequests.add(cmd.executeAsync());
                tasksCreated++;
            }
            poll(inFlightRequests);
        }
        awaitAll(inFlightRequests);
        System.out.println("Took: " + (System.currentTimeMillis() - time));
    }
}
Also used : TasksClient(io.zeebe.client.TasksClient) ZeebeClient(io.zeebe.client.ZeebeClient) CreateTaskCommand(io.zeebe.client.task.cmd.CreateTaskCommand) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) Future(java.util.concurrent.Future) ClientProperties(io.zeebe.client.ClientProperties)

Example 2 with ClientCommandRejectedException

use of io.zeebe.client.cmd.ClientCommandRejectedException in project zeebe by zeebe-io.

the class CommandRequestHandler method getResult.

@Override
public EventImpl getResult(DirectBuffer buffer, int offset, int blockLength, int version) {
    decoder.wrap(buffer, offset, blockLength, version);
    final long key = decoder.key();
    final int partitionId = decoder.partitionId();
    final long position = decoder.position();
    final int eventLength = decoder.eventLength();
    final DirectBufferInputStream inStream = new DirectBufferInputStream(buffer, decoder.limit() + ExecuteCommandResponseDecoder.eventHeaderLength(), eventLength);
    final EventImpl result;
    try {
        result = objectMapper.readValue(inStream, event.getClass());
    } catch (Exception e) {
        throw new ClientException("Cannot deserialize event in response", e);
    }
    result.setKey(key);
    result.setPartitionId(partitionId);
    result.setTopicName(event.getMetadata().getTopicName());
    result.setEventPosition(position);
    if (expectedState != null && !expectedState.equals(result.getState())) {
        throw new ClientCommandRejectedException(errorFunction.apply(event, result));
    }
    return result;
}
Also used : DirectBufferInputStream(org.agrona.io.DirectBufferInputStream) EventImpl(io.zeebe.client.event.impl.EventImpl) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ClientException(io.zeebe.client.cmd.ClientException) ClientException(io.zeebe.client.cmd.ClientException) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException)

Example 3 with ClientCommandRejectedException

use of io.zeebe.client.cmd.ClientCommandRejectedException in project zeebe by zeebe-io.

the class WorkflowInstanceStarter method main.

public static void main(String[] args) {
    final String brokerContactPoint = "127.0.0.1:51015";
    final String bpmnProcessId = "demoProcess";
    final String topicName = "default-topic";
    final int partitionId = 0;
    final Properties clientProperties = new Properties();
    clientProperties.put(ClientProperties.BROKER_CONTACTPOINT, brokerContactPoint);
    final ZeebeClient zeebeClient = new ZeebeClientImpl(clientProperties);
    System.out.println(String.format("> Connecting to %s", brokerContactPoint));
    System.out.println(String.format("> Deploying workflow to topic '%s' and partition '%d'", topicName, partitionId));
    final DeploymentEvent deploymentResult = zeebeClient.workflows().deploy(topicName).addResourceFromClasspath("demoProcess.bpmn").execute();
    try {
        final String deployedWorkflows = deploymentResult.getDeployedWorkflows().stream().map(wf -> String.format("<%s:%d>", wf.getBpmnProcessId(), wf.getVersion())).collect(Collectors.joining(","));
        System.out.println(String.format("> Deployed: %s", deployedWorkflows));
        System.out.println(String.format("> Create workflow instance for workflow: %s", bpmnProcessId));
        zeebeClient.workflows().create(topicName).bpmnProcessId(bpmnProcessId).payload("{\"a\": \"b\"}").execute();
        System.out.println("> Created.");
    } catch (ClientCommandRejectedException exception) {
        System.out.println(String.format("> Fail to deploy: %s", exception.getMessage()));
    }
    System.out.println("> Closing...");
    zeebeClient.close();
    System.out.println("> Closed.");
}
Also used : Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) DeploymentEvent(io.zeebe.client.event.DeploymentEvent) Collectors(java.util.stream.Collectors) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ZeebeClient(io.zeebe.client.ZeebeClient) ZeebeClient(io.zeebe.client.ZeebeClient) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) DeploymentEvent(io.zeebe.client.event.DeploymentEvent)

Example 4 with ClientCommandRejectedException

use of io.zeebe.client.cmd.ClientCommandRejectedException in project zeebe by zeebe-io.

the class ZeebeClientTest method shouldIncludeCallingFrameInExceptionStacktrace.

@Test
public void shouldIncludeCallingFrameInExceptionStacktrace() {
    // given
    final TaskEventImpl baseEvent = Events.exampleTask();
    broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key(r -> r.key()).event().allOf((r) -> r.getCommand()).put("state", "COMPLETE_REJECTED").done().register();
    // when
    try {
        client.tasks().complete(baseEvent).execute();
        fail("should throw exception");
    } catch (ClientCommandRejectedException e) {
        // then
        assertThat(e.getStackTrace()).anySatisfy(frame -> {
            assertThat(frame.getClassName()).isEqualTo(this.getClass().getName());
            assertThat(frame.getMethodName()).isEqualTo(testContext.getMethodName());
        });
    }
}
Also used : TaskEvent(io.zeebe.client.event.TaskEvent) java.util(java.util) Events(io.zeebe.client.util.Events) TransportListener(io.zeebe.transport.TransportListener) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) ClientTopologyManager(io.zeebe.client.clustering.impl.ClientTopologyManager) Protocol(io.zeebe.protocol.Protocol) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) TopicSubscription(io.zeebe.client.event.TopicSubscription) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) RemoteAddress(io.zeebe.transport.RemoteAddress) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) TestName(org.junit.rules.TestName) After(org.junit.After) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ExpectedException(org.junit.rules.ExpectedException) MsgPackConverter(io.zeebe.client.impl.data.MsgPackConverter) Before(org.junit.Before) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) java.util.concurrent(java.util.concurrent) ServerTransport(io.zeebe.transport.ServerTransport) Test(org.junit.Test) ClientTransport(io.zeebe.transport.ClientTransport) Assertions.fail(org.assertj.core.api.Assertions.fail) Rule(org.junit.Rule) ClientException(io.zeebe.client.cmd.ClientException) EventType(io.zeebe.protocol.clientapi.EventType) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) ClientApiRule(io.zeebe.test.broker.protocol.clientapi.ClientApiRule) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) TaskEventImpl(io.zeebe.client.event.impl.TaskEventImpl) Test(org.junit.Test)

Aggregations

ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)4 ClientProperties (io.zeebe.client.ClientProperties)2 ZeebeClient (io.zeebe.client.ZeebeClient)2 ClientException (io.zeebe.client.cmd.ClientException)2 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)2 TasksClient (io.zeebe.client.TasksClient)1 ClientTopologyManager (io.zeebe.client.clustering.impl.ClientTopologyManager)1 DeploymentEvent (io.zeebe.client.event.DeploymentEvent)1 TaskEvent (io.zeebe.client.event.TaskEvent)1 TopicSubscription (io.zeebe.client.event.TopicSubscription)1 EventImpl (io.zeebe.client.event.impl.EventImpl)1 TaskEventImpl (io.zeebe.client.event.impl.TaskEventImpl)1 MsgPackConverter (io.zeebe.client.impl.data.MsgPackConverter)1 CreateTaskCommand (io.zeebe.client.task.cmd.CreateTaskCommand)1 Events (io.zeebe.client.util.Events)1 Protocol (io.zeebe.protocol.Protocol)1 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)1 EventType (io.zeebe.protocol.clientapi.EventType)1 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)1 ClientApiRule (io.zeebe.test.broker.protocol.clientapi.ClientApiRule)1