Search in sources :

Example 6 with ZeebeClient

use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.

the class CreateTopic method main.

public static void main(final String[] args) {
    final String broker = "localhost:51015";
    final String topic = "default-topic";
    final int partitions = 1;
    final Properties clientProperties = new Properties();
    clientProperties.put(ClientProperties.BROKER_CONTACTPOINT, broker);
    try (ZeebeClient client = ZeebeClient.create(clientProperties)) {
        System.out.println("Creating topic " + topic + " with " + partitions + " partition(s) with contact point " + broker);
        System.out.println(client.topics().create(topic, partitions).execute().getState());
    }
}
Also used : ZeebeClient(io.zeebe.client.ZeebeClient) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties)

Example 7 with ZeebeClient

use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.

the class TypedEventLogger 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 Consumer<Event> logger = e -> {
        System.out.println(e.getMetadata());
        System.out.println(e);
        System.out.println();
    };
    final TopicSubscription subscription = zeebeClient.topics().newSubscription(topicName).name("logger").startAtHeadOfTopic().forcedStart().workflowEventHandler(logger::accept).workflowInstanceEventHandler(logger::accept).taskEventHandler(logger::accept).incidentEventHandler(logger::accept).open();
    // 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 : Consumer(java.util.function.Consumer) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) Scanner(java.util.Scanner) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) io.zeebe.client.event(io.zeebe.client.event) ZeebeClient(io.zeebe.client.ZeebeClient) Scanner(java.util.Scanner) ZeebeClient(io.zeebe.client.ZeebeClient) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl)

Example 8 with ZeebeClient

use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.

the class WorkflowInstanceWorker method main.

public static void main(String[] args) {
    final String brokerContactPoint = "127.0.0.1:51015";
    final String topicName = "default-topic";
    final int partitionId = 0;
    final String taskType = "foo";
    final String lockOwner = "worker-1";
    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("> Open task subscription for topic '%s', partition '%d' and type '%s'", topicName, partitionId, taskType));
    final TaskSubscription subscription = zeebeClient.tasks().newTaskSubscription(topicName).taskType(taskType).lockOwner(lockOwner).lockTime(Duration.ofSeconds(10)).handler((client, task) -> {
        System.out.println(String.format(">>> [type: %s, key: %s, lockExpirationTime: %s]\n[headers: %s]\n[payload: %s]\n===", task.getType(), task.getMetadata().getKey(), task.getLockExpirationTime().toString(), task.getHeaders(), task.getPayload()));
        client.complete(task).withoutPayload().execute();
    }).open();
    System.out.println("> Opened.");
    // wait for tasks
    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) Duration(java.time.Duration) ClientProperties(io.zeebe.client.ClientProperties) Scanner(java.util.Scanner) TaskSubscription(io.zeebe.client.task.TaskSubscription) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ZeebeClient(io.zeebe.client.ZeebeClient) Scanner(java.util.Scanner) TaskSubscription(io.zeebe.client.task.TaskSubscription) ZeebeClient(io.zeebe.client.ZeebeClient) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl)

Example 9 with ZeebeClient

use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.

the class BrokerRestartTest method shouldCreateUniquePartitionIdsAfterRestart.

@Test
public void shouldCreateUniquePartitionIdsAfterRestart() {
    // given
    final ZeebeClient client = clientRule.getClient();
    client.topics().create("foo", 2).execute();
    restartBroker();
    // when
    client.topics().create("bar", 2).execute();
    // then
    final TopologyResponse topology = client.requestTopology().execute();
    final List<TopologyBroker> brokers = topology.getBrokers();
    assertThat(brokers).hasSize(1);
    final TopologyBroker topologyBroker = brokers.get(0);
    final List<BrokerPartitionState> partitions = topologyBroker.getPartitions();
    // default partition + system partition + 4 partitions we create here
    assertThat(partitions).hasSize(6);
    assertThat(partitions).extracting("partitionId").doesNotHaveDuplicates();
}
Also used : ZeebeClient(io.zeebe.client.ZeebeClient) TopologyResponse(io.zeebe.client.clustering.impl.TopologyResponse) BrokerPartitionState(io.zeebe.client.clustering.impl.BrokerPartitionState) TopologyBroker(io.zeebe.client.clustering.impl.TopologyBroker) Test(org.junit.Test)

Example 10 with ZeebeClient

use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.

the class BrokerRestartTest 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)

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