Documentation
¶
Overview ¶
Package dtmx wraps DTM HTTP Saga orchestration for kernel services.
DTM itself remains an external coordinator. dtmx provides:
- kernel config / logx / errorx / metricsx integration
- saga GID generation
- HTTP /api/dtmsvr/submit client
- branch URL construction for application-local branch handlers
Services should expose idempotent action and compensate endpoints, and keep large payloads out of DTM's payload table. Store large data in object storage first, then pass only object keys and hashes in the saga payload.
Package dtmx provides a small kernel-native wrapper around DTM's HTTP Saga protocol. It deliberately avoids leaking dtm-labs SDK types into business code: services describe actions, compensations, and payloads; dtmx handles GID generation, request submission, logging, metrics, and errorx mapping.
Index ¶
Constants ¶
const ( DefaultServer = "http://127.0.0.1:36789/api/dtmsvr" DefaultBranchPrefix = "/internal/dtm" )
Variables ¶
var ( ErrInvalidConfig = errorx.BadRequest(errorx.Code("DTMX_INVALID_CONFIG"), "dtmx config is invalid") ErrSubmitFailed = errorx.Unavailable(errorx.Code("DTMX_SUBMIT_FAILED"), "failed to submit DTM transaction") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
NewGID(ctx context.Context) (string, error)
SubmitSaga(ctx context.Context, saga *Saga) error
BranchURL(path string) string
Config() Config
}
Client is the kernel DTM client abstraction.
type Config ¶
type Config struct {
// Enabled controls whether the caller should use DTM orchestration.
Enabled bool `json:"enabled" yaml:"enabled"`
// Server is the DTM HTTP API base URL, usually
// "http://127.0.0.1:36789/api/dtmsvr".
Server string `json:"server" yaml:"server"`
// ServiceBaseURL is the externally reachable base URL for branch action
// callbacks, for example "http://127.0.0.1:18001". It is kept in dtmx so
// business services do not hard-code their callback host.
ServiceBaseURL string `json:"service_base_url" yaml:"service_base_url"`
// BranchPrefix is prepended to branch paths when building callback URLs.
// Default: /internal/dtm.
BranchPrefix string `json:"branch_prefix" yaml:"branch_prefix"`
// Timeout bounds calls from the application to the DTM server.
Timeout time.Duration `json:"timeout_ns" yaml:"timeout_ns"`
// WaitResult asks DTM to wait for the saga result before returning from
// Submit. This is useful for request/response APIs such as skill upload.
WaitResult bool `json:"wait_result" yaml:"wait_result"`
// RequestTimeout / TimeoutToFail / RetryInterval are passed through to DTM
// in seconds when greater than zero.
RequestTimeout int64 `json:"request_timeout" yaml:"request_timeout"`
TimeoutToFail int64 `json:"timeout_to_fail" yaml:"timeout_to_fail"`
RetryInterval int64 `json:"retry_interval" yaml:"retry_interval"`
Logger logx.Logger `json:"-" yaml:"-"`
Metrics metricsx.Manager `json:"-" yaml:"-"`
MetricsEnabled bool `json:"metrics_enabled" yaml:"metrics_enabled"`
}
Config configures the DTM HTTP client.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
func New ¶
func New(cfg Config) (*HTTPClient, error)
func (*HTTPClient) BranchURL ¶
func (c *HTTPClient) BranchURL(path string) string
func (*HTTPClient) Config ¶
func (c *HTTPClient) Config() Config
func (*HTTPClient) NewGID ¶
func (c *HTTPClient) NewGID(ctx context.Context) (string, error)
NewGID returns a unique gid. DTM accepts caller-provided unique gid values; using UUID avoids adding a hard dependency on DTM's optional /newGid API.
func (*HTTPClient) SubmitSaga ¶
func (c *HTTPClient) SubmitSaga(ctx context.Context, saga *Saga) error
type Saga ¶
type Saga struct {
GID string `json:"gid"`
TransType string `json:"trans_type"`
Steps []map[string]string `json:"steps"`
Payloads []string `json:"payloads"`
WaitResult bool `json:"wait_result,omitempty"`
RequestTimeout int64 `json:"request_timeout,omitempty"`
TimeoutToFail int64 `json:"timeout_to_fail,omitempty"`
RetryInterval int64 `json:"retry_interval,omitempty"`
BranchHeaders map[string]string `json:"branch_headers,omitempty"`
}
Saga describes a DTM Saga transaction.