Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Messenger] Generated redis transport consumer name #51604

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

Open
danielburger1337 opened this issue Sep 9, 2023 · 0 comments · May be fixed by #53528
Open

[Messenger] Generated redis transport consumer name #51604

danielburger1337 opened this issue Sep 9, 2023 · 0 comments · May be fixed by #53528

Comments

@danielburger1337
Copy link
Contributor

Description

As you may now, the redis transport requires that each worker needs to have a unique connection consumer name. The suggested and very easy solution is to use the HOSTNAME env variable. This works perfectly in production where we use containerization via Docker, but there is a small issue when developing locally and not inside a devcontainer:

When developing locally in my WSL instance, for some reason the HOSTNAME env variable is empty when I try to use it via the '%env(HOSTNAME)%' notation in the Yaml configuration, even though the env variable does exist.

A tiny quality of life improvement would be to allow setting the consumer name to a generated random value.
AFAIK the consumer names dont have to be stable, so this would simplify configuration quite a bit when having multiple workers work on a single queue or multiple queues.

Example

# config/packages/messenger.yaml
framework:
    messenger:
        transports:
            # https://symfony.com/doc/current/messenger.html#transport-configuration
            async:
                dsn: '%env(MESSENGER_TRANSPORT_DSN)%'
                options:
                    consumer: _RANDOM

and then

// Symfony\Component\Messenger\Bridge\Redis\Transport\Connection

public function __construct(array $options, \Redis|Relay|\RedisCluster $redis = null)
{
    // ...
    $this->consumer = $options['consumer'] === '_RANDOM' ? bin2hex(random_bytes(8)) : $options['consumer'];
    // ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants