1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PHPDaemon\Clients\AMQP\Driver\Exception; |
4
|
|
|
|
5
|
|
|
use PHPDaemon\Clients\AMQP\Driver\ConnectionOptions; |
6
|
|
|
use PHPDaemon\Clients\AMQP\Driver\Protocol\Exception\AMQPConnectionExceptionInterface; |
7
|
|
|
use PHPDaemon\Clients\AMQP\Driver\Protocol\Exception\AMQPException; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Class AMQPConnectionException |
11
|
|
|
* @author Aleksey I. Kuleshov YOU GLOBAL LIMITED |
12
|
|
|
* @package PHPDaemon\Clients\AMQP\Driver\Exception |
13
|
|
|
*/ |
14
|
|
|
class AMQPConnectionException extends AMQPException implements AMQPConnectionExceptionInterface |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Create an exception that indicates a failure to establish a connection to |
18
|
|
|
* an AMQP broker. |
19
|
|
|
* |
20
|
|
|
* @param ConnectionOptions $options The options used when establishing the connection. |
21
|
|
|
* @param string $description A description of the problem. |
22
|
|
|
* @param \Exception|null $previous The exception that caused this exception, if any. |
23
|
|
|
* @return AMQPConnectionException |
24
|
|
|
*/ |
25
|
|
|
public static function couldNotConnect( |
26
|
|
|
ConnectionOptions $options, |
27
|
|
|
$description, |
28
|
|
|
\Exception $previous = null |
29
|
|
|
) |
30
|
|
|
{ |
31
|
|
|
return new self( |
32
|
|
|
sprintf( |
33
|
|
|
'Unable to connect to AMQP broker [%s:%d], check connection options and network connectivity (%s).', |
34
|
|
|
$options->getHost(), |
35
|
|
|
$options->getPort(), |
36
|
|
|
rtrim($description, '.') |
37
|
|
|
), |
38
|
|
|
0, |
39
|
|
|
$previous |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Create an exception that indicates an attempt to use a connection that has |
45
|
|
|
* already been closed. |
46
|
|
|
* |
47
|
|
|
* @param ConnectionOptions $options The options used when establishing the connection. |
48
|
|
|
* @param \Exception|null $previous The exception that caused this exception, if any. |
49
|
|
|
* @return AMQPConnectionException |
50
|
|
|
*/ |
51
|
|
View Code Duplication |
public static function notOpen( |
|
|
|
|
52
|
|
|
ConnectionOptions $options, |
53
|
|
|
\Exception $previous = null |
54
|
|
|
) |
55
|
|
|
{ |
56
|
|
|
return new self( |
57
|
|
|
sprintf( |
58
|
|
|
'Unable to use connection to AMQP broker [%s:%d] because it is closed.', |
59
|
|
|
$options->getHost(), |
60
|
|
|
$options->getPort() |
61
|
|
|
), |
62
|
|
|
0, |
63
|
|
|
$previous |
64
|
|
|
); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Create an exception that indicates that the credentials specified in the |
69
|
|
|
* connection options are incorrect. |
70
|
|
|
* |
71
|
|
|
* @param ConnectionOptions $options The options used when establishing the connection. |
72
|
|
|
* @param \Exception|null $previous The exception that caused this exception, if any. |
73
|
|
|
* @return AMQPConnectionException |
74
|
|
|
*/ |
75
|
|
View Code Duplication |
public static function authenticationFailed( |
|
|
|
|
76
|
|
|
ConnectionOptions $options, |
77
|
|
|
\Exception $previous = null |
78
|
|
|
) |
79
|
|
|
{ |
80
|
|
|
return new self( |
81
|
|
|
sprintf( |
82
|
|
|
'Unable to authenticate as "%s" on AMQP broker [%s:%d], check authentication credentials.', |
83
|
|
|
$options->getUsername(), |
84
|
|
|
$options->getHost(), |
85
|
|
|
$options->getPort() |
86
|
|
|
), |
87
|
|
|
0, |
88
|
|
|
$previous |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Create an exception that indicates a the AMQP handshake failed. |
94
|
|
|
* |
95
|
|
|
* @param ConnectionOptions $options The options used when establishing the connection. |
96
|
|
|
* @param string $description A description of the problem. |
97
|
|
|
* @param \Exception|null $previous The exception that caused this exception, if any. |
98
|
|
|
* @return AMQPConnectionException |
99
|
|
|
*/ |
100
|
|
|
public static function handshakeFailed( |
101
|
|
|
ConnectionOptions $options, |
102
|
|
|
$description, |
103
|
|
|
\Exception $previous = null |
104
|
|
|
) |
105
|
|
|
{ |
106
|
|
|
return new self( |
107
|
|
|
sprintf( |
108
|
|
|
'Unable to complete handshake on AMQP broker [%s:%d], %s.', |
109
|
|
|
$options->getHost(), |
110
|
|
|
$options->getPort(), |
111
|
|
|
rtrim($description, '.') |
112
|
|
|
), |
113
|
|
|
0, |
114
|
|
|
$previous |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
/** |
119
|
|
|
* Create an exception that indicates that the credentials specified in the |
120
|
|
|
* connection options do not grant access to the requested AMQP virtual host. |
121
|
|
|
* |
122
|
|
|
* @param ConnectionOptions $options The options used when establishing the connection. |
123
|
|
|
* @param \Exception|null $previous The exception that caused this exception, if any. |
124
|
|
|
* @return AMQPConnectionException |
125
|
|
|
*/ |
126
|
|
View Code Duplication |
public static function authorizationFailed( |
|
|
|
|
127
|
|
|
ConnectionOptions $options, |
128
|
|
|
\Exception $previous = null |
129
|
|
|
) |
130
|
|
|
{ |
131
|
|
|
return new self( |
132
|
|
|
sprintf( |
133
|
|
|
'Unable to access vhost "%s" as "%s" on AMQP broker [%s:%d], check permissions.', |
134
|
|
|
$options->getVhost(), |
135
|
|
|
$options->getUsername(), |
136
|
|
|
$options->getHost(), |
137
|
|
|
$options->getPort() |
138
|
|
|
), |
139
|
|
|
0, |
140
|
|
|
$previous |
141
|
|
|
); |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
/** |
145
|
|
|
* Create an exception that indicates that the broker has failed to send |
146
|
|
|
* any data for a period longer than the heartbeat interval. |
147
|
|
|
* |
148
|
|
|
* @param ConnectionOptions $options The options used when establishing the connection. |
149
|
|
|
* @param int $heartbeatInterval The heartbeat interval negotiated during the AMQP handshake. |
150
|
|
|
* @param \Exception|null $previous The exception that caused this exception, if any. |
151
|
|
|
* @return AMQPConnectionException |
152
|
|
|
*/ |
153
|
|
View Code Duplication |
public static function heartbeatTimedOut( |
|
|
|
|
154
|
|
|
ConnectionOptions $options, |
155
|
|
|
$heartbeatInterval, |
156
|
|
|
\Exception $previous = null |
157
|
|
|
) |
158
|
|
|
{ |
159
|
|
|
return new self( |
160
|
|
|
sprintf( |
161
|
|
|
'The AMQP connection with broker [%s:%d] has timed out, ' |
162
|
|
|
. 'the last heartbeat was received over %d seconds ago.', |
163
|
|
|
$options->getHost(), |
164
|
|
|
$options->getPort(), |
165
|
|
|
$heartbeatInterval |
166
|
|
|
), |
167
|
|
|
0, |
168
|
|
|
$previous |
169
|
|
|
); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
/** |
173
|
|
|
* Create an exception that indicates an unexpected closure of the |
174
|
|
|
* connection to the AMQP broker. |
175
|
|
|
* |
176
|
|
|
* @param ConnectionOptions $options The options used when establishing the connection. |
177
|
|
|
* @param \Exception|null $previous The exception that caused this exception, if any. |
178
|
|
|
* @return AMQPConnectionException |
179
|
|
|
*/ |
180
|
|
View Code Duplication |
public static function closedUnexpectedly( |
|
|
|
|
181
|
|
|
ConnectionOptions $options, |
182
|
|
|
\Exception $previous = null |
183
|
|
|
) |
184
|
|
|
{ |
185
|
|
|
return new self( |
186
|
|
|
sprintf( |
187
|
|
|
'The AMQP connection with broker [%s:%d] was closed unexpectedly.', |
188
|
|
|
$options->getHost(), |
189
|
|
|
$options->getPort() |
190
|
|
|
), |
191
|
|
|
0, |
192
|
|
|
$previous |
193
|
|
|
); |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.