Skip to content

Commit 0aa6119

Browse files
committed
Add Default option to set Priority
1 parent 8c43b67 commit 0aa6119

File tree

4 files changed

+13
-7
lines changed

4 files changed

+13
-7
lines changed

src/Console/ConsumeCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class ConsumeCommand extends WorkCommand
2525
{--tries=1 : Number of times to attempt a job before logging it failed}
2626
{--rest=0 : Number of seconds to rest between jobs}
2727
28-
{--max-priority=4}
28+
{--max-priority}
2929
{--consumer-tag}
3030
{--prefetch-size=0}
3131
{--prefetch-count=1000}

src/Console/QueueDeclareCommand.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class QueueDeclareCommand extends Command
1212
{name : The name of the queue to declare}
1313
{connection=rabbitmq : The name of the queue connection to use}
1414
{--durable=1}
15-
{--max-priority=4}
15+
{--max-priority}
1616
{--auto-delete=0}';
1717

1818
protected $description = 'Declare queue';
@@ -32,10 +32,13 @@ public function handle(RabbitMQConnector $connector): void
3232

3333
return;
3434
}
35+
36+
$arguments = [];
3537
$maxPriority = (int) $this->option('max-priority');
36-
$arguments = [
37-
'x-max-priority' => $maxPriority,
38-
];
38+
if ($maxPriority) {
39+
$arguments['x-max-priority'] = $maxPriority;
40+
}
41+
3942
$queue->declareQueue(
4043
$this->argument('name'),
4144
(bool) $this->option('durable'),

src/Consumer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ public function daemon($connectionName, $queue, WorkerOptions $options)
9191
);
9292

9393
$jobClass = $connection->getJobClass();
94+
$arguments = [];
95+
if ($this->maxPriority) {
96+
$arguments['priority'] = ['I', $this->maxPriority];
97+
}
9498

9599
$this->channel->basic_consume(
96100
$queue,
@@ -123,7 +127,7 @@ function (AMQPMessage $message) use ($connection, $options, $connectionName, $qu
123127
}
124128
},
125129
null,
126-
['priority' => ['I', $this->maxPriority]]
130+
$arguments
127131
);
128132

129133
while ($this->channel->is_consuming()) {

src/Queue/RabbitMQQueue.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,6 @@ protected function createMessage($payload, int $attempts = 0): array
530530
$properties = [
531531
'content_type' => 'application/json',
532532
'delivery_mode' => AMQPMessage::DELIVERY_MODE_PERSISTENT,
533-
'priority' => 1,
534533
];
535534

536535
$currentPayload = json_decode($payload, true, 512);

0 commit comments

Comments
 (0)