Message bus in TYPO3 with the Doctrine DBAL messenger transport
19. Mai 2025
19. Mai 2025
The documentation for the message bus can be found on the website https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/MessageBus/Index.html, but there are a few additions that I want to make:
During the development I used the default synchronous transport
\Symfony\Component\Messenger\Transport\Sync\SyncTransport
When I switched to the asynchronous transport
\Symfony\Component\Messenger\Bridge\Doctrine\Transport\DoctrineTransport
my code did not work at first. The cause was that I used the DataHandler and therefore must use
Bootstrap::initializeBackendAuthentication();
together with the backend user _CLI_ for the asynchronous transport but not for the synchronous transport.
In the file of the systemd service
/etc/systemd/system/typo3-message-consumer-projectname.service
I had to add the environment variable
TYPO3_CONTEXT=Development/dsimon
The content of the file then looks like this:
[Unit]
Description=Run the TYPO3 message consumer
Requires=mariadb.service
After=mariadb.service
[Service]
Environment="TYPO3_CONTEXT=Development/dsimon"
Type=simple
User=www-data
Group=www-data
ExecStart=/usr/bin/php8.3 /var/www/projectname/vendor/bin/typo3 messenger:consume doctrine --exit-code-on-limit 133
# Generally restart on error
Restart=on-failure
# Restart on exit code 133 (which is returned by the command when limits are reached)
RestartForceExitStatus=133
# ..but do not interpret exit code 133 as an error (as it's just a restart request)
SuccessExitStatus=133
[Install]
WantedBy=multi-user.target
After making changes to this file, the command
systemctl daemon-reload
must be executed
systemctl start typo3-message-consumer-projectname.service
systemctl stop typo3-message-consumer-projectname.service
systemctl restart typo3-message-consumer-projectname.service
With the command
systemctl status typo3-message-consumer-projectname.service
you can check whether the service is running and with the command
journalctl -u typo3-message-consumer-projectname.service -n 10
you can check for error messages when the service is not working.