RabbitMQ php错误Socket连接超时

时间:2016-01-08 15:37:13

标签: php rabbitmq php-amqplib

我收到套接字连接超时错误。由于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";
     }
 }  

0 个答案:

没有答案
相关问题