Search in sources :

Example 1 with ZeebeClient

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();
}
Also used : ZeebeClient(io.zeebe.client.ZeebeClient) Test(org.junit.Test)

Example 2 with ZeebeClient

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));
    }
}
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 3 with ZeebeClient

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);
            }
        }
    }
}
Also used : Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) Scanner(java.util.Scanner) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) TopicSubscription(io.zeebe.client.event.TopicSubscription) ZeebeClient(io.zeebe.client.ZeebeClient) EventMetadata(io.zeebe.client.event.EventMetadata) Scanner(java.util.Scanner) TopicSubscription(io.zeebe.client.event.TopicSubscription) ZeebeClient(io.zeebe.client.ZeebeClient) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) EventMetadata(io.zeebe.client.event.EventMetadata)

Example 4 with ZeebeClient

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");
}
Also used : ZeebeClient(io.zeebe.client.ZeebeClient) TaskEvent(io.zeebe.client.event.TaskEvent) Test(org.junit.Test)

Example 5 with ZeebeClient

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");
}
Also used : Topics(io.zeebe.client.topic.Topics) ZeebeClient(io.zeebe.client.ZeebeClient) TaskEvent(io.zeebe.client.event.TaskEvent) Topic(io.zeebe.client.topic.Topic) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Aggregations

ZeebeClient (io.zeebe.client.ZeebeClient)22 Test (org.junit.Test)15 ClientProperties (io.zeebe.client.ClientProperties)8 Properties (java.util.Properties)7 ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)5 TaskEvent (io.zeebe.client.event.TaskEvent)4 TopologyBroker (io.zeebe.client.clustering.impl.TopologyBroker)3 TopologyResponse (io.zeebe.client.clustering.impl.TopologyResponse)3 Duration (java.time.Duration)3 Scanner (java.util.Scanner)3 BrokerPartitionState (io.zeebe.client.clustering.impl.BrokerPartitionState)2 ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)2 TaskSubscription (io.zeebe.client.task.TaskSubscription)2 Topic (io.zeebe.client.topic.Topic)2 Topics (io.zeebe.client.topic.Topics)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Rule (org.junit.Rule)2 ClientRule (io.zeebe.broker.it.ClientRule)1