Skip to content

Commit c0b9adb

Browse files
committed
Fixes Correlation ID support, adds ability to set arbitrary Correlation IDs
Conflicts: src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/Jobs/RabbitMQJob.php
1 parent 13981c2 commit c0b9adb

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,26 @@ private function setAttempts($count)
160160
/**
161161
* Get the job identifier.
162162
*
163-
* @return string
163+
* @return string|false
164164
*/
165165
public function getJobId()
166166
{
167-
return $this->message->get('correlation_id');
167+
if ($this->message->has('correlation_id') === true) {
168+
return $this->message->get('correlation_id');
169+
}
170+
171+
return false;
172+
}
173+
174+
/**
175+
* Sets the job identifier.
176+
*
177+
* @param string $id
178+
*
179+
* @return void
180+
*/
181+
public function setJobId($id)
182+
{
183+
$this->connection->setCorrelationid($id);
168184
}
169185
}

src/VladimirYuldashev/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 18 additions & 1 deletion
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);
@@ -250,4 +255,16 @@ public function setAttempts($count)
250255
{
251256
$this->attempts = $count;
252257
}
258+
259+
/**
260+
* Sets the correlation id for a message to be published
261+
*
262+
* @param string $id
263+
*
264+
* @return void
265+
*/
266+
public function setCorrelationId($id)
267+
{
268+
$this->correlationId = $id;
269+
}
253270
}

0 commit comments

Comments
 (0)