Skip to content

Commit dd72afc

Browse files
committed
Merge remote-tracking branch 'origin/v4.2' into v5.0
Conflicts: README.md composer.json src/FintechFab/LaravelQueueRabbitMQ/Queue/Jobs/RabbitMQJob.php src/FintechFab/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php
2 parents 5e79b14 + b67565f commit dd72afc

17 files changed

+186
-1442
lines changed

README.md

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,10 @@ Require this package in your composer.json and run composer update (IMPORTANT! D
77

88
"fintech-fab/laravel-queue-rabbitmq": "5.0"
99

10-
or run:
11-
12-
composer require "fintech-fab/laravel-queue-rabbitmq"
13-
1410
After composer update is finished you need to add ServiceProvider to your `providers` array in app.php:
1511

16-
1712
'FintechFab\LaravelQueueRabbitMQ\LaravelQueueRabbitMQServiceProvider',
1813

19-
2014
now you are able to configure your connections in queue.php:
2115

2216
return [
@@ -26,26 +20,30 @@ now you are able to configure your connections in queue.php:
2620
'connections' => [
2721

2822
'rabbitmq' => [
29-
'driver' => 'rabbitmq',
30-
31-
'host' => '',
32-
'port' => '',
33-
34-
'vhost' => '',
35-
'login' => '',
36-
'password' => '',
37-
38-
'queue' => '', // name of the default queue
39-
40-
'exchange_name' => '', // name of the exchange
41-
42-
// Type of your exchange
43-
// Can be AMQP_EX_TYPE_DIRECT or AMQP_EX_TYPE_FANOUT
44-
// see documentation for more info
45-
// http://www.rabbitmq.com/tutorials/amqp-concepts.html
46-
'exchange_type' => AMQP_EX_TYPE_DIRECT,
47-
'exchange_flags' => AMQP_DURABLE,
48-
23+
'driver' => 'rabbitmq',
24+
25+
'host' => '',
26+
'port' => 5672,
27+
28+
'vhost' => '/',
29+
'login' => '',
30+
'password' => '',
31+
32+
'queue' => '', // name of the default queue,
33+
34+
'queue_params' => [
35+
'passive' => false,
36+
'durable' => true,
37+
'exclusive' => false,
38+
'auto_delete' => false,
39+
],
40+
41+
'exchange_params' => [
42+
'type' => 'direct', // more info at http://www.rabbitmq.com/tutorials/amqp-concepts.html
43+
'passive' => false,
44+
'durable' => true, // the exchange will survive server restarts
45+
'auto_delete' => false, // the exchange won't be deleted once the channel is closed.
46+
],
4947

5048
],
5149

composer.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@
1212
"require": {
1313
"php": ">=5.4.0",
1414
"illuminate/support": "5.0.*",
15-
"illuminate/queue": "5.0.*"
16-
},
17-
"suggest": {
18-
"ext-amqp": "PECL extension for the AMQP protocol - it won't work without"
15+
"illuminate/queue": "5.0.*",
16+
"videlalvaro/php-amqplib": "2.5.*"
1917
},
2018
"autoload": {
2119
"psr-0": {

src/FintechFab/LaravelQueueRabbitMQ/Queue/Connectors/RabbitMQConnector.php

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php namespace FintechFab\LaravelQueueRabbitMQ\Queue\Connectors;
22

3-
use AMQPConnection;
43
use FintechFab\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;
54
use Illuminate\Queue\Connectors\ConnectorInterface;
5+
use PhpAmqpLib\Connection\AMQPConnection;
66

77
class RabbitMQConnector implements ConnectorInterface
88
{
@@ -16,25 +16,12 @@ class RabbitMQConnector implements ConnectorInterface
1616
*/
1717
public function connect(array $config)
1818
{
19-
2019
// create connection with AMQP
21-
$connection = new AMQPConnection($config);
22-
$connection->connect();
23-
24-
if (!isset($config['exchange_type'])) {
25-
$config['exchange_type'] = AMQP_EX_TYPE_DIRECT;
26-
}
27-
28-
if (!isset($config['exchange_flags'])) {
29-
$config['exchange_flags'] = AMQP_DURABLE;
30-
}
20+
$connection = new AMQPConnection($config['host'], $config['port'], $config['login'], $config['password'], $config['vhost']);
3121

3222
return new RabbitMQQueue(
3323
$connection,
34-
$config['queue'],
35-
$config['exchange_name'],
36-
$config['exchange_type'],
37-
$config['exchange_flags']
24+
$config
3825
);
3926
}
4027

src/FintechFab/LaravelQueueRabbitMQ/Queue/Jobs/RabbitMQJob.php

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
<?php namespace FintechFab\LaravelQueueRabbitMQ\Queue\Jobs;
22

3-
use AMQPEnvelope;
4-
use AMQPQueue;
53
use Illuminate\Container\Container;
64
use Illuminate\Queue\Jobs\Job;
5+
use PhpAmqpLib\Channel\AMQPChannel;
6+
use PhpAmqpLib\Message\AMQPMessage;
7+
use Queue;
78

89
class RabbitMQJob extends Job
910
{
1011

12+
protected $channel;
1113
protected $queue;
12-
protected $envelope;
14+
protected $message;
1315

1416
public function __construct(
1517
Container $container,
16-
AMQPQueue $queue,
17-
AMQPEnvelope $envelope
18+
AMQPChannel $channel,
19+
$queue,
20+
AMQPMessage $message
1821
)
1922
{
2023
$this->container = $container;
24+
$this->channel = $channel;
2125
$this->queue = $queue;
22-
$this->envelope = $envelope;
26+
$this->message = $message;
2327
}
2428

2529
/**
@@ -29,7 +33,7 @@ public function __construct(
2933
*/
3034
public function fire()
3135
{
32-
$this->resolveAndFire(json_decode($this->envelope->getBody(), true));
36+
$this->resolveAndFire(json_decode($this->message->body, true));
3337
}
3438

3539
/**
@@ -39,7 +43,7 @@ public function fire()
3943
*/
4044
public function getRawBody()
4145
{
42-
return $this->envelope->getBody();
46+
return $this->message->body;
4347
}
4448

4549
/**
@@ -50,7 +54,18 @@ public function getRawBody()
5054
public function delete()
5155
{
5256
parent::delete();
53-
$this->queue->ack($this->envelope->getDeliveryTag());
57+
58+
$this->channel->basic_ack($this->message->delivery_info['delivery_tag']);
59+
}
60+
61+
/**
62+
* Get queue name
63+
*
64+
* @return string
65+
*/
66+
public function getQueue()
67+
{
68+
return $this->queue;
5469
}
5570

5671
/**
@@ -64,7 +79,7 @@ public function release($delay = 0)
6479
{
6580
$this->delete();
6681

67-
$body = $this->envelope->getBody();
82+
$body = $this->message->body;
6883
$body = json_decode($body, true);
6984

7085
$attempts = $this->attempts();
@@ -90,7 +105,7 @@ public function release($delay = 0)
90105
*/
91106
public function attempts()
92107
{
93-
$body = json_decode($this->envelope->getBody(), true);
108+
$body = json_decode($this->message->body, true);
94109

95110
return isset($body['data']['attempts']) ? (int)$body['data']['attempts'] : 0;
96111
}
@@ -102,7 +117,7 @@ public function attempts()
102117
*/
103118
public function getJobId()
104119
{
105-
return $this->envelope->getMessageId();
120+
return $this->message->body;
106121
}
107122

108123
/**

0 commit comments

Comments
 (0)