Go
github.com/QuantumBPM/quantum-go-sdk/v2 - the reference implementation. Requires Go 1.25+.
Installation
go get github.com/QuantumBPM/quantum-go-sdk/v2
Quick start
package main
import (
"context"
"log"
"os"
"github.com/google/uuid"
quantumbpm "github.com/QuantumBPM/quantum-go-sdk/v2"
"github.com/QuantumBPM/quantum-go-sdk/v2/auth"
"github.com/QuantumBPM/quantum-go-sdk/v2/variables"
)
func main() {
provider := auth.NewClientCredentialsTokenProvider(auth.ClientCredentials{
TokenURL: "https://idp.example.com/realms/acme/protocol/openid-connect/token",
ClientID: "billing-svc",
ClientSecret: os.Getenv("QUANTUMBPM_CLIENT_SECRET"),
})
client, err := quantumbpm.New(quantumbpm.Config{
BaseURL: "https://quantumbpm.example.com",
ProjectID: uuid.MustParse("YOUR_PROJECT_ID"),
TokenProvider: provider,
})
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
result, err := client.DMN.Evaluate(ctx, "loan-eligibility", variables.New().
Set("requestedAmt", 1000).
Set("creditScore", 720))
if err != nil {
log.Fatal(err)
}
log.Printf("decisions: %+v", result)
}
Authentication
auth.NewClientCredentialsTokenProvider fetches tokens from your OIDC identity provider with the client credentials grant. TokenURL, ClientID and ClientSecret are required. Scopes, Audience and HTTPClient (default http.DefaultClient) are optional:
provider := auth.NewClientCredentialsTokenProvider(auth.ClientCredentials{
TokenURL: "https://idp.example.com/realms/acme/protocol/openid-connect/token",
ClientID: "billing-svc",
ClientSecret: os.Getenv("QUANTUMBPM_CLIENT_SECRET"),
Scopes: []string{"openid"},
Audience: "quantumbpm",
})
The exact token endpoint depends on the identity provider, see Authentication. A failed token request makes Token return an error with the HTTP status and response body. For a token you already hold, use auth.NewStaticTokenProvider(token).
DMN
draft, _ := client.DMN.CreateDefinition(ctx, "loan-eligibility", dmnXML)
deployed, _ := client.DMN.DeployDefinition(ctx, draft.Id)
result, _ := client.DMN.Evaluate(ctx, deployed.DefinitionsID, variables.New().
Set("requestedAmt", 5000))
A draft is not evaluable until it is deployed, and the deploy gives it the next version of its <definitions id>. Saving XML identical to the latest deployed version returns a conflict error, and nothing is saved.
BPMN
draft, _ := client.BPMN.CreateResource(ctx, "loan-process", bpmnXML)
client.BPMN.DeployResource(ctx, draft.Id)
deployed, _ := client.BPMN.GetResource(ctx, draft.Id)
processDef := (*deployed.Processes)[0]
// The latest deployed version, or bpmn.WithStartVersion(n) for one version.
instanceID, _ := client.BPMN.StartInstance(ctx, processDef.ProcessID, variables.New().
Set("applicantID", "u-123"))
Correlation keys (businessId)
Stamp a caller-supplied correlation key (order number, ticket ID, etc.) on a new instance with bpmn.WithStartBusinessID. The key is inherited by every child instance, external job, user task, and DMN execution emitted by the process - workers receive it as job.BusinessId (a *string).
instanceID, _ := client.BPMN.StartInstance(ctx, processDef.ProcessID, vars,
bpmn.WithStartBusinessID("ORDER-42"))
// Filter listings by the same key.
page, _ := client.BPMN.ListInstances(ctx, bpmn.WithInstanceBusinessID("ORDER-42"))
tasks, _ := client.BPMN.ListUserTasks(ctx, bpmn.WithUserTaskBusinessID("ORDER-42"))
// DMN evaluations stamp it on the resulting execution row.
result, _ := client.DMN.Evaluate(ctx, "loan-eligibility", vars,
dmn.WithBusinessID("ORDER-42"))
External job workers
The runtime owns long-polling, lock heartbeats, dispatch, and outcome mapping. Handlers run on a goroutine pool sized per task type.
import "github.com/QuantumBPM/quantum-go-sdk/v2/workers"
worker := client.NewWorker(workers.Config{ClientID: "billing-svc"})
worker.Handle("send-email", func(ctx context.Context, j *workers.Job) (variables.Vars, error) {
to, _ := variables.Get[string](j.Vars, "recipient")
if err := emailer.Send(to); err != nil {
return nil, err // → ThrowError("WORKER_ERROR")
}
return variables.New().Set("messageID", "msg-123"), nil // → Complete
}, workers.WithMaxJobs(10), workers.WithLockDuration(time.Minute))
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
worker.Run(ctx) // blocks until SIGTERM, then shuts down cleanly
Heartbeats keep each job locked to the worker while its handler runs. The server clamps lockDuration to 10s..5m by default, and the worker heartbeats at half of the lock it was granted. When a heartbeat finds the lock gone, the handler's ctx is cancelled and nothing is reported for that job. When Run's ctx is cancelled, the worker stops polling, and running handlers keep heartbeating and report their results for up to workers.Config.ShutdownTimeout (20s by default). Handlers still running then have their ctx cancelled and are not reported. A job abandoned that way costs a retry, see When a lock runs out. On Kubernetes, keep terminationGracePeriodSeconds above the shutdown timeout.
Throw a *workers.BpmnError to fail the job with a code that boundary error events on the originating service task can catch:
return nil, workers.NewBpmnError("INSUFFICIENT_FUNDS", variables.New().Set("balance", 12.0))
Any other returned error (or panic) is reported with the code WORKER_ERROR and the message attached as the error variable (truncated to 2048 bytes by default, raise via the MaxErrorMessageBytes field on workers.Config). A boundary error event whose error definition has errorCode="WORKER_ERROR" catches it once the retry budget is exhausted - see Failure handling.
Use workers.HandleTyped[T] for opt-in typed dispatch - the SDK decodes job variables into T before invoking the handler.
Full reference
See the SDK README for the complete API surface, including resource/instance management, messaging and signals, user tasks, and the Vars typed-access helpers.