Skip to content
Get started
Get started
Go SDK (github.com/egeominotti/bunqueue/sdk/go)
View Markdown
sdks · go

Go SDK with goroutine workers.

Official Go client speaking bunqueue TCP protocol v3 with concurrent workers, automatic panic recovery, verified TLS, and atomic flows.

Go SDK (Protocol v3)

Dispatch goroutine workers with panic recovery, atomic flows, and verified TLS

enqueue GO Go Service NewQueue / Add store TCP MsgPack v3 4-byte len + TLS claim + ack SRV bunqueue SQLite or PG 17-19 RUN Goroutines panic-safe pool go get github.com/egeominotti/bunqueue/sdk/go · zero CGO dependencies
Idiomatic Go 1.26.5+: bounded goroutine pools, full panic recovery, typed errors.As handling, and optional HeartbeatIntervalS lock renewal.

Add the Go module (Go 1.26.5+, v0.2.0+ for protocol v3) and configure TCP/TLS options:

go get github.com/egeominotti/bunqueue/sdk/go
import (
"os"
"time"
bunqueue "github.com/egeominotti/bunqueue/sdk/go"
)
queue := bunqueue.NewQueue("emails", bunqueue.Options{
Host: "queue.example.com", Port: 6789, Token: os.Getenv("BUNQUEUE_TOKEN"),
TLS: &bunqueue.TLSOptions{CAFile: "./ca.pem"}, // or &bunqueue.TLSOptions{} for system CAs
ConnectTimeout: 10 * time.Second, CommandTimeout: 30 * time.Second,
})
defer queue.Close()

Enqueue single jobs with JobOptions or send a batch in one TCP round-trip with AddBulk:

_, err := queue.Add("charge", map[string]any{"orderId": "ord_42"}, bunqueue.JobOptions{
"jobId": "order-ord_42", "priority": 10, "delay": 5000, "attempts": 5, "durable": true,
})
entries := make([]bunqueue.BulkEntry, 0, len(orders))
for _, o := range orders {
entries = append(entries, bunqueue.BulkEntry{
Name: "ingest", Data: o, Opts: bunqueue.JobOptions{"jobId": "order-" + o.ID},
})
}
ids, err := queue.AddBulk(entries)

Worker runs a bounded goroutine pool with automatic panic recovery (converted to job failures with stack traces); set HeartbeatIntervalS (disabled by default) to renew leases on long jobs:

worker := bunqueue.NewWorker("emails", func(job *bunqueue.Job) (any, error) {
payload, ok := job.Data().(map[string]any)
if !ok || payload["to"] == "" {
return nil, bunqueue.NewUnrecoverableError("missing recipient") // skip retries -> DLQ
}
return sendEmail(payload["to"].(string))
}, bunqueue.WorkerOptions{
Host: "localhost",
Port: 6789,
Concurrency: 8,
BatchSize: 10,
PollTimeoutMs: 5000,
LockTtlMs: 30000,
HeartbeatIntervalS: 10, // enable lock & worker heartbeats for long jobs
})
worker.On("completed", func(args ...any) { log.Printf("done %s", args[0].(*bunqueue.Job).ID()) })
worker.On("error", func(args ...any) { log.Println("worker error:", args[0]) })
// Graceful shutdown: worker.Stop() (drain in-flight), then worker.Close() (unregister & disconnect)
worker.Run()

Query jobs, control queues/DLQ, and submit atomic PUSHF chains or parent/child trees with FlowProducer:

job, _ := queue.GetJob(id) // nil when missing
state, _ := queue.GetState(id) // "waiting" | "active" | ...
result, _ := queue.WaitForJob(id, 30000)
counts, _ := queue.GetJobCounts()
_ = queue.Pause()
dropped, _ := queue.Drain()
_, _ = queue.RetryDlq("", 0)

Atomic parent/child trees and sequential pipelines with FlowProducer:

flow := bunqueue.NewFlowProducer(bunqueue.Options{})
defer flow.Close()
ids, err := flow.AddChain([]bunqueue.ChainStep{
{Name: "extract", QueueName: "etl"},
{Name: "transform", QueueName: "etl"},
{Name: "load", QueueName: "etl"},
})
node, err := flow.Add(bunqueue.FlowJob{
Name: "assemble",
QueueName: "orders",
Children: []bunqueue.FlowJob{
{Name: "reserve-stock", QueueName: "orders"},
{Name: "charge-card", QueueName: "orders"},
},
})

Observe connection, auth, command latency, and retry events via OnEvent (tokens and job payloads are never emitted):

queue := bunqueue.NewQueue("emails", bunqueue.Options{
OnEvent: func(event bunqueue.TelemetryEvent) {
metrics.Observe(event)
},
})

Use errors.As to branch on typed connection, timeout, auth, command, or serialization errors. Pass 64-bit snowflake IDs as strings to stay within IEEE 754 2^53 integer precision.