Search in sources :

Example 6 with ZeebeClientImpl

use of io.zeebe.client.impl.ZeebeClientImpl 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.");
}
Also used : Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) DeploymentEvent(io.zeebe.client.event.DeploymentEvent) Collectors(java.util.stream.Collectors) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ZeebeClient(io.zeebe.client.ZeebeClient) ZeebeClient(io.zeebe.client.ZeebeClient) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) DeploymentEvent(io.zeebe.client.event.DeploymentEvent)

Example 7 with ZeebeClientImpl

use of io.zeebe.client.impl.ZeebeClientImpl 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);
}
Also used : ZeebeClient(io.zeebe.client.ZeebeClient) Duration(java.time.Duration) Properties(java.util.Properties) ClientProperties(io.zeebe.client.ClientProperties) ClientTransport(io.zeebe.transport.ClientTransport) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) Test(org.junit.Test)

Example 8 with ZeebeClientImpl

use of io.zeebe.client.impl.ZeebeClientImpl in project zeebe by zeebe-io.

the class ZeebeClientTopologyTimeoutTest method buildClient.

protected ZeebeClient buildClient() {
    final Properties properties = new Properties();
    properties.setProperty(ClientProperties.CLIENT_REQUEST_TIMEOUT_SEC, "1");
    final ZeebeClient client = new ZeebeClientImpl(properties, clientClock);
    closeables.manage(client);
    return client;
}
Also used : Properties(java.util.Properties) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl)

Example 9 with ZeebeClientImpl

use of io.zeebe.client.impl.ZeebeClientImpl in project zeebe by zeebe-io.

the class PollableTopicSubscriptionTest method shouldAcknowledgeOnlyOnceWhenTriggeredMultipleTimes.

@Test
public void shouldAcknowledgeOnlyOnceWhenTriggeredMultipleTimes() throws InterruptedException {
    // given
    final long subscriberKey = 123L;
    broker.stubTopicSubscriptionApi(subscriberKey);
    final ResponseController ackResponseController = stubAcknowledgeRequest().registerControlled();
    final PollableTopicSubscription subscription = clientRule.topics().newPollableSubscription(clientRule.getDefaultTopicName()).startAtHeadOfTopic().name(SUBSCRIPTION_NAME).open();
    final int subscriptionCapacity = ((ZeebeClientImpl) client).getSubscriptionPrefetchCapacity();
    final int replenishmentThreshold = (int) (subscriptionCapacity * (1.0d - Subscriber.REPLENISHMENT_THRESHOLD));
    final RemoteAddress clientAddress = receivedSubscribeCommands().findFirst().get().getSource();
    // push and handle as many events such that an ACK is triggered
    for (int i = 0; i < replenishmentThreshold + 1; i++) {
        broker.pushTopicEvent(clientAddress, subscriberKey, i, i);
    }
    final AtomicInteger handledEvents = new AtomicInteger(0);
    doRepeatedly(() -> handledEvents.addAndGet(subscription.poll(DO_NOTHING))).until(e -> e == replenishmentThreshold + 1);
    waitUntil(() -> receivedAckRequests().count() == 1);
    // when consuming another event (while the ACK is not yet confirmed)
    broker.pushTopicEvent(clientAddress, subscriberKey, 99, 99);
    doRepeatedly(() -> subscription.poll(DO_NOTHING)).until(e -> e == 1);
    // then
    // give some time for another ACK request
    Thread.sleep(500L);
    ackResponseController.unblockNextResponse();
    final List<ExecuteCommandRequest> ackRequests = receivedAckRequests().collect(Collectors.toList());
    // and not two
    assertThat(ackRequests).hasSize(1);
    // unblock the request so tear down succeeds
    stubAcknowledgeRequest().register();
}
Also used : RemoteAddress(io.zeebe.transport.RemoteAddress) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ResponseController(io.zeebe.test.broker.protocol.brokerapi.ResponseController) Test(org.junit.Test)

Example 10 with ZeebeClientImpl

use of io.zeebe.client.impl.ZeebeClientImpl in project zeebe by zeebe-io.

the class TopicSubscriptionTest method shouldCloseSubscriptionWhileOpeningSubscriber.

@Test
public void shouldCloseSubscriptionWhileOpeningSubscriber() {
    // given
    final int subscriberKey = 123;
    broker.stubTopicSubscriptionApi(0L);
    final ResponseController responseController = broker.onExecuteCommandRequest(EventType.SUBSCRIBER_EVENT, "SUBSCRIBE").respondWith().key(subscriberKey).event().allOf((r) -> r.getCommand()).put("state", "SUBSCRIBED").done().registerControlled();
    final TopicSubscriptionBuilderImpl builder = (TopicSubscriptionBuilderImpl) client.topics().newSubscription(clientRule.getDefaultTopicName()).handler(DO_NOTHING).name("foo");
    final Future<TopicSubscriberGroup> future = builder.buildSubscriberGroup();
    waitUntil(() -> broker.getReceivedCommandRequests().stream().filter(r -> r.eventType() == EventType.SUBSCRIBER_EVENT && "SUBSCRIBE".equals(r.getCommand().get("state"))).count() == 1);
    final Thread closingThread = new Thread(client::close);
    closingThread.start();
    final SubscriptionManager subscriptionManager = ((ZeebeClientImpl) client).getSubscriptionManager();
    waitUntil(() -> subscriptionManager.isClosing());
    // when
    responseController.unblockNextResponse();
    // then
    waitUntil(() -> future.isDone());
    assertThat(future).isDone();
    final Optional<ControlMessageRequest> closeRequest = broker.getReceivedControlMessageRequests().stream().filter(c -> c.messageType() == ControlMessageType.REMOVE_TOPIC_SUBSCRIPTION).findFirst();
    assertThat(closeRequest).isPresent();
    final ControlMessageRequest request = closeRequest.get();
    assertThat(request.getData()).containsEntry("subscriberKey", subscriberKey);
}
Also used : SubscriptionManager(io.zeebe.client.task.impl.subscription.SubscriptionManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ControlMessageType(io.zeebe.protocol.clientapi.ControlMessageType) TimeoutException(java.util.concurrent.TimeoutException) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) ZeebeClient(io.zeebe.client.ZeebeClient) StubBrokerRule(io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule) Future(java.util.concurrent.Future) ErrorCode(io.zeebe.protocol.clientapi.ErrorCode) RemoteAddress(io.zeebe.transport.RemoteAddress) ClientRule(io.zeebe.client.util.ClientRule) TopicSubscriberGroup(io.zeebe.client.event.impl.TopicSubscriberGroup) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Duration(java.time.Duration) ExpectedException(org.junit.rules.ExpectedException) Before(org.junit.Before) TopicSubscriptionBuilderImpl(io.zeebe.client.event.impl.TopicSubscriptionBuilderImpl) TestUtil.waitUntil(io.zeebe.test.util.TestUtil.waitUntil) Set(java.util.Set) Test(org.junit.Test) Collectors(java.util.stream.Collectors) ResponseController(io.zeebe.test.broker.protocol.brokerapi.ResponseController) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) RuleChain(org.junit.rules.RuleChain) ActorFuture(io.zeebe.util.sched.future.ActorFuture) List(java.util.List) Stream(java.util.stream.Stream) Rule(org.junit.Rule) EventType(io.zeebe.protocol.clientapi.EventType) Conditions(io.zeebe.test.util.Conditions) Optional(java.util.Optional) ExecuteCommandRequest(io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) TestUtil(io.zeebe.test.util.TestUtil) ControlMessageRequest(io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest) TopicSubscriberGroup(io.zeebe.client.event.impl.TopicSubscriberGroup) TopicSubscriptionBuilderImpl(io.zeebe.client.event.impl.TopicSubscriptionBuilderImpl) SubscriptionManager(io.zeebe.client.task.impl.subscription.SubscriptionManager) ZeebeClientImpl(io.zeebe.client.impl.ZeebeClientImpl) ResponseController(io.zeebe.test.broker.protocol.brokerapi.ResponseController) Test(org.junit.Test)

Aggregations

ZeebeClientImpl (io.zeebe.client.impl.ZeebeClientImpl)12 ZeebeClient (io.zeebe.client.ZeebeClient)7 Properties (java.util.Properties)7 ClientProperties (io.zeebe.client.ClientProperties)6 RemoteAddress (io.zeebe.transport.RemoteAddress)4 Duration (java.time.Duration)4 Test (org.junit.Test)4 ExecuteCommandRequest (io.zeebe.test.broker.protocol.brokerapi.ExecuteCommandRequest)3 Scanner (java.util.Scanner)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 TaskSubscription (io.zeebe.client.task.TaskSubscription)2 ClientRule (io.zeebe.client.util.ClientRule)2 ControlMessageType (io.zeebe.protocol.clientapi.ControlMessageType)2 ErrorCode (io.zeebe.protocol.clientapi.ErrorCode)2 EventType (io.zeebe.protocol.clientapi.EventType)2 ControlMessageRequest (io.zeebe.test.broker.protocol.brokerapi.ControlMessageRequest)2 ResponseController (io.zeebe.test.broker.protocol.brokerapi.ResponseController)2 StubBrokerRule (io.zeebe.test.broker.protocol.brokerapi.StubBrokerRule)2 TestUtil (io.zeebe.test.util.TestUtil)2 TestUtil.waitUntil (io.zeebe.test.util.TestUtil.waitUntil)2