Skip to content

Commit 0798440

Browse files
authored
Merge pull request php-amqplib#750 from ramunasd/fix_connection_close_exception
throw AMQPConnectionClosedException when broker wants to close connection
2 parents 14caaaa + 1d4790e commit 0798440

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

PhpAmqpLib/Channel/AbstractChannel.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,20 @@ abstract class AbstractChannel
3232
*/
3333
const PROTOCOL_091 = Wire\Constants091::VERSION;
3434

35-
/** @var array */
36-
protected $frame_queue;
35+
/**
36+
* Lower level queue for frames
37+
* @var array
38+
*/
39+
protected $frame_queue = array();
3740

38-
/** @var array */
39-
protected $method_queue;
41+
/**
42+
* Higher level queue for methods
43+
* @var array
44+
*/
45+
protected $method_queue = array();
4046

4147
/** @var bool */
42-
protected $auto_decode;
48+
protected $auto_decode = false;
4349

4450
/** @var Wire\Constants */
4551
protected $constants;
@@ -87,9 +93,6 @@ public function __construct(AbstractConnection $connection, $channel_id)
8793
$this->connection = $connection;
8894
$this->channel_id = $channel_id;
8995
$connection->channels[$channel_id] = $this;
90-
$this->frame_queue = array(); // Lower level queue for frames
91-
$this->method_queue = array(); // Higher level queue for methods
92-
$this->auto_decode = false;
9396

9497
$this->msg_property_reader = new AMQPReader(null);
9598
$this->wait_content_reader = new AMQPReader(null);

PhpAmqpLib/Connection/AbstractConnection.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PhpAmqpLib\Exception\AMQPInvalidFrameException;
99
use PhpAmqpLib\Exception\AMQPIOException;
1010
use PhpAmqpLib\Exception\AMQPNoDataException;
11-
use PhpAmqpLib\Exception\AMQPProtocolConnectionException;
1211
use PhpAmqpLib\Exception\AMQPRuntimeException;
1312
use PhpAmqpLib\Exception\AMQPSocketException;
1413
use PhpAmqpLib\Exception\AMQPTimeoutException;
@@ -386,6 +385,8 @@ public function write($data)
386385

387386
protected function do_close()
388387
{
388+
$this->frame_queue = [];
389+
$this->method_queue = [];
389390
$this->setIsConnected(false);
390391
$this->close_input();
391392
$this->close_socket();
@@ -723,18 +724,19 @@ public function close($reply_code = 0, $reply_text = '', $method_sig = array(0,
723724

724725
/**
725726
* @param AMQPReader $reader
726-
* @throws \PhpAmqpLib\Exception\AMQPProtocolConnectionException
727+
* @throws AMQPConnectionClosedException
727728
*/
728729
protected function connection_close(AMQPReader $reader)
729730
{
730-
$reply_code = $reader->read_short();
731-
$reply_text = $reader->read_shortstr();
732-
$class_id = $reader->read_short();
733-
$method_id = $reader->read_short();
731+
$code = (int)$reader->read_short();
732+
$reason = $reader->read_shortstr();
733+
$class = $reader->read_short();
734+
$method = $reader->read_short();
735+
$reason .= sprintf('(%s, %s)', $class, $method);
734736

735737
$this->x_close_ok();
736738

737-
throw new AMQPProtocolConnectionException($reply_code, $reply_text, array($class_id, $method_id));
739+
throw new AMQPConnectionClosedException($code, $reason);
738740
}
739741

740742
/**
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22
namespace PhpAmqpLib\Exception;
33

4+
/**
5+
* @deprecated
6+
*/
47
class AMQPProtocolConnectionException extends AMQPProtocolException
58
{
69
}

0 commit comments

Comments
 (0)