Fixed amqp consumer does not works when using fanout exchange. (#2820)

* amqp 类型fanout情况下 routing_key不存在的情况

* Update CHANGELOG-2.0.md

Co-authored-by: 李铭昕 <715557344@qq.com>
This commit is contained in:
武杰 2020-11-17 16:02:10 +08:00 committed by GitHub
parent d5f7d289ad
commit 6a4fbc8044
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 0 deletions

View File

@ -1,5 +1,9 @@
# v2.0.20 - TBD # v2.0.20 - TBD
## Fixed
- [#2820](https://github.com/hyperf/hyperf/pull/2820) Fixed amqp consumer does not works when using fanout exchange.
# v2.0.19 - 2020-11-17 # v2.0.19 - 2020-11-17
## Added ## Added

View File

@ -18,6 +18,7 @@ use Hyperf\Amqp\Event\WaitTimeout;
use Hyperf\Amqp\Exception\MessageException; use Hyperf\Amqp\Exception\MessageException;
use Hyperf\Amqp\Message\ConsumerMessageInterface; use Hyperf\Amqp\Message\ConsumerMessageInterface;
use Hyperf\Amqp\Message\MessageInterface; use Hyperf\Amqp\Message\MessageInterface;
use Hyperf\Amqp\Message\Type;
use Hyperf\Amqp\Pool\PoolFactory; use Hyperf\Amqp\Pool\PoolFactory;
use Hyperf\Contract\ConfigInterface; use Hyperf\Contract\ConfigInterface;
use Hyperf\ExceptionHandler\Formatter\FormatterInterface; use Hyperf\ExceptionHandler\Formatter\FormatterInterface;
@ -132,6 +133,10 @@ class Consumer extends Builder
$channel->queue_bind($message->getQueue(), $message->getExchange(), $routingKey); $channel->queue_bind($message->getQueue(), $message->getExchange(), $routingKey);
} }
if (empty($routineKeys) && $message->getType() === Type::FANOUT) {
$channel->queue_bind($message->getQueue(), $message->getExchange());
}
if (is_array($qos = $message->getQos())) { if (is_array($qos = $message->getQos())) {
$size = $qos['prefetch_size'] ?? null; $size = $qos['prefetch_size'] ?? null;
$count = $qos['prefetch_count'] ?? null; $count = $qos['prefetch_count'] ?? null;