Skip to content
This repository was archived by the owner on Sep 3, 2020. It is now read-only.

Commit e7fa181

Browse files
committed
Fixes Correlation ID support, adds ability to set arbitrary Correlation IDs
1 parent 97fde57 commit e7fa181

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,11 +132,26 @@ private function setAttempts($count)
132132
/**
133133
* Get the job identifier.
134134
*
135-
* @return string
135+
* @return string|false
136136
*/
137137
public function getJobId()
138138
{
139-
return $this->message->get('correlation_id');
139+
if ($this->message->has('correlation_id') === true) {
140+
return $this->message->get('correlation_id');
141+
}
142+
143+
return false;
140144
}
141145

146+
/**
147+
* Sets the job identifier.
148+
*
149+
* @param string $id
150+
*
151+
* @return void
152+
*/
153+
public function setJobId($id)
154+
{
155+
$this->connection->setCorrelationid($id);
156+
}
142157
}

src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ class RabbitMQQueue extends Queue implements QueueContract
3333
*/
3434
private $attempts;
3535

36+
/**
37+
* @var string
38+
*/
39+
private $correlationId;
40+
3641
/**
3742
* @param AMQPStreamConnection $amqpConnection
3843
* @param array $config
@@ -93,7 +98,7 @@ public function pushRaw($payload, $queue = null, array $options = [])
9398

9499
// push job to a queue
95100
$message = new AMQPMessage($payload, $headers);
96-
$this->message->set('correlation_id', uniqid());
101+
$message->set('correlation_id', $this->correlationId ?: uniqid());
97102

98103
// push task to a queue
99104
$this->channel->basic_publish($message, $exchange, $queue);
@@ -249,4 +254,16 @@ public function setAttempts($count)
249254
{
250255
$this->attempts = $count;
251256
}
252-
}
257+
258+
/**
259+
* Sets the correlation id for a message to be published
260+
*
261+
* @param string $id
262+
*
263+
* @return void
264+
*/
265+
public function setCorrelationId($id)
266+
{
267+
$this->correlationId = $id;
268+
}
269+
}

0 commit comments

Comments
 (0)