Last active
April 5, 2018 06:36
-
-
Save meyerdan/6f9dd94192652977870346d09d310b20 to your computer and use it in GitHub Desktop.
Zeebe Client Api ideas
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ZeebeClient | |
{ | |
ZeebeTopicClient topic(String topicName); | |
Map<String, PartitionInfo> listTopics(); | |
} | |
public interface ZeebeTopicClient | |
{ | |
Future<TaskEvent> createTask(CreateTaskCommand cmd); | |
Future<TaskEvent> completeTask(CompleteTaskCommand cmd); | |
Future<WorkflowInstanceEnvent> createWorkflowInstance(CompleteTaskCommand cmd); | |
TopicSubscriptionBuilder<Event> newEventSubscription(); | |
// | |
PollableTaskSubscriptionBuilder newPollableTaskSubscription(); | |
PollableEventSubscriptionBuilder newPollableEventSubscription(); | |
<T extends Event> newEventSubscription(Class<T> type); | |
... | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZeebeClient client = ...; | |
ZeebeTopicClient orderTopic = client.topic("order-processing"); | |
try | |
{ | |
Future<WorkflowInstanceEvent> evt = orderTopic.deployWorkflow(new DeployWorkflowCommand("foo.bpmn").replaceOldVersions()); | |
} | |
catch (CommandFailedException e) | |
{ | |
// handle error | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZeebeClient client = null; | |
Map<String, PartitionInfo> partitions = client.listTopics(); | |
PartitionInfo partitionInfo = partitions.get("order-processing"); | |
Node leader = partitionInfo.getLeader(); | |
List<Node> leader = partitionInfo.getFollowers(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZeebeClient client = ...; | |
ZeebeTopicClient orderTopic = client.topic("order-processing"); | |
// start wf instance sync | |
try | |
{ | |
Future<WorkflowInstanceEvent> evt = orderTopic.createWorkflowInstance(new StartWorkflowInstanceCommand("orderProcess") | |
.payload(...)); | |
} | |
catch (CommandFailedException e) | |
{ | |
// handle error | |
} | |
// ----------------------------------------------------------------------- | |
// start wf instance async | |
final Future<WorkflowInstanceEvent> evt = orderTopic.sendAsync(new StartWorkflowInstanceCommand("orderProcess") | |
.payload(...)); | |
try | |
{ | |
evt.join(); | |
} | |
catch (CommandFailedException e) | |
{ | |
// handle error | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZeebeClient client = ...; | |
ZeebeTopicClient orderTopic = client.topic("order-processing"); | |
// async task handler | |
orderTopic.newTaskSubscription("fraudCheck") | |
// ... | |
.handler(new TaskHandler() | |
{ | |
@Override | |
public void handle(TaskEvent taskEvent) | |
{ | |
// store in database | |
database.store(taskEvent.getKey(), taskEvent.toJson()); | |
} | |
}) | |
.open(); | |
// later | |
String taskEventJson = database.load(taskKey); | |
TaskEvent taskEvent = TaskEvent.fromJson(taskEvent); | |
try { | |
topicClient.completeTask(new CompleteTaskCommand(taskEvent).payload(...)); | |
} | |
catch (CommandFailedException e) | |
{ | |
// handle error | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ZeebeClient client = ...; | |
ZeebeTopicClient orderTopic = client.topic("order-processing"); | |
orderTopic.newTaskSubscription("fraudCheck") | |
// ... | |
.handler(new TaskHandler() | |
{ | |
@Override | |
public void handle(TaskEvent taskEvent) | |
{ | |
// do work ... | |
try | |
{ | |
topicClient.completeTask(new CompleteTaskCommand(taskEvent).payload(...)); | |
} | |
catch (CommandFailedException e) | |
{ | |
// handle error | |
} | |
} | |
}) | |
.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment