Skip to content

Commit 205b6ac

Browse files
committed
Merge branch 'upgrade-4.1'
Conflicts: README.md composer.json
2 parents 392c6d7 + b741ef5 commit 205b6ac

File tree

6 files changed

+111
-37
lines changed

6 files changed

+111
-37
lines changed

README.md

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ RabbitMQ driver for Laravel
55

66
Require this package in your composer.json and run composer update:
77

8-
"fintech-fab/laravel-queue-rabbitmq": "4.0"
8+
"fintech-fab/laravel-queue-rabbitmq": "4.1"
99

1010
or run:
1111

@@ -20,31 +20,44 @@ After composer update is finished you need to add ServiceProvider to your `provi
2020
now you are able to configure your connections in queue.php:
2121

2222
return array(
23-
24-
'default' => 'rabbitmq',
25-
26-
'connections' => array(
27-
28-
'rabbitmq' => array(
29-
'driver' => 'rabbitmq',
30-
31-
'host' => '',
32-
'port' => '',
33-
34-
'vhost' => '',
35-
'login' => '',
36-
'password' => '',
37-
38-
'queue' => '', // name of the default queue
39-
'exchange_name' => '', // name of the exchange
40-
),
41-
42-
),
43-
23+
24+
'default' => 'rabbitmq',
25+
26+
'connections' => array(
27+
28+
'rabbitmq' => array(
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+
49+
50+
),
51+
52+
),
53+
4454
);
4555

4656
You can also find these examples in src/examples folder.
4757

58+
####Usage
59+
Once you completed the configuration you can use Laravel Queue API. If you used other queue drivers you do not need to change anything else. If you do not know how to use Queue API, please refer to the official Laravel documentation: http://laravel.com/docs/queues
60+
4861
####PHPUnit
4962
Unit tests will be provided soon.
5063

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "fintech-fab/laravel-queue-rabbitmq",
3-
"version": "4.0",
3+
"version": "4.1",
44
"description": "RabbitMQ driver for Laravel Queue",
55
"license": "Apache-2.0",
66
"authors": [
@@ -11,8 +11,8 @@
1111
],
1212
"require": {
1313
"php": ">=5.3.0",
14-
"illuminate/support": "4.0.x",
15-
"illuminate/queue": "4.0.*@dev"
14+
"illuminate/support": "4.1.*@dev",
15+
"illuminate/queue": "4.1.*@dev"
1616
},
1717
"suggest": {
1818
"ext-amqp": "PECL extension for the AMQP protocol - this is preferred"

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,20 @@ public function connect(array $config)
2121
$connection = new AMQPConnection($config);
2222
$connection->connect();
2323

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+
}
31+
2432
return new RabbitMQQueue(
2533
$connection,
2634
$config['queue'],
27-
$config['exchange_name']
35+
$config['exchange_name'],
36+
$config['exchange_type'],
37+
$config['exchange_flags']
2838
);
2939
}
3040
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ public function fire()
2828
$this->resolveAndFire(json_decode($this->envelope->getBody(), true));
2929
}
3030

31+
/**
32+
* Get the raw body string for the job.
33+
*
34+
* @return string
35+
*/
36+
public function getRawBody()
37+
{
38+
return $this->envelope->getBody();
39+
}
40+
3141
/**
3242
* Delete the job from the queue.
3343
*

src/FintechFab/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,24 @@ class RabbitMQQueue extends Queue implements QueueInterface
1818
protected $exchange;
1919
protected $default_queue;
2020
protected $exchange_name;
21+
protected $exchange_type;
22+
protected $exchange_flags;
2123

2224
/**
2325
* @param AMQPConnection $amqpConnection
2426
* @param string $default_queue
2527
* @param string $exchange_name
2628
*
27-
* @internal param string $routing_key
29+
* @param mixed $exchange_type
30+
* @param mixed $exchange_flags
2831
*/
29-
public function __construct(AMQPConnection $amqpConnection, $default_queue, $exchange_name)
32+
public function __construct(AMQPConnection $amqpConnection, $default_queue, $exchange_name, $exchange_type, $exchange_flags)
3033
{
3134
$this->connection = $amqpConnection;
3235
$this->default_queue = $default_queue;
3336
$this->exchange_name = $exchange_name;
37+
$this->exchange_type = $exchange_type;
38+
$this->exchange_flags = $exchange_flags;
3439
$this->channel = $this->getChannel();
3540
$this->exchange = $this->getExchange($this->channel);
3641
}
@@ -62,6 +67,31 @@ public function push($job, $data = '', $queue = null)
6267
return $job;
6368
}
6469

70+
/**
71+
* Push a raw payload onto the queue.
72+
*
73+
* @param string $payload
74+
* @param string $queue
75+
* @param array $options
76+
*
77+
* @throws \AMQPException
78+
* @return mixed
79+
*/
80+
public function pushRaw($payload, $queue = null, array $options = array())
81+
{
82+
// get queue
83+
$queue = $this->declareQueue($queue);
84+
85+
// push task to a queue
86+
$job = $this->exchange->publish($payload, $queue->getName());
87+
88+
if (!$job) {
89+
throw new AMQPException('Could not push job to a queue');
90+
}
91+
92+
return $job;
93+
}
94+
6595
/**
6696
* Push a new job onto the queue after a delay.
6797
*
@@ -139,7 +169,8 @@ public function getExchange(AMQPChannel $channel)
139169
{
140170
$exchange = new AMQPExchange($channel);
141171
$exchange->setName($this->exchange_name);
142-
$exchange->setType(AMQP_EX_TYPE_DIRECT);
172+
$exchange->setFlags($this->exchange_flags);
173+
$exchange->setType($this->exchange_type);
143174
$exchange->declareExchange();
144175

145176
return $exchange;

src/examples/queue.php

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,27 @@
1212
'connections' => array(
1313

1414
'rabbitmq' => array(
15-
'driver' => 'rabbitmq',
15+
'driver' => 'rabbitmq',
1616

17-
'host' => '',
18-
'port' => '',
17+
'host' => '',
18+
'port' => '',
19+
20+
'vhost' => '',
21+
'login' => '',
22+
'password' => '',
23+
24+
'queue' => '', // name of the default queue
25+
26+
'exchange_name' => '', // name of the exchange
27+
28+
// Type of your exchange
29+
// Can be AMQP_EX_TYPE_DIRECT or AMQP_EX_TYPE_FANOUT
30+
// see documentation for more info
31+
// http://www.rabbitmq.com/tutorials/amqp-concepts.html
32+
'exchange_type' => AMQP_EX_TYPE_DIRECT,
33+
'exchange_flags' => AMQP_DURABLE,
1934

20-
'vhost' => '',
21-
'login' => '',
22-
'password' => '',
2335

24-
'queue' => '', // name of the default queue
25-
'exchange_name' => '', // name of the exchange
2636
),
2737

2838
),

0 commit comments

Comments
 (0)