bschmitt / laravel-amqp

AMQP wrapper for Laravel and Lumen to publish and consume messages
MIT License
268 stars 86 forks source link

Error after reading from consumer #23

Closed dugjohnson closed 7 years ago

dugjohnson commented 7 years ago

I'm just using this plug-in as a consumer in an Artisan Command of a RabbitMQ queue that is fed elswhere.

Everything reads correctly. At the end I get the following error


PHP Fatal error:  Uncaught Error: Call to a member function send_channel_method_frame() on null in /opt/worldeducation/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php:116
Stack trace:
#0 /opt/worldeducation/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(97): PhpAmqpLib\Channel\AbstractChannel->send_method_frame(Array, Object(PhpAmqpLib\Wire\AMQPWriter))
#1 /opt/worldeducation/vendor/bschmitt/laravel-amqp/src/Request.php(145): PhpAmqpLib\Channel\AMQPChannel->close()
#2 [internal function]: Bschmitt\Amqp\Request::shutdown(Object(PhpAmqpLib\Channel\AMQPChannel), Object(PhpAmqpLib\Connection\AMQPSSLConnection))
#3 {main}
  thrown in /opt/worldeducation/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php on line 116

My code

public function handle()
    {

        Amqp::consume('brain_etl', function ($message, $resolver) {

            try {

                $zohoETL = new ZohoETL();
                $zohoETL->payload = $message->body;
                $zohoETL->save();

                $resolver->acknowledge($message);

                $resolver->stopWhenProcessed();
            } catch (Exception $exception) {
                $this->info('Done processing');
            }

        });

    }

I put in the try/catch to try to eliminate the console display, but that didn't change anything.

Any ideas of how to fix this would be appreciated

bschmitt commented 7 years ago

I'm not 100% sure but it has sth to do with the declaration of the queue. Can you post your config here?

hp-amqplib/issues/337 https://github.com/php-amqplib/php-amqplib/pull/358

outcaster commented 6 years ago

Hi! apparently it seems I have the same issue, i have a consumer with this test code:

`public function handle() { \Amqp::consume('site', function ($message, $resolver) {

       var_dump($message->body);

       $resolver->acknowledge($message);
       $resolver->stopWhenProcessed();

    });
}`

This consumer is listening to a queue called 'site'. the plugin config is this one

`'properties' => [ 'local' => [ 'host' => getenv('RABBITMQ_HOST'), 'port' => getenv('RABBITMQ_PORT'), 'username' => getenv('RABBITMQ_USERNAME'), 'password' => getenv('RABBITMQ_PASSWORD'), 'vhost' => '/', 'connect_options' => [], 'ssl_options' => [],

        'exchange'              => getenv('RABBITMQ_EXCHANGE'),
        'exchange_type'         => 'topic',
        'exchange_passive'      => false,
        'exchange_durable'      => true,
        'exchange_auto_delete'  => false,
        'exchange_internal'     => false,
        'exchange_nowait'       => false,
        'exchange_properties'   => [],

        'queue_force_declare'   => false,
        'queue_passive'         => false,
        'queue_durable'         => true,
        'queue_exclusive'       => false,
        'queue_auto_delete'     => false,
        'queue_nowait'          => false,
        'queue_properties'      => ['x-ha-policy' => ['S', 'all']],

        'consumer_tag'          => '',
        'consumer_no_local'     => false,
        'consumer_no_ack'       => false,
        'consumer_exclusive'    => false,
        'consumer_nowait'       => false,
        'timeout'               => 0,
        'persistent'            => false,
    ],
],`

The queue has been declared from the rabbit mq admin with mostly default configuration, just set as "durable".

The consumer works fine, read and process the messages however in the last line of code, when it tries to close, i get

Call to a member function send_channel_method_frame() on null in /var/www/html/demo/vendor/php-amqplib/php-amqplib/PhpAmqpLib/Channel/AbstractChannel.php:116

no clue about what could be causing this. any idea would be gladly appreciated thanks!

outcaster commented 6 years ago

found the issue by myself, its related to the amqp-lib version that was installed on my server, i updated it to the latest version and the issue was gone :).