Skip to content

Commit 71a525a

Browse files
committed
[consumption] fix echange cound not be decalred, no channel.
1 parent fee8fc5 commit 71a525a

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

‎pkg/enqueue/Consumption/QueueConsumer.php‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Enqueue\Consumption;
44

55
use Enqueue\AmqpExt\AmqpConsumer;
6-
use Enqueue\AmqpExt\AmqpContext;
76
use Enqueue\Consumption\Exception\ConsumptionInterruptedException;
87
use Enqueue\Consumption\Exception\InvalidArgumentException;
98
use Enqueue\Consumption\Exception\LogicException;
@@ -146,19 +145,17 @@ public function bind($queue, $processor)
146145
*/
147146
public function consume(ExtensionInterface $runtimeExtension = null)
148147
{
148+
if (empty($this->boundProcessors)) {
149+
throw new \LogicException('There is nothing to consume. It is required to bind something before calling consume method.');
150+
}
151+
149152
/** @var PsrConsumer[] $consumers */
150153
$consumers = [];
151154
/** @var PsrQueue $queue */
152155
foreach ($this->boundProcessors as list($queue, $processor)) {
153156
$consumers[$queue->getQueueName()] = $this->psrContext->createConsumer($queue);
154157
}
155158

156-
foreach ($consumers as $consumer) {
157-
if ($consumer instanceof AmqpConsumer) {
158-
$consumer->basicConsume($this->receiveTimeout, null);
159-
}
160-
}
161-
162159
$extension = $this->extension ?: new ChainExtension([]);
163160
if ($runtimeExtension) {
164161
$extension = new ChainExtension([$extension, $runtimeExtension]);
@@ -170,13 +167,19 @@ public function consume(ExtensionInterface $runtimeExtension = null)
170167
$logger = $context->getLogger() ?: new NullLogger();
171168
$logger->info('Start consuming');
172169

170+
$amqpConsumer = null;
171+
foreach ($consumers as $consumer) {
172+
if ($consumer instanceof AmqpConsumer) {
173+
$consumer->basicConsume($this->receiveTimeout, null);
174+
175+
$amqpConsumer = $consumer;
176+
}
177+
}
178+
173179
while (true) {
174180
try {
175-
if ($this->psrContext instanceof AmqpContext) {
176-
reset($consumers);
177-
/** @var AmqpConsumer $consumer */
178-
$consumer = current($consumers);
179-
$consumer->basicConsume($this->receiveTimeout, function (AmqpMessage $message, AmqpConsumer $consumer) use ($extension, $logger) {
181+
if ($amqpConsumer) {
182+
$amqpConsumer->basicConsume($this->receiveTimeout, function (AmqpMessage $message, AmqpConsumer $consumer) use ($extension, $logger) {
180183
$currentProcessor = null;
181184

182185
/** @var PsrQueue $queue */

0 commit comments

Comments
 (0)