netglue / laminas-messenger

PSR-11 factories for integrating Symfony Messenger with Laminas/Mezzio
Other
10 stars 4 forks source link

The receiver "doctrine" does not exist. Valid receivers are: doctrine. #225

Open aluuraco opened 1 month ago

aluuraco commented 1 month ago

I'm getting the strange receiver does not exist error message when trying to initiate the messenger:consume command. Does anybody know what's wrong?

For some more context, I'm using this on a stand-alone Laminas MVC project and I've created a bin/console file to initiate the Command like the following: php bin/console messenger:consume

The bin/console is written as follows:

#!/usr/bin/env php
<?php

use Netglue\PsrContainer\Messenger\Container\Command\DebugCommandFactory;
use Netglue\PsrContainer\Messenger\Container\Command\ConsumeCommandFactory;
use Symfony\Component\Console\Application as SymfonyConsoleApplication;
use Laminas\Mvc\Application as LaminasApplication;

// Set the correct path to Laminas bootstrap file
require 'vendor/autoload.php';

// Initialize Laminas application
$appConfig = require 'config/application.config.php';
$app = LaminasApplication::init($appConfig);
$serviceManager = $app->getServiceManager();

$consoleApp = new SymfonyConsoleApplication('symfony-console');
// Retrieve the actual command from the factory, not the factory itself
$consumeCommandFactory = new ConsumeCommandFactory();
$consumeMessagesCommand = $consumeCommandFactory($serviceManager);

$debugCommandFactory = new DebugCommandFactory();
$debugMessagesCommand = $debugCommandFactory($serviceManager);
// Add command to the console application
$consoleApp->add($consumeMessagesCommand);
$consoleApp->add($debugMessagesCommand);

// Run the console application
try {
    $consoleApp->run();
}catch (\Exception $exception){
    var_dump("CLI Error: " . $exception->getMessage());
}

I've also the following config written, following the examples provided in the docs folder of this library:

return [
    'dependencies' => [
        'factories' => [
            'doctrine' => [TransportFactory::class, 'doctrine'],
        ],
    ],

    // And for Mezzio, this is how it expects. We define this separately in case the NetGlue package
    // does not work well with MVC.
    'symfony' => [
        'messenger' => [
            'doctrine' => [
                'dsn' => 'doctrine://doctrine.entitymanager.orm_default',
                'serializer' => SymfonySerializer::class,
            ],

        ]
    ]
];
gsteel commented 1 month ago

Hay @aluuraco - I'm pretty sure that your transport should be defined under symfony.messenger.transports.transportName, you have it defined under symfony.messenger.transportName - I'd also advise a more descriptive service name such as doctrineTransportForSomething so that no-one pulls the transport from the DI container when they really wanted the ORM or DBAL connection for example.

gsteel commented 1 month ago

PS, if the docs are wrong, please send a patch with a fix :)

aluuraco commented 1 month ago

I found that my issue description had an error during copy and paste of the config file: `return [ 'dependencies' => [ 'factories' => [ 'doctrine' => [TransportFactory::class, 'doctrine'], 'my_default_failure_transport' => [MessageBusStaticFactory::class, 'my_default_failure_transport'], ], ],

// And for Mezzio, this is how it expects. We define this separately in case the NetGlue package
// does not work well with MVC.
'symfony' => [
    'messenger' => [
        'transports' => [
            'doctrine' => [
                'dsn' => 'doctrine://doctrine.entitymanager.orm_default',
                'serializer' => SymfonySerializer::class,
            ],
            'my_default_failure_transport' => [
                'dsn' => 'in-memory:///',
            ],
        ],
        'failure_transport' => 'my_default_failure_transport',
        'logger' => LoggerInterface::class,
        'routing' => [
            ApplicationMessage::class => ['doctrine']
        ]
    ]
]

];`

I'm still getting the same error message that the very same transport that I have defined, is a receiver that does not exist, even though the command would say that the transport that I parsed into the command is a valid receiver.

gsteel commented 1 month ago

🤔 As per #190, the doctrine transport factory is the only untested thing here.

What version of Symfony messenger are you using? 6 or 7? In 7, (I think) the shipped doctrine factory was marked internal, so this lib might need to work out something else when it comes to using doctrine as a transport.

Regardless, it's going to take me some time to figure out what the problem is and I don't have very much of that right now.

Any tests that you can contribute will improve the situation 👍