prolic / HumusAmqp

PHP 7.4 AMQP library
https://humusamqp.readthedocs.io/
MIT License
76 stars 17 forks source link

Producers/Consumers etc. are not lazy #96

Open func0der opened 3 years ago

func0der commented 3 years ago

Hey there,

I tried the lazy connections. They seem to work fine. What is not lazy are the producers and probably the consumers either.

Given I have the AMQP (library not extension) connection set up as lazy and my producers config in the DI container (laminas in this case) looks like this:

  'factories' => [
            EncryptionConnectionMarkerInterface::class => [
                \Humus\Amqp\Container\ConnectionFactory::class,
                EncryptionConnectionMarkerInterface::class,
            ],
   ],

I inject that specific producer into a class (console command in this case) and get the following error:

PHP Fatal error:  Uncaught PhpAmqpLib\Exception\AMQPConnectionClosedException: ACCESS_REFUSED - Login was refused using authentication mechanism AMQPLAIN. For details see the broker logfile.(0, 0) in /var/www/current/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php:754
Stack trace:
#0 [internal function]: PhpAmqpLib\Connection\AbstractConnection->connection_close()
#1 /var/www/current/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(216): call_user_func()
#2 /var/www/current/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php(373): PhpAmqpLib\Channel\AbstractChannel->dispatch()
#3 /var/www/current/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(264): PhpAmqpLib\Channel\AbstractChannel->wait()
#4 /var/www/current/www/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Connection/AMQPLazyConnection.php(23): PhpAmqpLib\Connection\AbstractConnection->connect()
#5 /var/www/current/www/vendor/prolic in /var/www/current/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php on line 772

Fatal error: Uncaught PhpAmqpLib\Exception\AMQPConnectionClosedException: ACCESS_REFUSED - Login was refused using authentication mechanism AMQPLAIN. For details see the broker logfile.(0, 0) in /var/www/current/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php on line 772

Laminas\ServiceManager\Exception\ServiceNotCreatedException: Service with name "DocumentEncryptionProducerMarkerInterface" could not be created. Reason: ACCESS_REFUSED - Login was refused using authentication mechanism AMQPLAIN. For details see the broker logfile.(0, 0) in /var/www/current/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php on line 772

Call Stack:
    0.0002     396384   1. {main}() /var/www/current/www/vendor/vvzf/console-wrapper/bin/mezzio-console:0
    0.0481    3208944   2. {closure:/var/www/current/www/vendor/vvzf/console-wrapper/bin/mezzio-console:27-38}() /var/www/current/www/vendor/vvzf/console-wrapper/bin/mezzio-console:38
    0.3607    6685696   3. Laminas\ServiceManager\ServiceManager->get($name = 'Symfony\\Component\\Console\\Application') /var/www/current/www/vendor/vvzf/console-wrapper/bin/mezzio-console:32
    0.3607    6685696   4. Laminas\ServiceManager\ServiceManager->doCreate($resolvedName = 'Symfony\\Component\\Console\\Application', $options = ???) /var/www/current/www/vendor/laminas/laminas-servicemanager/src/ServiceManager.php:201

The line that is referenced here is the referencing the ProducerFactory that tries to create a new channel, even though it does not have to at creation time.

When the channel is created the connection will initialize which makes the "Lazy" connection unlazy.

Am I using this feature wrong? If not, what good is a lazy connection, if every other aspect of the library is eager? :D

Is there a plan to implement lazy producers/consumers/exchanges etc. that basically just trigger the connection if needed?

prolic commented 3 years ago

Thanks for the report. Right now I am very busy these days, I'll see if I can get to it soon.