use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.
the class BrokerRestartTest method shouldNotCreatePreviouslyCreatedTopicAfterRestart.
@Test
public void shouldNotCreatePreviouslyCreatedTopicAfterRestart() {
// given
final ZeebeClient client = clientRule.getClient();
final String topicName = "foo";
client.topics().create(topicName, 2).execute();
restartBroker();
// then
exception.expect(ClientCommandRejectedException.class);
// when
client.topics().create(topicName, 2).execute();
}
use of io.zeebe.client.ZeebeClient 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.ZeebeClient in project zeebe by zeebe-io.
the class EventLogger method main.
public static void main(String[] args) {
final String brokerContactPoint = "127.0.0.1:51015";
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));
final String topicName = "default-topic";
System.out.println(String.format("> Open event subscription from topic '%s'", topicName));
final TopicSubscription subscription = zeebeClient.topics().newSubscription(topicName).startAtHeadOfTopic().forcedStart().name("logger").handler(event -> {
final EventMetadata metadata = event.getMetadata();
System.out.println(String.format(">>> [topic: %d, position: %d, key: %d, type: %s]\n%s\n===", metadata.getPartitionId(), metadata.getPosition(), metadata.getKey(), metadata.getType(), event.getJson()));
}).open();
System.out.println("> Opened.");
// wait for events
try (Scanner scanner = new Scanner(System.in)) {
while (scanner.hasNextLine()) {
final String nextLine = scanner.nextLine();
if (nextLine.contains("exit")) {
System.out.println("> Closing...");
subscription.close();
zeebeClient.close();
System.out.println("> Closed.");
System.exit(0);
}
}
}
}
use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.
the class BrokerRecoveryTest method shouldCreateTopicAfterRestart.
@Test
public void shouldCreateTopicAfterRestart() {
// given
final ZeebeClient client = clientRule.getClient();
restartBroker();
// when
client.topics().create("foo", 2).execute();
// then
final TaskEvent taskEvent = client.tasks().create("foo", "bar").execute();
assertThat(taskEvent.getState()).isEqualTo("CREATED");
}
use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.
the class TaskEventClusteredTest method shouldCreateTaskWhenFollowerUnavailable.
@Test
public void shouldCreateTaskWhenFollowerUnavailable() {
// given
final ZeebeClient client = clientRule.getClient();
final String topicName = "foo";
clusteringRule.createTopic(topicName, 1);
final Topics topics = client.topics().getTopics().execute();
final Topic topic = topics.getTopics().stream().filter(t -> topicName.equals(t.getName())).findFirst().get();
final TopologyBroker leader = clusteringRule.getLeaderForPartition(topic.getPartitions().get(0).getId());
// choosing a new leader in a raft group where the previously leading broker is no longer available
clusteringRule.stopBroker(leader.getSocketAddress());
// when
final TaskEvent taskEvent = client.tasks().create(topicName, "bar").execute();
// then
assertThat(taskEvent.getState()).isEqualTo("CREATED");
}
Aggregations