use of io.zeebe.client.task.cmd.CreateTaskCommand 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.task.cmd.CreateTaskCommand in project zeebe by zeebe-io.
the class ClientCommandManagerTest method testRequestFailure.
@Test
public void testRequestFailure() {
// given
stubRequestProcessingFailureResponse();
final CreateTaskCommand command = createTaskCmd();
// when
assertThatThrownBy(command::execute).isInstanceOf(RuntimeException.class).hasMessageContaining("Request exception (REQUEST_PROCESSING_FAILURE): test");
// then
assertAtLeastTopologyRefreshRequests(1);
assertCreateTaskRequests(1);
}
Aggregations