class SqsQueue extends Queue implements Queue, ClearableQueue

Traits

Constants

MAX_SQS_PAYLOAD_SIZE

The maximum SQS payload size in bytes (1 MB).

MAX_MESSAGES_PER_BATCH

The maximum number of messages allowed per SendMessageBatch request.

EXTENDED_PAYLOAD_CACHE_PREFIX

The cache key prefix for extended SQS payloads.

IMPORTANT: Uses Laravel's prefix for cross-framework queue interoperability.

Properties

protected Container $container

The IoC container instance.

from  Queue
protected string $connectionName

The connection name for the queue.

from  Queue
protected array $config

The original configuration for the queue.

from  Queue
protected bool $dispatchAfterCommit

Indicates that jobs should be dispatched after all database transactions have committed.

from  Queue
protected null|Queue): mixed): mixed $afterCommitDispatcher

Dispatch an after-commit operation through its live queue owner.

from  Queue
static protected callable[] $createPayloadCallbacks

The create payload callbacks.

from  Queue
protected array $overflowStorage

The overflow storage options for large payload offloading.

Methods

int
secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

int
availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

int
currentTime()

Get the current system time as a UNIX timestamp.

string
runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

mixed
getAttributeValue(object $target, string $attributeClass, string|null $property = null, mixed $default = null)

Get a configuration value from an attribute, falling back to a property.

mixed
extractAttributeValue(object $instance)

Extract the value from an attribute instance.

object|null
getAttributeInstance(object $target, string $attributeClass, ReflectionClass|null $declaringClass = null)

Get an instance of the given attribute class from the target class or its parents.

bool
propertyOverridesAttribute(object $target, ReflectionClass $reflection, string|null $property, ReflectionClass $attributeDeclaringClass)

Determine if a property declared on a child class overrides an inherited attribute.

mixed
pushOn(string|null $queue, object|string $job, mixed $data = '')

Push a new job onto the queue.

from  Queue
mixed
laterOn(string|null $queue, DateInterval|DateTimeInterface|int $delay, object|string $job, mixed $data = '')

Push a new job onto a specific queue after (n) seconds.

from  Queue
mixed
bulk(array $jobs, mixed $data = '', string|null $queue = null)

Push an array of jobs onto the queue.

string
createPayload(array|object|string $job, string|null $queue, mixed $data = '', DateInterval|DateTimeInterface|int|null $delay = null)

Create a payload string from the given job and data.

from  Queue
array
createPayloadArray(array|object|string $job, string|null $queue, mixed $data = '')

Create a payload array from the given job and data.

from  Queue
array
createObjectPayload(object $job, string|null $queue)

Create a payload for an object-based queue handler.

from  Queue
string
getDisplayName(object $job)

Get the display name for the given job.

from  Queue
mixed
getJobTries(mixed $job)

Get the maximum number of attempts for an object-based queue handler.

from  Queue
mixed
getJobBackoff(mixed $job)

Get the backoff for an object-based queue handler.

from  Queue
mixed
getJobExpiration(mixed $job)

Get the expiration timestamp for an object-based queue handler.

from  Queue
bool
jobShouldBeEncrypted(object $job)

Determine if the job should be encrypted.

from  Queue
array
createStringPayload(array|string $job, string|null $queue, mixed $data)

Create a typical, string based queue payload array.

from  Queue
static void
createPayloadUsing(callable|null $callback)

Register a callback to be executed when creating job payloads.

from  Queue
array
withCreatePayloadHooks(string|null $queue, array $payload)

Create the given payload using any registered payload hooks.

from  Queue
setAfterCommitDispatcher(Closure|null $dispatcher)

Set the dispatcher for after-commit queue operations.

from  Queue
mixed
enqueueUsing(object|string $job, string $payload, string|null $queue, DateInterval|DateTimeInterface|int|null $delay, callable $callback)

Enqueue a job using the given callback.

from  Queue
mixed
enqueueNow(object|string $job, string $payload, string|null $queue, DateInterval|DateTimeInterface|int|null $delay, callable $callback)

Enqueue a job immediately using the given callback.

from  Queue
bool
shouldDispatchAfterCommit(object|string $job)

Determine if the job should be dispatched after all database transactions have committed.

from  Queue
void
addUniqueJobRollbackCallback(DatabaseTransactionsManager $transactions, object|string $job)

Register a transaction rollback callback that releases the unique lock for the given job.

from  Queue
void
addDebouncedJobRollbackCallback(DatabaseTransactionsManager $transactions, object|string $job)

Register a transaction rollback callback that releases the debounce token for the given job.

from  Queue
void
raiseJobQueueingEvent(string|null $queue, object|string $job, string $payload, DateInterval|DateTimeInterface|int|null $delay)

Raise the job queueing event.

from  Queue
void
raiseJobQueuedEvent(string|null $queue, mixed $jobId, object|string $job, string $payload, DateInterval|DateTimeInterface|int|null $delay)

Raise the job queued event.

from  Queue
string
getConnectionName()

Get the connection name for the queue.

from  Queue
setConnectionName(string $name)

Set the connection name for the queue.

from  Queue
array
getConfig()

Get the queue configuration array.

from  Queue
setConfig(array $config)

Set the queue configuration array.

from  Queue
getContainer()

Get the container instance being used by the connection.

from  Queue
setContainer(Container $container)

Set the IoC container instance.

from  Queue
static void
flushState()

Flush all static state.

from  Queue
__construct(SqsClient $sqs, string $default, string $prefix = '', string $suffix = '', bool $dispatchAfterCommit = false, array $overflowStorage = [])

Create a new Amazon SQS queue instance.

int
size(string|null $queue = null)

Get the size of the queue.

int
pendingSize(string|null $queue = null)

Get the number of pending jobs.

int
delayedSize(string|null $queue = null)

Get the number of delayed jobs.

int
reservedSize(string|null $queue = null)

Get the number of reserved jobs.

pendingJobs(string|null $queue = null)

Get the pending jobs for the given queue.

delayedJobs(string|null $queue = null)

Get the delayed jobs for the given queue.

reservedJobs(string|null $queue = null)

Get the reserved jobs for the given queue.

allPendingJobs()

Get all pending jobs across every queue.

allDelayedJobs()

Get all delayed jobs across every queue.

allReservedJobs()

Get all reserved jobs across every queue.

int|null
creationTimeOfOldestPendingJob(string|null $queue = null)

Get the creation timestamp of the oldest pending job, excluding delayed jobs.

mixed
push(object|string $job, mixed $data = '', string|null $queue = null)

Push a new job onto the queue.

mixed
pushRaw(string $payload, string|null $queue = null, array $options = [])

Push a raw payload onto the queue.

mixed
later(DateInterval|DateTimeInterface|int $delay, object|string $job, mixed $data = '', string|null $queue = null)

Push a new job onto the queue after (n) seconds.

array
partitionJobsByAfterCommit(array $jobs, DatabaseTransactionsManager|null $transactions)

Partition jobs by whether they should be deferred until the active transaction commits.

array
prepareBatchMessages(array $jobs, mixed $data, string|null $queue)

Create the payload for each of the given jobs.

void
sendBatchedMessages(array $messages, string|null $queue)

Build entries, dispatch chunks, and raise queued events with SQS message IDs.

array
prepareSendMessageBatchEntry(int $id, array $message, string|null $queue)

Build the SendMessageBatch entry for a prepared message.

array
chunkBatchEntries(array $entries)

Chunk batch entries by SQS count and payload-size limits.

bool
willOverflow(string $payload)

Determine if the payload should be stored in cache.

array
prepareOverflowPayload(string $payload)

Build the cache path and pointer for an overflow payload.

void
storeOverflowPayload(Repository $store, string $path, string $payload)

Store an overflow payload.

void
cleanupOverflowPayloads(Repository $store, array $paths)

Remove unpublished overflow payloads without hiding the primary failure.

overflowStore()

Get the cache store for overflow payloads.

Job|null
pop(string|null $queue = null)

Pop the next job off of the queue.

int
clear(string|null $queue)

Delete all of the jobs from the queue.

array
getQueueableOptions(object|string $job, string|null $queue, string $payload, DateInterval|DateTimeInterface|int|null $delay = null)

Get the queueable options from the job.

string
getQueue(string|null $queue)

Get the queue or return the default.

string
suffixQueue(string $queue, string $suffix = '')

Add the given suffix to the given queue name.

SqsClient
getSqs()

Get the underlying SQS instance.

Details

in InteractsWithTime at line 17
protected int secondsUntil(DateInterval|DateTimeInterface|int $delay)

Get the number of seconds until the given DateTime.

Parameters

DateInterval|DateTimeInterface|int $delay

Return Value

int

in InteractsWithTime at line 29
protected int availableAt(DateInterval|DateTimeInterface|int|null $delay = 0)

Get the "available at" UNIX timestamp.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

int

in InteractsWithTime at line 41
protected DateTimeInterface|int parseDateInterval(DateInterval|DateTimeInterface|int|null $delay)

If the given value is an interval, convert it to a DateTime instance.

Parameters

DateInterval|DateTimeInterface|int|null $delay

Return Value

DateTimeInterface|int

in InteractsWithTime at line 57
protected int currentTime()

Get the current system time as a UNIX timestamp.

Return Value

int

in InteractsWithTime at line 65
protected string runTimeForHumans(float $startTime, float|null $endTime = null)

Given a start time, format the total run time for human readability.

Parameters

float $startTime
float|null $endTime

Return Value

string

protected mixed getAttributeValue(object $target, string $attributeClass, string|null $property = null, mixed $default = null)

Get a configuration value from an attribute, falling back to a property.

Parameters

object $target
string $attributeClass
string|null $property
mixed $default

Return Value

mixed

protected mixed extractAttributeValue(object $instance)

Extract the value from an attribute instance.

Parameters

object $instance

Return Value

mixed

protected object|null getAttributeInstance(object $target, string $attributeClass, ReflectionClass|null $declaringClass = null)

Get an instance of the given attribute class from the target class or its parents.

Parameters

object $target
string $attributeClass
ReflectionClass|null $declaringClass

Return Value

object|null

protected bool propertyOverridesAttribute(object $target, ReflectionClass $reflection, string|null $property, ReflectionClass $attributeDeclaringClass)

Determine if a property declared on a child class overrides an inherited attribute.

Parameters

object $target
ReflectionClass $reflection
string|null $property
ReflectionClass $attributeDeclaringClass

Return Value

bool

in Queue at line 82
mixed pushOn(string|null $queue, object|string $job, mixed $data = '')

Push a new job onto the queue.

Parameters

string|null $queue
object|string $job
mixed $data

Return Value

mixed

in Queue at line 91
mixed laterOn(string|null $queue, DateInterval|DateTimeInterface|int $delay, object|string $job, mixed $data = '')

Push a new job onto a specific queue after (n) seconds.

Parameters

string|null $queue
DateInterval|DateTimeInterface|int $delay
object|string $job
mixed $data

Return Value

mixed

at line 261
mixed bulk(array $jobs, mixed $data = '', string|null $queue = null)

Push an array of jobs onto the queue.

Parameters

array $jobs
mixed $data
string|null $queue

Return Value

mixed

in Queue at line 117
protected string createPayload(array|object|string $job, string|null $queue, mixed $data = '', DateInterval|DateTimeInterface|int|null $delay = null)

Create a payload string from the given job and data.

Parameters

array|object|string $job
string|null $queue
mixed $data
DateInterval|DateTimeInterface|int|null $delay

Return Value

string

Exceptions

InvalidPayloadException

in Queue at line 150
protected array createPayloadArray(array|object|string $job, string|null $queue, mixed $data = '')

Create a payload array from the given job and data.

Parameters

array|object|string $job
string|null $queue
mixed $data

Return Value

array

in Queue at line 160
protected array createObjectPayload(object $job, string|null $queue)

Create a payload for an object-based queue handler.

Parameters

object $job
string|null $queue

Return Value

array

in Queue at line 214
protected string getDisplayName(object $job)

Get the display name for the given job.

Parameters

object $job

Return Value

string

in Queue at line 223
mixed getJobTries(mixed $job)

Get the maximum number of attempts for an object-based queue handler.

Parameters

mixed $job

Return Value

mixed

in Queue at line 237
mixed getJobBackoff(mixed $job)

Get the backoff for an object-based queue handler.

Parameters

mixed $job

Return Value

mixed

in Queue at line 257
mixed getJobExpiration(mixed $job)

Get the expiration timestamp for an object-based queue handler.

Parameters

mixed $job

Return Value

mixed

in Queue at line 272
protected bool jobShouldBeEncrypted(object $job)

Determine if the job should be encrypted.

Parameters

object $job

Return Value

bool

in Queue at line 284
protected array createStringPayload(array|string $job, string|null $queue, mixed $data)

Create a typical, string based queue payload array.

Parameters

array|string $job
string|null $queue
mixed $data

Return Value

array

in Queue at line 307
static void createPayloadUsing(callable|null $callback)

Register a callback to be executed when creating job payloads.

Boot-only. The callback persists in a static property for the worker lifetime and runs on every subsequent payload creation across all coroutines. Passing null clears the registry.

Parameters

callable|null $callback

Return Value

void

in Queue at line 319
protected array withCreatePayloadHooks(string|null $queue, array $payload)

Create the given payload using any registered payload hooks.

Parameters

string|null $queue
array $payload

Return Value

array

in Queue at line 335
Queue setAfterCommitDispatcher(Closure|null $dispatcher)

Set the dispatcher for after-commit queue operations.

Parameters

Closure|null $dispatcher

Return Value

Queue

in Queue at line 350
protected mixed enqueueUsing(object|string $job, string $payload, string|null $queue, DateInterval|DateTimeInterface|int|null $delay, callable $callback)

Enqueue a job using the given callback.

The callback receives the queue that owns the operation first so deferred pooled dispatch never retains a borrowed queue.

Parameters

object|string $job
string $payload
string|null $queue
DateInterval|DateTimeInterface|int|null $delay
callable $callback

Return Value

mixed

in Queue at line 388
protected mixed enqueueNow(object|string $job, string $payload, string|null $queue, DateInterval|DateTimeInterface|int|null $delay, callable $callback)

Enqueue a job immediately using the given callback.

Parameters

object|string $job
string $payload
string|null $queue
DateInterval|DateTimeInterface|int|null $delay
callable $callback

Return Value

mixed

in Queue at line 402
protected bool shouldDispatchAfterCommit(object|string $job)

Determine if the job should be dispatched after all database transactions have committed.

Parameters

object|string $job

Return Value

bool

in Queue at line 418
protected void addUniqueJobRollbackCallback(DatabaseTransactionsManager $transactions, object|string $job)

Register a transaction rollback callback that releases the unique lock for the given job.

Parameters

DatabaseTransactionsManager $transactions
object|string $job

Return Value

void

in Queue at line 434
protected void addDebouncedJobRollbackCallback(DatabaseTransactionsManager $transactions, object|string $job)

Register a transaction rollback callback that releases the debounce token for the given job.

Parameters

DatabaseTransactionsManager $transactions
object|string $job

Return Value

void

in Queue at line 452
protected void raiseJobQueueingEvent(string|null $queue, object|string $job, string $payload, DateInterval|DateTimeInterface|int|null $delay)

Raise the job queueing event.

Parameters

string|null $queue
object|string $job
string $payload
DateInterval|DateTimeInterface|int|null $delay

Return Value

void

in Queue at line 473
protected void raiseJobQueuedEvent(string|null $queue, mixed $jobId, object|string $job, string $payload, DateInterval|DateTimeInterface|int|null $delay)

Raise the job queued event.

Parameters

string|null $queue
mixed $jobId
object|string $job
string $payload
DateInterval|DateTimeInterface|int|null $delay

Return Value

void

in Queue at line 492
string getConnectionName()

Get the connection name for the queue.

Return Value

string

in Queue at line 504
Queue setConnectionName(string $name)

Set the connection name for the queue.

Boot or tests only. Queue connection instances are cached on QueueManager; runtime use races across coroutines and changes every concurrent dispatch through this connection.

Parameters

string $name

Return Value

Queue

in Queue at line 514
array getConfig()

Get the queue configuration array.

Return Value

array

in Queue at line 526
Queue setConfig(array $config)

Set the queue configuration array.

Boot or tests only. Queue connection instances are cached on QueueManager; runtime use races across coroutines and changes every concurrent dispatch through this connection.

Parameters

array $config

Return Value

Queue

in Queue at line 536
Container getContainer()

Get the container instance being used by the connection.

Return Value

Container

in Queue at line 548
Queue setContainer(Container $container)

Set the IoC container instance.

Boot or tests only. Queue connection instances are cached on QueueManager; runtime use races across coroutines and changes every concurrent dispatch through this connection.

Parameters

Container $container

Return Value

Queue

in Queue at line 558
static void flushState()

Flush all static state.

Return Value

void

at line 58
__construct(SqsClient $sqs, string $default, string $prefix = '', string $suffix = '', bool $dispatchAfterCommit = false, array $overflowStorage = [])

Create a new Amazon SQS queue instance.

Parameters

SqsClient $sqs

the Amazon SQS instance

string $default

the name of the default queue

string $prefix

the queue URL prefix

string $suffix

the queue name suffix

bool $dispatchAfterCommit
array $overflowStorage

at line 73
int size(string|null $queue = null)

Get the size of the queue.

Parameters

string|null $queue

Return Value

int

at line 94
int pendingSize(string|null $queue = null)

Get the number of pending jobs.

Parameters

string|null $queue

Return Value

int

at line 107
int delayedSize(string|null $queue = null)

Get the number of delayed jobs.

Parameters

string|null $queue

Return Value

int

at line 120
int reservedSize(string|null $queue = null)

Get the number of reserved jobs.

Parameters

string|null $queue

Return Value

int

at line 133
Collection pendingJobs(string|null $queue = null)

Get the pending jobs for the given queue.

Parameters

string|null $queue

Return Value

Collection

at line 141
Collection delayedJobs(string|null $queue = null)

Get the delayed jobs for the given queue.

Parameters

string|null $queue

Return Value

Collection

at line 149
Collection reservedJobs(string|null $queue = null)

Get the reserved jobs for the given queue.

Parameters

string|null $queue

Return Value

Collection

at line 157
Collection allPendingJobs()

Get all pending jobs across every queue.

Return Value

Collection

at line 165
Collection allDelayedJobs()

Get all delayed jobs across every queue.

Return Value

Collection

at line 173
Collection allReservedJobs()

Get all reserved jobs across every queue.

Return Value

Collection

at line 183
int|null creationTimeOfOldestPendingJob(string|null $queue = null)

Get the creation timestamp of the oldest pending job, excluding delayed jobs.

Not supported by SQS, returns null.

Parameters

string|null $queue

Return Value

int|null

at line 192
mixed push(object|string $job, mixed $data = '', string|null $queue = null)

Push a new job onto the queue.

Parameters

object|string $job
mixed $data
string|null $queue

Return Value

mixed

at line 212
mixed pushRaw(string $payload, string|null $queue = null, array $options = [])

Push a raw payload onto the queue.

Parameters

string $payload
string|null $queue
array $options

Return Value

mixed

at line 231
mixed later(DateInterval|DateTimeInterface|int $delay, object|string $job, mixed $data = '', string|null $queue = null)

Push a new job onto the queue after (n) seconds.

Parameters

DateInterval|DateTimeInterface|int $delay
object|string $job
mixed $data
string|null $queue

Return Value

mixed

at line 321
protected array partitionJobsByAfterCommit(array $jobs, DatabaseTransactionsManager|null $transactions)

Partition jobs by whether they should be deferred until the active transaction commits.

Parameters

array $jobs
DatabaseTransactionsManager|null $transactions

Return Value

array

at line 342
protected array prepareBatchMessages(array $jobs, mixed $data, string|null $queue)

Create the payload for each of the given jobs.

Payloads are created at dispatch time, even for jobs deferred until after the transaction commits.

Parameters

array $jobs
mixed $data
string|null $queue

Return Value

array

at line 368
protected void sendBatchedMessages(array $messages, string|null $queue)

Build entries, dispatch chunks, and raise queued events with SQS message IDs.

Parameters

array $messages
string|null $queue

Return Value

void

Exceptions

SqsException
Throwable

at line 476
protected array prepareSendMessageBatchEntry(int $id, array $message, string|null $queue)

Build the SendMessageBatch entry for a prepared message.

Parameters

int $id
array $message
string|null $queue

Return Value

array

at line 493
protected array chunkBatchEntries(array $entries)

Chunk batch entries by SQS count and payload-size limits.

Parameters

array $entries

Return Value

array

at line 522
protected bool willOverflow(string $payload)

Determine if the payload should be stored in cache.

Parameters

string $payload

Return Value

bool

at line 537
protected array prepareOverflowPayload(string $payload)

Build the cache path and pointer for an overflow payload.

Parameters

string $payload

Return Value

array

at line 554
protected void storeOverflowPayload(Repository $store, string $path, string $payload)

Store an overflow payload.

Parameters

Repository $store
string $path
string $payload

Return Value

void

at line 566
protected void cleanupOverflowPayloads(Repository $store, array $paths)

Remove unpublished overflow payloads without hiding the primary failure.

Parameters

Repository $store
array $paths

Return Value

void

at line 582
protected Repository overflowStore()

Get the cache store for overflow payloads.

Return Value

Repository

at line 595
Job|null pop(string|null $queue = null)

Pop the next job off of the queue.

Parameters

string|null $queue

Return Value

Job|null

at line 619
int clear(string|null $queue)

Delete all of the jobs from the queue.

Parameters

string|null $queue

Return Value

int

at line 639
array getQueueableOptions(object|string $job, string|null $queue, string $payload, DateInterval|DateTimeInterface|int|null $delay = null)

Get the queueable options from the job.

Parameters

object|string $job
string|null $queue
string $payload
DateInterval|DateTimeInterface|int|null $delay

Return Value

array

at line 695
string getQueue(string|null $queue)

Get the queue or return the default.

Parameters

string|null $queue

Return Value

string

at line 707
protected string suffixQueue(string $queue, string $suffix = '')

Add the given suffix to the given queue name.

Parameters

string $queue
string $suffix

Return Value

string

at line 721
SqsClient getSqs()

Get the underlying SQS instance.

Return Value

SqsClient