File tree Expand file tree Collapse file tree 4 files changed +80
-3
lines changed
Expand file tree Collapse file tree 4 files changed +80
-3
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,44 @@ In your ```config/queue.php``` file you have to provide the following:
5151In your ``` config/app.php ``` add ``` 'Forumhouse\LaravelAmqp\ServiceProvider\LaravelAmqpServiceProvider' ``` to the list of service
5252providers registered.
5353
54+ Improved worker stability (PHP 7.1+ is required)
55+ ------------
56+
57+ For better stability please add following code in app/Exceptions/Handler.php:
58+
59+ ``` php
60+ class Handler extends ExceptionHandler
61+ {
62+ ```
63+
64+ to
65+
66+ ``` php
67+ class Handler extends ExceptionHandler
68+ {
69+ use AMQPFailureDetector;
70+ ```
71+
72+ And
73+
74+ ``` php
75+ public function report(Exception $exception)
76+ {
77+ parent::report($exception);
78+ }
79+ ```
80+
81+ to
82+
83+ ``` php
84+ public function report(Exception $exception)
85+ {
86+ $this->catchAMQPConnectionFailure($exception);
87+ parent::report($exception);
88+ }
89+ ```
90+
91+
5492Usage
5593------------
5694
Original file line number Diff line number Diff line change 44 "minimum-stability" : " stable" ,
55 "license" : " GPL-2.0" ,
66 "require" : {
7- "php" : " >=7" ,
7+ "php" : " >=7.1 " ,
88 "php-amqplib/php-amqplib" : " 2.6.*"
99 },
1010 "require-dev" : {
Original file line number Diff line number Diff line change @@ -125,11 +125,14 @@ public function getQueue()
125125 * Get the job identifier.
126126 *
127127 * @return string
128- * @throws \OutOfBoundsException
129128 */
130129 public function getJobId ()
131130 {
132- return $ this ->amqpMessage ->get ('message_id ' );
131+ try {
132+ return $ this ->amqpMessage ->get ('message_id ' );
133+ } catch (\OutOfBoundsException $ exception ){
134+ return null ;
135+ }
133136 }
134137
135138}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Forumhouse \LaravelAmqp \Traits ;
4+ use Exception ;
5+ use Illuminate \Support \Str ;
6+
7+ trait AMQPFailureDetector
8+ {
9+
10+ public function catchAMQPConnectionFailure (Exception $ exception )
11+ {
12+ if (\App::runningInConsole () && $ this ->causedByLostConnection ($ exception ) && extension_loaded ('posix ' )){
13+ posix_kill (getmypid (), SIGTERM );
14+ }
15+ }
16+
17+ protected function causedByLostConnection (Exception $ e )
18+ {
19+ $ message = $ e ->getMessage ();
20+
21+ return Str::contains ($ message , [
22+ 'server has gone away ' ,
23+ 'no connection to the server ' ,
24+ 'Lost connection ' ,
25+ 'is dead or not enabled ' ,
26+ 'Error while sending ' ,
27+ 'decryption failed or bad record mac ' ,
28+ 'server closed the connection unexpectedly ' ,
29+ 'SSL connection has been closed unexpectedly ' ,
30+ 'Error writing data to the connection ' ,
31+ 'Resource deadlock avoided ' ,
32+ 'Transaction() on null ' ,
33+ 'child connection forced to terminate due to client_idle_limit ' ,
34+ ]);
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments