diff --git a/CHANGELOG-2.0.md b/CHANGELOG-2.0.md index d3b6ed60a..a60dbf14a 100644 --- a/CHANGELOG-2.0.md +++ b/CHANGELOG-2.0.md @@ -1,5 +1,9 @@ # 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 ## Added diff --git a/src/amqp/src/Consumer.php b/src/amqp/src/Consumer.php index c8eb6a205..45ef5d2d8 100644 --- a/src/amqp/src/Consumer.php +++ b/src/amqp/src/Consumer.php @@ -18,6 +18,7 @@ use Hyperf\Amqp\Event\WaitTimeout; use Hyperf\Amqp\Exception\MessageException; use Hyperf\Amqp\Message\ConsumerMessageInterface; use Hyperf\Amqp\Message\MessageInterface; +use Hyperf\Amqp\Message\Type; use Hyperf\Amqp\Pool\PoolFactory; use Hyperf\Contract\ConfigInterface; use Hyperf\ExceptionHandler\Formatter\FormatterInterface; @@ -132,6 +133,10 @@ class Consumer extends Builder $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())) { $size = $qos['prefetch_size'] ?? null; $count = $qos['prefetch_count'] ?? null;