Documentation
¶
Index ¶
- Constants
- Variables
- func Bool(val bool) *bool
- func Encode(m *Message) []byte
- func Float64(val float64) *float64
- func Int64(val int64) *int64
- func Time(v time.Duration) *time.Duration
- type AllowOption
- type Message
- func (m *Message) Ack() error
- func (m *Message) AcknowledgementRequired() bool
- func (m *Message) Bytes() []byte
- func (m *Message) CorrelationMetadata() map[string]string
- func (m *Message) Nack() error
- func (m *Message) NackFailure(err error) error
- func (m *Message) Payload() []byte
- func (m *Message) SetAcknowledgement(ack func() error, nack func() error)
- func (m *Message) SetFailureAcknowledgement(ack func() error, nack func(error) error)
- func (m *Message) TraceContextMetadata() map[string]string
- func (m *Message) Validate() error
- type Metadata
- type Options
- type TaskFunc
Constants ¶
const ( // MaxMetadataValueBytes bounds every user-supplied metadata identity. MaxMetadataValueBytes = 256 // MaxMetadataTags bounds user-supplied metadata dimensions. MaxMetadataTags = 32 // MaxCorrelationFields bounds the transport-neutral correlation carrier. MaxCorrelationFields = 3 // MaxCorrelationFieldBytes matches correlation codec field-name bounds. MaxCorrelationFieldBytes = 64 // MaxCorrelationValueBytes matches the largest supported correlation ID. MaxCorrelationValueBytes = 1024 // MaxTraceContextFields bounds caller-owned telemetry propagation carriers. MaxTraceContextFields = 16 // MaxTraceContextFieldBytes bounds telemetry propagation field names. MaxTraceContextFieldBytes = 64 // MaxTraceContextValueBytes bounds one telemetry propagation field value. MaxTraceContextValueBytes = 8192 // MaxTraceContextBytes bounds the complete telemetry propagation carrier. MaxTraceContextBytes = 8192 )
const DefaultMaxMessageBytes = 1024 * 1024
DefaultMaxMessageBytes bounds encoded messages to one mebibyte.
const MaxRetryCount int64 = 100
MaxRetryCount bounds attempts scheduled from one delivered message.
Variables ¶
var ( // ErrInvalidMessageLimit reports a non-positive decode limit. ErrInvalidMessageLimit = errors.New("message byte limit must be positive") // ErrMessageTooLarge reports an encoded message above its decode limit. ErrMessageTooLarge = errors.New("message exceeds byte limit") // ErrInvalidMessage reports unsafe or inconsistent execution metadata. ErrInvalidMessage = errors.New("invalid message execution metadata") )
Functions ¶
func Bool ¶
Bool is a helper function that creates a pointer to a bool value. Useful for setting AllowOption fields that require *bool.
Example:
opts := AllowOption{Jitter: job.Bool(true)}
func Encode ¶
Encode takes a Message struct and marshals it into a byte slice using msgpack. If the marshalling process encounters an error, the function will panic. It returns the marshalled byte slice.
Parameters:
- m: A pointer to the Message struct to be encoded.
Returns:
- A byte slice containing the msgpack-encoded data.
func Float64 ¶
Float64 is a helper function that creates a pointer to a float64 value. Useful for setting AllowOption fields that require *float64.
Example:
opts := AllowOption{RetryFactor: job.Float64(1.5)}
func Int64 ¶
Int64 is a helper function that creates a pointer to an int64 value. Useful for setting AllowOption fields that require *int64.
Example:
opts := AllowOption{RetryCount: job.Int64(3)}
Types ¶
type AllowOption ¶
type AllowOption struct {
RetryCount *int64 // Maximum retry attempts (nil uses default: 0)
RetryDelay *time.Duration // Fixed delay between retries (nil uses exponential backoff)
RetryFactor *float64 // Backoff multiplier (nil uses default: 2)
RetryMin *time.Duration // Minimum backoff delay (nil uses default: 100ms)
RetryMax *time.Duration // Maximum backoff delay (nil uses default: 10s)
Jitter *bool // Enable backoff jitter (nil uses default: false)
Timeout *time.Duration // Job execution timeout (nil uses default: 60 minutes)
Metadata *Metadata // Optional bounded identity propagated to operational records
}
AllowOption provides optional configuration for individual job execution. All fields are pointers to distinguish between "not set" and "set to zero value". This allows partial configuration while keeping unspecified fields at their defaults.
Example usage:
opts := AllowOption{
RetryCount: job.Int64(3), // Retry failed jobs up to 3 times
Timeout: job.Time(5 * time.Minute), // 5 minute timeout
}
q.QueueTask(myTask, opts)
type Message ¶
type Message struct {
Task TaskFunc `json:"-" msgpack:"-"`
// Timeout is the duration the task can be processed by Handler.
// zero if not specified
// default is 60 time.Minute
Timeout time.Duration `json:"timeout" msgpack:"timeout"`
// Payload is the payload data of the task.
Body []byte `json:"body" msgpack:"body"`
// RetryCount set count of retry
// default is 0, no retry.
RetryCount int64 `json:"retry_count" msgpack:"retry_count"`
// RetryDelay set delay between retry
// default is 100ms
RetryDelay time.Duration `json:"retry_delay" msgpack:"retry_delay"`
// RetryFactor is the multiplying factor for each increment step.
//
// Defaults to 2.
RetryFactor float64 `json:"retry_factor" msgpack:"retry_factor"`
// Minimum value of the counter.
//
// Defaults to 100 milliseconds.
RetryMin time.Duration `json:"retry_min" msgpack:"retry_min"`
// Maximum value of the counter.
//
// Defaults to 10 seconds.
RetryMax time.Duration `json:"retry_max" msgpack:"retry_max"`
// Jitter eases contention by randomizing backoff steps
Jitter bool `json:"jitter" msgpack:"jitter"`
// Metadata is optional bounded identity retained for operational records.
Metadata *Metadata `json:"metadata,omitempty" msgpack:"metadata,omitempty"`
// contains filtered or unexported fields
}
Message describes a task and its metadata.
func Decode ¶
Decode takes a byte slice and unmarshals it into a Message struct using msgpack. If the unmarshalling process encounters an error, the function will panic. It returns a pointer to the unmarshalled Message.
Parameters:
- b: A byte slice containing the msgpack-encoded data.
Returns:
- A pointer to the decoded Message struct.
func NewMessage ¶
func NewMessage(m core.QueuedMessage, opts ...AllowOption) Message
NewMessage create new message
func NewTask ¶
func NewTask(task TaskFunc, opts ...AllowOption) Message
func (*Message) AcknowledgementRequired ¶
AcknowledgementRequired reports whether backend settlement is attached.
func (*Message) Bytes ¶
Bytes returns the byte slice of the Message struct. If the marshalling process encounters an error, the function will panic. It returns the marshalled byte slice.
Returns:
- A byte slice containing the msgpack-encoded data.
func (*Message) CorrelationMetadata ¶
CorrelationMetadata returns a copy of the transport-neutral carrier attached by a correlation-aware producer.
func (*Message) NackFailure ¶
NackFailure rejects unsuccessful processing with its classified cause.
func (*Message) Payload ¶
Payload returns the payload data of the Message. It returns the byte slice of the payload.
Returns:
- A byte slice containing the payload data.
func (*Message) SetAcknowledgement ¶
SetAcknowledgement attaches backend delivery settlement callbacks.
func (*Message) SetFailureAcknowledgement ¶
SetFailureAcknowledgement attaches settlement callbacks to a delivery whose backend needs the handler failure to choose retry or terminal behavior.
func (*Message) TraceContextMetadata ¶
TraceContextMetadata returns a copy of the transport-neutral telemetry carrier attached by a trace-aware producer.
type Metadata ¶
type Metadata struct {
OriginalID string `json:"original_id,omitempty" msgpack:"original_id,omitempty"`
PayloadSchemaVersion string `json:"payload_schema_version,omitempty" msgpack:"payload_schema_version,omitempty"`
ContentType string `json:"content_type,omitempty" msgpack:"content_type,omitempty"`
EnqueuedAt *time.Time `json:"enqueued_at,omitempty" msgpack:"enqueued_at,omitempty"`
RetryPolicy string `json:"retry_policy,omitempty" msgpack:"retry_policy,omitempty"`
HandlerType string `json:"handler_type,omitempty" msgpack:"handler_type,omitempty"`
JobType string `json:"job_type,omitempty" msgpack:"job_type,omitempty"`
Tags map[string]string `json:"tags,omitempty" msgpack:"tags,omitempty"`
TraceID string `json:"trace_id,omitempty" msgpack:"trace_id,omitempty"`
TenantID string `json:"tenant_id,omitempty" msgpack:"tenant_id,omitempty"`
ProducerVersion string `json:"producer_version,omitempty" msgpack:"producer_version,omitempty"`
Correlation map[string]string `json:"correlation,omitempty" msgpack:"correlation,omitempty"`
TraceContext map[string]string `json:"trace_context,omitempty" msgpack:"trace_context,omitempty"`
}
Metadata carries optional, backend-neutral job identity into failure and dead-letter records. Empty fields remain unknown and must not be fabricated.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options configures retry behavior and timeouts for individual jobs. These settings control how failed tasks are retried and when they time out.
func NewOptions ¶
func NewOptions(opts ...AllowOption) Options
NewOptions creates a job Options struct by merging defaults with provided AllowOption values. Only non-nil fields in AllowOption will override the defaults. This allows partial configuration where unspecified options retain their default values.
Example:
// Only override retry count and timeout, keep other defaults
opts := job.NewOptions(job.AllowOption{
RetryCount: job.Int64(5),
Timeout: job.Time(10 * time.Minute),
})