Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support redis symfony/messenger consumers #535

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ DATABASE_URL=postgresql://127.0.0.1:5432/main?serverVersion=11&charset=utf8
###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=doctrine://default
# MESSENGER_TRANSPORT_FAILED_DSN=amqp://guest:guest@localhost:5672/%2f/failed
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=false
MESSENGER_TRANSPORT_FAILED_DSN=doctrine://default?queue_name=failed&auto_setup=false
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
# MESSENGER_TRANSPORT_FAILED_DSN=redis://localhost:6379/failed
###< symfony/messenger ###

###> symfony/mailer ###
Expand Down
5 changes: 4 additions & 1 deletion .env.docker
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,11 @@ DATABASE_URL=postgresql://main:main@database:5432/main?serverVersion=11&charset=
###> symfony/messenger ###
# Choose one of the transports below
# MESSENGER_TRANSPORT_DSN=amqp://guest:guest@localhost:5672/%2f/messages
# MESSENGER_TRANSPORT_DSN=doctrine://default
# MESSENGER_TRANSPORT_FAILED_DSN=amqp://guest:guest@localhost:5672/%2f/failed
MESSENGER_TRANSPORT_DSN=doctrine://default?auto_setup=false
MESSENGER_TRANSPORT_FAILED_DSN=doctrine://default?queue_name=failed&auto_setup=false
# MESSENGER_TRANSPORT_DSN=redis://localhost:6379/messages
# MESSENGER_TRANSPORT_FAILED_DSN=redis://localhost:6379/failed
###< symfony/messenger ###

###> symfony/mailer ###
Expand Down
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ ARG TIMEZONE="UTC"

SHELL ["sh", "-eo", "pipefail", "-c"]

# install composer and extensions: pdo_pgsql, intl, zip
# install composer and extensions: pdo_pgsql, redis, intl, zip
RUN apk update && \
apk add --no-cache -q \
$PHPIZE_DEPS \
Expand All @@ -17,6 +17,8 @@ RUN apk update && \
icu-dev \
libzip-dev \
openssh-client \
&& pecl install \
redis \
&& \
curl -sS https://getcomposer.org/installer | \
php -- --install-dir=/usr/local/bin --filename=composer && \
Expand All @@ -26,6 +28,7 @@ RUN apk update && \
docker-php-ext-install pdo_pgsql && \
docker-php-ext-install intl && \
docker-php-ext-install zip && \
docker-php-ext-enable redis.so && \
rm -rf /var/cache/apk/*

# set timezone
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"symfony/messenger": "5.3.*",
"symfony/monolog-bundle": "^3.5",
"symfony/process": "5.3.*",
"symfony/redis-messenger": "5.3.*",
"symfony/security-bundle": "5.3.*",
"symfony/twig-bundle": "5.3.*",
"symfony/validator": "5.3.*",
Expand Down Expand Up @@ -113,7 +114,12 @@
"preferred-install": {
"*": "dist"
},
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"composer/package-versions-deprecated": true,
"phpstan/extension-installer": true,
"symfony/flex": true
}
},
"extra": {
"symfony": {
Expand Down
16 changes: 8 additions & 8 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions config/packages/messenger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ framework:
failure_transport: failed

transports:
async: 'doctrine://default?auto_setup=false'
failed: 'doctrine://default?queue_name=failed&auto_setup=false'
async: '%env(MESSENGER_TRANSPORT_DSN)%'
failed: '%env(MESSENGER_TRANSPORT_FAILED_DSN)%'

routing:
'Buddy\Repman\Message\Organization\SynchronizePackage': async
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ services:
volumes:
- postgres-data:/var/lib/postgresql/data

redis:
<< : *restart_policy
image: redis:6.2-alpine

app:
<< : *restart_policy
image: buddy/repman:1.3.4
Expand All @@ -34,6 +38,7 @@ services:
- app-public:/app/public
depends_on:
- database
- redis

consumer:
<< : *restart_policy
Expand Down
7 changes: 4 additions & 3 deletions src/Service/Telemetry.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@
use Buddy\Repman\Service\Telemetry\TechnicalEmail;
use Ramsey\Uuid\Uuid;
use Symfony\Component\Messenger\Transport\Receiver\MessageCountAwareInterface;
use Symfony\Component\Messenger\Transport\TransportInterface;

final class Telemetry
{
private string $instanceIdFile;
private TelemetryQuery $query;
private Endpoint $endpoint;
private Config $config;
private MessageCountAwareInterface $failedTransport;
private TransportInterface $failedTransport;
private ProxyRegister $proxies;

public function __construct(string $instanceIdFile, TelemetryQuery $query, Endpoint $endpoint, Config $config, MessageCountAwareInterface $failedTransport, ProxyRegister $proxies)
public function __construct(string $instanceIdFile, TelemetryQuery $query, Endpoint $endpoint, Config $config, TransportInterface $failedTransport, ProxyRegister $proxies)
{
$this->instanceIdFile = $instanceIdFile;
$this->query = $query;
Expand Down Expand Up @@ -70,7 +71,7 @@ public function collectAndSend(\DateTimeImmutable $date): void
sprintf('%s %s', php_uname('s'), php_uname('r')),
PHP_MAJOR_VERSION.'.'.PHP_MINOR_VERSION.'.'.PHP_RELEASE_VERSION,
$this->query->usersCount(),
$this->failedTransport->getMessageCount(),
($this->failedTransport instanceof MessageCountAwareInterface) ? $this->failedTransport->getMessageCount() : 0,
$this->getConfig(),
),
$this->getOrganizations($date),
Expand Down