Categorygithub.com/agilize/camunda-client-go
modulepackage
0.1.1
Repository: https://github.com/agilize/camunda-client-go.git
Documentation: pkg.go.dev

# README

Camunda REST API client for golang

Build Status GoDoc

Installation

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

Usage

Create client:

timeout := time.Second * 10
client := camunda_client_go.NewClient(camunda_client_go.ClientOptions{
    ApiUser: "demo",
    ApiPassword: "demo",
    Timeout: &timeout,
})

Create deployment:

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

logger.infof("Result: %#+v", result)

Start instance:

processKey := "DemoProcess"
result, err = client.ProcessDefinition.StartInstance(
	camunda_client_go.QueryProcessDefinitionBy{Key: &processKey},
	camunda_client_go.ReqStartInstance{},
)
if err != nil {
    logger.Errorf("Error start process: %s", err)
    return
}

logger.infof("Result: %#+v", result)

Usage for External task

Create external task processor:

logger := logrus.New()
asyncResponseTimeout := 5000
proc := processor.NewProcessor(client, &processor.ProcessorOptions{
    WorkerId: "demo-worker",
    LockDuration: time.Second * 5,
    MaxTasks: 1,
    AsyncResponseTimeout: &asyncResponseTimeout,
}, logger)

Add and subscribe external task handler:

proc.AddHandler(
    &[]camunda_client_go.QueryFetchAndLockTopic{
        {TopicName: "HelloWorldSetter"},
    },
    func(ctx *processor.Context) error {
        logger.Infof("Running task %s. WorkerId: %s. TopicName: %s", 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 {
            logger.Errorf("Error set complete task %s: %s", ctx.Task.Id, err)
            
            return ctx.HandleFailure(processor.QueryHandleFailure{
                ErrorMessage: &errTxt,
                Retries: &retries,
                RetryTimeout: &retryTimeout,
            })
        }
        
        logger.Infof("Task %s completed", ctx.Task.Id)
        return nil
    },
)

WARNING

This project is still under development. Use code with caution!

Features

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

Road map

  • Full coverage by tests
  • Full support references api

Testing

Unit-tests:

go test -v -race ./...

Run linter:

golangci-lint run

LICENSE

MIT

AUTHOR

Konstantin Osipov [email protected]

# Packages

No description provided by the author

# Functions

NewClient a create new instance Client.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Structs

Client a client for Camunda API.
ClientOptions a client options.
Deployment a client for Deployment API.
Error a custom error type.
ExternalTask a client for ExternalTask API.
ProcessDefinition a client for ProcessDefinition.
QueryComplete a query for Complete request.
QueryExtendLock a query for ExtendLock request.
QueryFetchAndLock query for FetchAndLock request.
QueryFetchAndLockTopic a JSON array of topic objects for which external tasks should be fetched.
QueryGetListPost a query for ListPost request.
QueryHandleBPMNError a query for HandleBPMNError request.
QueryHandleFailure a query for HandleFailure request.
QueryListPostSorting a JSON array of criteria to sort the result by.
QueryProcessDefinitionBy path builder.
QuerySetRetriesAsync a query for SetRetriesAsync request.
QuerySetRetriesSync a query for SetRetriesSync request.
ReqActivateOrSuspendById response ActivateOrSuspendById.
ReqActivateOrSuspendByKey response ActivateOrSuspendByKey.
ReqDeploymentCreate a request to deployment create.
ReqRedeploy a request to redeploy.
ReqRestartInstance a request to restart instance.
ReqStartInstance a JSON object with the following properties: (at least an empty JSON object {} or an empty request body).
ReqStartInstructions a JSON array of instructions that specify which activities to start the process instance at.
ReqSubmitStartForm request a SubmitStartForm.
ResActivityInstanceStatistics a JSON array containing statistics results per activity.
ResActivityInstanceStatisticsIncident a statistics incident.
ResBatch a JSON object corresponding to the Batch interface in the engine.
ResBPMNProcessDefinition a JSON object containing the id of the definition and the BPMN 2.0 XML.
ResCaseDefinition a JSON object corresponding to the CaseDefinition interface in the engine.
ResCount a count response.
ResDecisionDefinition a JSON object corresponding to the DecisionDefinition interface in the engine.
ResDecisionRequirementsDefinition a JSON object corresponding to the DecisionRequirementsDefinition interface in the engine.
ResDeployment a JSON array of deployment objects.
ResDeploymentCreate a JSON object corresponding to the DeploymentWithDefinitions interface in the engine.
ResDeploymentResource a JSON array containing all deployment resources of the given deployment.
ResExternalTask a ExternalTask response.
ResGetStartFormKey a response from GetStartFormKey method.
ResInstanceStatistics a JSON array containing statistics results per process definition.
ResLink a link struct.
ResLockedExternalTask a response FetchAndLock method.
ResProcessDefinition a JSON object corresponding to the ProcessDefinition interface in the engine.
ResStartedProcessDefinition ProcessDefinition for started.
ReqSubmitStartForm response rrom SubmitStartForm method.
Time a custom time format.
ValueInfo a value info in variable.
Variable a variable.
VariableSet a variable for set.