Skip to content

Instantly share code, notes, and snippets.

@meyerdan
Last active April 5, 2018 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meyerdan/6f9dd94192652977870346d09d310b20 to your computer and use it in GitHub Desktop.
Save meyerdan/6f9dd94192652977870346d09d310b20 to your computer and use it in GitHub Desktop.
Zeebe Client Api ideas
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);
...
}
ZeebeClient client = ...;
ZeebeTopicClient orderTopic = client.topic("order-processing");
try
{
Future<WorkflowInstanceEvent> evt = orderTopic.deployWorkflow(new DeployWorkflowCommand("foo.bpmn").replaceOldVersions());
}
catch (CommandFailedException e)
{
// handle error
}
ZeebeClient client = null;
Map<String, PartitionInfo> partitions = client.listTopics();
PartitionInfo partitionInfo = partitions.get("order-processing");
Node leader = partitionInfo.getLeader();
List<Node> leader = partitionInfo.getFollowers();
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
}
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
}
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