99use Illuminate \Queue \Jobs \Job ;
1010use Illuminate \Queue \Jobs \JobName ;
1111use Illuminate \Support \Str ;
12- use PhpAmqpLib \ Channel \ AMQPChannel ;
13- use PhpAmqpLib \ Message \ AMQPMessage ;
12+ use Interop \ Amqp \ AmqpConsumer ;
13+ use Interop \ Amqp \ AmqpMessage ;
1414use VladimirYuldashev \LaravelQueueRabbitMQ \Queue \RabbitMQQueue ;
1515
1616class RabbitMQJob extends Job implements JobContract
@@ -23,20 +23,20 @@ class RabbitMQJob extends Job implements JobContract
2323 const ATTEMPT_COUNT_HEADERS_KEY = 'attempts_count ' ;
2424
2525 protected $ connection ;
26- protected $ channel ;
26+ protected $ consumer ;
2727 protected $ message ;
2828
2929 public function __construct (
3030 Container $ container ,
3131 RabbitMQQueue $ connection ,
32- AMQPChannel $ channel ,
32+ AmqpConsumer $ consumer ,
3333 string $ queue ,
34- AMQPMessage $ message ,
34+ AmqpMessage $ message ,
3535 string $ connectionName = null
3636 ) {
3737 $ this ->container = $ container ;
3838 $ this ->connection = $ connection ;
39- $ this ->channel = $ channel ;
39+ $ this ->consumer = $ consumer ;
4040 $ this ->queue = $ queue ;
4141 $ this ->message = $ message ;
4242 $ this ->connectionName = $ connectionName ;
@@ -79,16 +79,10 @@ public function fire()
7979 */
8080 public function attempts (): int
8181 {
82- if ($ this ->message ->has ('application_headers ' ) === true ) {
83- $ headers = $ this ->message ->get ('application_headers ' )->getNativeData ();
84-
85- if (isset ($ headers [self ::ATTEMPT_COUNT_HEADERS_KEY ]) === true ) {
86- return $ headers [self ::ATTEMPT_COUNT_HEADERS_KEY ];
87- }
88- }
89-
9082 // set default job attempts to 1 so that jobs can run without retry
91- return 1 ;
83+ $ defaultAttempts = 1 ;
84+
85+ return $ this ->message ->getProperty (self ::ATTEMPT_COUNT_HEADERS_KEY , $ defaultAttempts );
9286 }
9387
9488 /**
@@ -98,14 +92,15 @@ public function attempts(): int
9892 */
9993 public function getRawBody (): string
10094 {
101- return $ this ->message ->body ;
95+ return $ this ->message ->getBody () ;
10296 }
10397
10498 /** @inheritdoc */
10599 public function delete ()
106100 {
107101 parent ::delete ();
108- $ this ->channel ->basic_ack ($ this ->message ->get ('delivery_tag ' ));
102+
103+ $ this ->consumer ->acknowledge ($ this ->message );
109104 }
110105
111106 /** @inheritdoc */
@@ -143,7 +138,7 @@ public function release($delay = 0)
143138 */
144139 public function getJobId (): string
145140 {
146- return $ this ->message ->get ( ' correlation_id ' );
141+ return $ this ->message ->getCorrelationId ( );
147142 }
148143
149144 /**
0 commit comments