Skip to content

CezaryTarnowski-TomTom/camunda-client-go

 
 

Repository files navigation

Camunda REST API client for golang

Go Report Card codecov Go Reference Release

Installation

go get github.com/citilinkru/camunda-client-go

Usage

Create client:

client := camunda_client_go.NewClient(camunda_client_go.ClientOptions{
	EndpointUrl: "http://localhost:8080/engine-rest",
    ApiUser: "demo",
    ApiPassword: "demo",
    Timeout: time.Second * 10,
})

Create deployment:

file, err := os.Open("demo.bpmn")
if err != nil {
    fmt.Printf("Error read file: %s\n", err)
    return
}
result, err := client.Deployment.Create(camunda_client_go.ReqDeploymentCreate{
    DeploymentName: "DemoProcess",
    Resources: map[string]interface{}{
        "demo.bpmn": file,
    },
})
if err != nil {
    fmt.Printf("Error deploy process: %s\n", err)
    return
}

fmt.Printf("Result: %#+v\n", result)

Start instance:

processKey := "demo-process"
result, err := client.ProcessDefinition.StartInstance(
	camunda_client_go.QueryProcessDefinitionBy{Key: &processKey},
	camunda_client_go.ReqStartInstance{},
)
if err != nil {
    fmt.Printf("Error start process: %s\n", err)
    return
}

fmt.Printf("Result: %#+v\n", result)

More examples

Examples documentation

Usage for External task

Create external task processor:

logger := func(err error) {
	fmt.Println(err.Error())
}
asyncResponseTimeout := 5000
proc := processor.NewProcessor(client, &processor.Options{
    WorkerId: "demo-worker",
    LockDuration: time.Second * 5,
    MaxTasks: 10,
    MaxParallelTaskPerHandler: 100,
    AsyncResponseTimeout: &asyncResponseTimeout,
}, logger)

Add and subscribe external task handler:

proc.AddHandler(
    []*camunda_client_go.QueryFetchAndLockTopic{
        {TopicName: "HelloWorldSetter"},
    },
    func(ctx *processor.Context) error {
        fmt.Printf("Running task %s. WorkerId: %s. TopicName: %s\n", ctx.Task.Id, ctx.Task.WorkerId, ctx.Task.TopicName)

        err := ctx.Complete(processor.QueryComplete{
            Variables: &map[string]camunda_client_go.Variable {
                "result": {Value: "Hello world!", Type: "string"},
            },
        })
        if err != nil {
            fmt.Printf("Error set complete task %s: %s\n", ctx.Task.Id, err)
            
            return ctx.HandleFailure(processor.QueryHandleFailure{
                ErrorMessage: &errTxt,
                Retries: &retries,
                RetryTimeout: &retryTimeout,
            })
        }
        
        fmt.Printf("Task %s completed\n", ctx.Task.Id)
        return nil
    },
)

Features

  • Support api version 7.11
  • Full support API External Task
  • Full support API Process Definition
  • Full support API Process Instance
  • Full support API Deployment
  • Partial support API History
  • Partial support API Tenant
  • Without external dependencies

Road map

  • Full coverage by tests
  • Full support references api

Testing

Unit-tests:

go test -v -race ./...

Run linter:

docker run --rm -v $(pwd):/app -w /app golangci/golangci-lint:v1.42.0 golangci-lint run -v

Integration tests:

docker run --rm --name camunda -p 8080:8080 camunda/camunda-bpm-platform
go test -tags=integration -failfast ./...

Examples:

Go to examples directory and follow the instructions to run the examples.

CONTRIBUTE

  • write code
  • run go fmt ./...
  • run all linters and tests (see above)
  • run all examples (see above)
  • create a PR describing the changes

LICENSE

MIT

AUTHOR

Konstantin Osipov k.osipov.msk@gmail.com

About

Camunda REST API client for golang

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 100.0%