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());
}
}
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);
}
}
}
}
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);
}
}
}
}
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();
}
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");
}
Aggregations