Create a gist now

Instantly share code, notes, and snippets.

@meyerdan /Api.java
Last active Apr 5, 2018

Embed
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