3

我收到套接字连接超时错误。由于 php-amqplib 上的帖子有限。想不通。

注意:我正在尝试捕获该错误并重新连接它。但无法弄清楚如何在php中做到这一点。nodejs 的 _onError 行会有所帮助。

我收到以下错误:

PHP Fatal error:  Uncaught exception 'PhpAmqpLib\Exception\AMQPTimeoutException' with message 'Error sending data. Socket connection timed out' in /home/users/yagneshm/rabbitmq-php/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php:194        

Stack trace:
        #0 /home/users/yagneshm/rabbitmq-php/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(336): PhpAmqpLib\Wire\IO\StreamIO->write('\x01\x00\x01\x00\x00\x00\r\x00<\x00(\x00\x00\x00\x04...')
        #1 /home/users/yagneshm/rabbitmq-php/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Connection/AbstractConnection.php(377): PhpAmqpLib\Connection\AbstractConnection->write('\x01\x00\x01\x00\x00\x00\r\x00<\x00(\x00\x00\x00\x04...')
        #2 /home/users/yagneshm/rabbitmq-php/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php(1102): PhpAmqpLib\Connection\AbstractConnection->send_content(1, 60, 0, 15, '\xB9\x80\x10application/...', 'test no. 998539', Object(PhpAmqpLib\Wire\AMQPWriter))
        #3 /home/users/yagneshm/rabbitmq-php/src/rmq.php(144): PhpAmqpLib\Channel\AMQ in /home/users/yagneshm/rabbitmq-php/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Wire/IO/StreamIO.php on line 194

我正在使用以下连接功能:

public function connect() 
    {
        try 
        {
            $this->connection = new AMQPStreamConnection($this->HOST, $this->PORT, $this->USER, $this->PASS, $this->VHOST, ['read_write_timeout' => 2 * $this->HEARTBEAT,'heartbeat'=> $this->HEARTBEAT]);
            $this->channel = $this->connection->channel();
        } catch (Exception $e) {
            echo "log error";    
        }
    }

以及以下发送消息:

public function send($queue, $message, $params)
{
    try
    {
         $message = new AMQPMessage( $message, array( 'content_type' =>$contentType,
                                                      'delivery_mode' => $Persistent,
                                                      'expiration' => $Expiration,
                                                      'priority' => $Priority,
                                                      'message_id' => $messageId ));
          $this->channel->basic_publish($message, $exchangeName, $queue);            

     } catch (Exception $e) 
     {
            echo "log error";
     }
 }  
4

0 回答 0