---
title: "Queue callbacks"
manual: "Crawler"
version: "main"
permalink: "https://docs.typo3.org/permalink/tomasnorre/crawler:queue-callbacks@main"
source: "Features/QueueCallbacks/Index.rst"
rendered: "2026-11-22T10:43:00+00:00"
---

# Queue callbacks {#queue-callbacks}

<!-- TODO: no Markdown rendering for "versionadded" -->

Callbacks implement AOECrawlerQueueQueueCallbackInterface, see
Queue callbacks implement an interface.

Besides URLs, the queue can hold callbacks: instead of crawling a URL, the
worker calls a class of your extension. This is useful for work that should
run in the background with the crawler, e.g. crawling external files. The
result is stored with the queue entry and shown in the **Crawler log**.

## Implement the callback {#implement-the-callback}

A callback implements `AOECrawlerQueueQueueCallbackInterface`. It is a
service, so it gets its dependencies by constructor injection:

**EXT:my_extension/Classes/Crawler/ReindexFileCallback.php**

```php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Crawler;

use AOE\Crawler\Queue\QueueCallbackInterface;
use MyVendor\MyExtension\Service\FileIndexer;

final readonly class ReindexFileCallback implements QueueCallbackInterface
{
    public function __construct(
        private FileIndexer $fileIndexer,
    ) {
    }

    public function execute(array $parameters): mixed
    {
        return $this->fileIndexer->reindex((int) $parameters['fileUid']);
    }
}
```

The return value is stored JSON encoded as the result of the queue entry.

With `autoconfigure: true` in the [`Configuration/Services.yaml`](https://docs.typo3.org/m/typo3/reference-coreapi/14.3/en-us/ExtensionArchitecture/FileStructure/Configuration/ServicesYaml.html#file-extension-configuration-services-yaml) of your
extension, which is the default, the callback is registered automatically.
Classes that are not services are created with
`GeneralUtility::makeInstance()`, without constructor arguments.

## Add the callback to the queue {#add-the-callback-to-the-queue}

Add a queue entry with `AOECrawlerQueueQueueEntryWriter::addCallback()`.
Inject the `QueueEntryWriter` into your own service:

**EXT:my_extension/Classes/Service/FileQueue.php**

```php
<?php

declare(strict_types=1);

namespace MyVendor\MyExtension\Service;

use AOE\Crawler\Queue\QueueEntryWriter;
use MyVendor\MyExtension\Crawler\ReindexFileCallback;

final readonly class FileQueue
{
    public function __construct(
        private QueueEntryWriter $queueEntryWriter,
    ) {
    }

    public function reindexLater(int $fileUid, int $pageId): void
    {
        $this->queueEntryWriter->addCallback(
            ReindexFileCallback::class,
            ['fileUid' => $fileUid],
            $pageId,
        );
    }
}
```

`addCallback()` takes these arguments:

-   **`$callbackClassName`**

    The class implementing `QueueCallbackInterface`.

-   **`$parameters`**

    Handed over to `execute()`. They are stored JSON encoded, so they must be
    JSON encodable.

-   **`$pageId`**

    The page the queue entry is shown with in the **Crawler log**,
    `0` by default.

-   **`$scheduled`**

    The Unix timestamp to execute the callback at, `0` (the default) for now.

-   **`$setId`**

    The set the queue entry belongs to, `0` by default. Give several queue
    entries the same set id to show them together in the
    **Crawler log**.

The queue entry is dispatched to the message bus like a URL, and processed by
the worker, see [Message bus instead of the Crawler process handling](https://docs.typo3.org/permalink/tomasnorre/crawler:upgrade-message-bus@main).
