forked from nitram509/lib-bpmn-engine
/
zeebe_exporter.go
39 lines (35 loc) · 1.27 KB
/
zeebe_exporter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package main
import (
"context"
"fmt"
"github.com/hazelcast/hazelcast-go-client"
"github.com/ipsitasbgit/lib-bpmn-engine/pkg/bpmn_engine"
"github.com/ipsitasbgit/lib-bpmn-engine/pkg/bpmn_engine/exporter/zeebe"
)
func main() {
// create a new named engine
bpmnEngine := bpmn_engine.New("a name")
// the exporter will require a running Hazelcast cluster at 127.0.0.1:5701
ctx := context.TODO()
config := hazelcast.Config{}
config.Cluster.Network.SetAddresses("localhost:5701")
client, err := hazelcast.StartNewClientWithConfig(ctx, config)
// create the client
exporter, _ := zeebe.NewExporterWithHazelcastClient(client)
// register the exporter
bpmnEngine.AddEventExporter(&exporter)
// basic example loading a BPMN from file,
process, err := bpmnEngine.LoadFromFile("simple_task.bpmn")
if err != nil {
panic("file \"simple_task.bpmn\" can't be read.")
}
// register a handler for a service task by defined task type
bpmnEngine.NewTaskHandler().Id("hello-world").Handler(printContextHandler)
// and execute the process
instance, _ := bpmnEngine.CreateAndRunInstance(process.ProcessKey, nil)
println(fmt.Sprintf("instanceKey=%d", instance.GetInstanceKey()))
}
func printContextHandler(job bpmn_engine.ActivatedJob) {
// trivial handler is requires
job.Complete()
}