Final Class Yiisoft\Queue\Stubs\InMemoryAdapter
| Inheritance | Yiisoft\ |
|---|---|
| Implements | Yiisoft\ |
In-memory implementation of {@see AdapterInterface} for testing and development purposes.
This adapter stores messages in a local array and processes them sequentially within the same process without any external queue backend. Messages are assigned incremental integer identifiers and are handled in FIFO order.
Note: This implementation is not persistent and should not be used in production, as all data is lost when the process ends.
Public Methods
Method Details
| public Yiisoft\ |
public function getMessagesList(): array
{
return array_values($this->messages);
}
| public Yiisoft\ | ||
| $message | Yiisoft\ |
|
public function push(MessageInterface $message): MessageInterface
{
$id = count($this->messages) + $this->current;
$this->messages[] = $message;
return new IdEnvelope($message, $id);
}
| public void runExisting ( callable $handlerCallback ) | ||
| $handlerCallback | callable | |
public function runExisting(callable $handlerCallback): void
{
$result = true;
while (isset($this->messages[$this->current]) && $result === true) {
$result = $handlerCallback($this->messages[$this->current]);
unset($this->messages[$this->current]);
$this->current++;
}
}
| public \ | ||
| $id | integer|string | |
public function status(int|string $id): MessageStatus
{
$id = (int) $id;
if ($id < 0) {
return MessageStatus::NOT_FOUND;
}
if ($id < $this->current) {
return MessageStatus::DONE;
}
if (isset($this->messages[$id])) {
return MessageStatus::WAITING;
}
return MessageStatus::NOT_FOUND;
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.