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));
}
}
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;
}
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.");
}
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());
});
}
}
Aggregations