use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldReceiveTasksFromMultiplePartitions.
@Test
public void shouldReceiveTasksFromMultiplePartitions() {
// given
final String topicName = "gyros";
final int numPartitions = 2;
final ZeebeClient client = clientRule.getClient();
client.topics().create(topicName, numPartitions).execute();
final Topics topics = client.topics().getTopics().execute();
final Topic topic = topics.getTopics().stream().filter(t -> t.getName().equals(topicName)).findFirst().get();
final Integer[] partitionIds = topic.getPartitions().stream().mapToInt(p -> p.getId()).boxed().toArray(Integer[]::new);
final String taskType = "foooo";
final RecordingTaskHandler handler = new RecordingTaskHandler();
createTaskOnPartition(client, topicName, partitionIds[0], taskType);
createTaskOnPartition(client, topicName, partitionIds[1], taskType);
// when
client.tasks().newTaskSubscription(topicName).handler(handler).lockOwner("foo").lockTime(Duration.ofSeconds(30)).taskType(taskType).open();
// then
waitUntil(() -> handler.getHandledTasks().size() == 2);
final Integer[] receivedPartitionIds = handler.getHandledTasks().stream().map(t -> t.getMetadata().getPartitionId()).toArray(Integer[]::new);
assertThat(receivedPartitionIds).containsExactlyInAnyOrder(partitionIds);
}
use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.
the class TopologyViewer method main.
public static void main(final String[] args) {
final String[] brokers = new String[] { "localhost:51015", "localhost:41015", "localhost:31015" };
for (final String broker : brokers) {
final Properties clientProperties = new Properties();
clientProperties.put(ClientProperties.BROKER_CONTACTPOINT, broker);
try (ZeebeClient zeebeClient = ZeebeClient.create(clientProperties)) {
final TopologyResponse topology = zeebeClient.requestTopology().execute();
System.out.println("Requesting topology with initial contact point " + broker);
System.out.println(" Topology:");
topology.getBrokers().forEach(b -> {
System.out.println(" " + b.getSocketAddress());
b.getPartitions().forEach(p -> System.out.println(" " + p.getTopicName() + "." + p.getPartitionId() + " - " + p.getState()));
});
} catch (final Exception e) {
System.out.println("Broker " + broker + " not available");
}
}
}
use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.
the class WorkflowInstanceStarter method main.
public static void main(String[] args) {
final String brokerContactPoint = "127.0.0.1:51015";
final String bpmnProcessId = "demoProcess";
final String topicName = "default-topic";
final int partitionId = 0;
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("> Deploying workflow to topic '%s' and partition '%d'", topicName, partitionId));
final DeploymentEvent deploymentResult = zeebeClient.workflows().deploy(topicName).addResourceFromClasspath("demoProcess.bpmn").execute();
try {
final String deployedWorkflows = deploymentResult.getDeployedWorkflows().stream().map(wf -> String.format("<%s:%d>", wf.getBpmnProcessId(), wf.getVersion())).collect(Collectors.joining(","));
System.out.println(String.format("> Deployed: %s", deployedWorkflows));
System.out.println(String.format("> Create workflow instance for workflow: %s", bpmnProcessId));
zeebeClient.workflows().create(topicName).bpmnProcessId(bpmnProcessId).payload("{\"a\": \"b\"}").execute();
System.out.println("> Created.");
} catch (ClientCommandRejectedException exception) {
System.out.println(String.format("> Fail to deploy: %s", exception.getMessage()));
}
System.out.println("> Closing...");
zeebeClient.close();
System.out.println("> Closed.");
}
use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.
the class RequestTopicsTest method shouldRequestTopics.
@Test
public void shouldRequestTopics() {
// given
final List<Map<String, Object>> partitions = new ArrayList<>();
partitions.add(buildPartition(1, "foo"));
partitions.add(buildPartition(2, "foo"));
partitions.add(buildPartition(3, "bar"));
brokerRule.onControlMessageRequest(r -> r.messageType() == ControlMessageType.REQUEST_PARTITIONS && r.partitionId() == Protocol.SYSTEM_PARTITION).respondWith().data().put("partitions", partitions).done().register();
final ZeebeClient client = clientRule.getClient();
// when
final Topics result = client.topics().getTopics().execute();
// then
final List<Topic> returnedTopics = result.getTopics();
assertThat(returnedTopics).hasSize(2);
final Map<String, List<Partition>> topicsByName = returnedTopics.stream().collect(Collectors.toMap(Topic::getName, Topic::getPartitions));
assertThat(topicsByName.get("foo")).hasSize(2).areExactly(1, matching(1, "foo")).areExactly(1, matching(2, "foo"));
assertThat(topicsByName.get("bar")).hasSize(1).areExactly(1, matching(3, "bar"));
final List<ControlMessageRequest> partitionRequests = brokerRule.getReceivedControlMessageRequests().stream().filter(r -> r.messageType() == ControlMessageType.REQUEST_PARTITIONS).collect(Collectors.toList());
assertThat(partitionRequests).hasSize(1);
final ControlMessageRequest request = partitionRequests.get(0);
assertThat(request.partitionId()).isEqualTo(Protocol.SYSTEM_PARTITION);
}
use of io.zeebe.client.ZeebeClient in project zeebe by zeebe-io.
the class ClientConfigurationTest method shouldConfigureKeepAlive.
@Test
public void shouldConfigureKeepAlive() {
// given
final Properties props = new Properties();
props.put(ClientProperties.CLIENT_TCP_CHANNEL_KEEP_ALIVE_PERIOD, Long.toString(KEEP_ALIVE_TIMEOUT));
final Duration expectedTimeout = Duration.ofMillis(KEEP_ALIVE_TIMEOUT);
// when
final ZeebeClient client = ZeebeClient.create(props);
// then
final ClientTransport transport = ((ZeebeClientImpl) client).getTransport();
assertThat(transport.getChannelKeepAlivePeriod()).isEqualTo(expectedTimeout);
}
Aggregations