use of io.zeebe.client.TasksClient 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));
}
}
Aggregations