From f8711db07e36dc9351a6f95e5a6c9cc7d90467c0 Mon Sep 17 00:00:00 2001 From: avatarofhope2 Date: Fri, 26 May 2023 14:22:39 -0600 Subject: [PATCH] Add the ability for AmqpContext to utilize the randomly generated queue names by updating the queue name. This requires queue-interop/amqp-interop to allow changing setting the queue name, though. --- AmqpContext.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/AmqpContext.php b/AmqpContext.php index 3456965..4edbc39 100644 --- a/AmqpContext.php +++ b/AmqpContext.php @@ -162,7 +162,7 @@ public function deleteTopic(InteropAmqpTopic $topic): void public function declareQueue(InteropAmqpQueue $queue): int { - list(, $messageCount) = $this->getLibChannel()->queue_declare( + list($queueName, $messageCount) = $this->getLibChannel()->queue_declare( $queue->getQueueName(), (bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_PASSIVE), (bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_DURABLE), @@ -171,6 +171,16 @@ public function declareQueue(InteropAmqpQueue $queue): int (bool) ($queue->getFlags() & InteropAmqpQueue::FLAG_NOWAIT), $queue->getArguments() ? new AMQPTable($queue->getArguments()) : null ); + /* + * The queue name could have been entered as empty string, and come out in a format similar to: + * amq.gen-LQTh8IdojOCrvOnEuFog8w. The format of the automatically generated name is not in the spec, but the + * automatic generation is part of the amqp specification: + * https://www.rabbitmq.com/resources/specs/amqp0-9-1.xml (see methods declare and declare-ok) + */ + if ($queueName) { + $queue->setQueueName($queueName); + } + return $messageCount ?? 0; }