use of io.zeebe.client.impl.ZeebeClientImpl 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.impl.ZeebeClientImpl 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.impl.ZeebeClientImpl in project zeebe by zeebe-io.
the class ClientRule method interruptBrokerConnections.
public void interruptBrokerConnections() {
final ClientTransport transport = ((ZeebeClientImpl) client).getTransport();
transport.interruptAllChannels();
}
use of io.zeebe.client.impl.ZeebeClientImpl in project zeebe by zeebe-io.
the class TaskSubscriptionTest method shouldRetryWithMoreTasksThanSubscriptionCapacity.
/**
* This tests a case that should not occur under normal circumstances, but might occur
* in case of inconsistencies between broker and client state (e.g. due to bugs in either of them)
*/
@Test
public void shouldRetryWithMoreTasksThanSubscriptionCapacity() throws InterruptedException {
// given
broker.stubTaskSubscriptionApi(123L);
broker.onExecuteCommandRequest(EventType.TASK_EVENT, "COMPLETE").respondWith().key((r) -> r.key()).event().allOf((r) -> r.getCommand()).put("state", "COMPLETED").done().register();
final WaitingTaskHandler handler = new WaitingTaskHandler();
final Properties clientProperties = ((ZeebeClientImpl) client).getInitializationProperties();
final int numExecutionThreads = Integer.parseInt(clientProperties.getProperty(ClientProperties.CLIENT_SUBSCRIPTION_EXECUTION_THREADS));
final int taskCapacity = 4;
clientRule.tasks().newTaskSubscription(clientRule.getDefaultTopicName()).handler(handler).lockOwner("owner").lockTime(1000L).taskFetchSize(taskCapacity).taskType("foo").open();
final RemoteAddress clientAddress = broker.getReceivedControlMessageRequests().get(0).getSource();
for (int i = 0; i < taskCapacity + numExecutionThreads; i++) {
broker.pushLockedTask(clientAddress, 123L, i, i, "owner", "foo");
}
TestUtil.waitUntil(() -> handler.numWaitingThreads.get() > 0);
// pushing one more event, exceeding client capacity
broker.pushLockedTask(clientAddress, 123L, Integer.MAX_VALUE, Integer.MAX_VALUE, "owner", "foo");
// waiting for the client to receive all pending tasks
Thread.sleep(500L);
// when
handler.shouldWait = false;
continueTaskHandlingThreads();
// then the additional event is handled nevertheless (i.e. client applies backpressure)
TestUtil.waitUntil(() -> handler.numHandledEvents.get() == taskCapacity + numExecutionThreads + 1);
}
use of io.zeebe.client.impl.ZeebeClientImpl 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);
}
}
}
}
Aggregations