workbunny / webman-rabbitmq

🚀🐇 A PHP implementation of RabbitMQ Client for webman plugin.
https://www.workerman.net/plugin/67
MIT License
23 stars 4 forks source link

关于helpers提供的消息发布方法 #1

Closed jeyfang0110 closed 1 year ago

jeyfang0110 commented 1 year ago

最近在看rabbitmq相关的组件,在尝试使用这个组件时,关于helpers下的两个方法有个疑问,如下

 * 同步生产
 * @param FastBuilder $builder
 * @param string $body
 * @param array|null $headers
 * @param bool $close
 * @return bool
 */
function sync_publish(FastBuilder $builder, string $body, ?array $headers = null, bool $close = false) : bool
{
    $message = $builder->getMessage();
    if(
        ($message->getExchangeType() !== Constants::DELAYED and $headers['x-delay'] ?? 1) or
        ($message->getExchangeType() === Constants::DELAYED and !($headers['x-delay'] ?? 0))
    ){
        throw new WebmanRabbitMQException('Invalid publish. ');
    }
    $message->setBody($body);
    if($headers !== null){
        $message->setHeaders(array_merge($message->getHeaders(), $headers));
    }
    return $builder->syncConnection()->publish($message, $close);
}

若这里$builder是普通队列,则$message的ExchangeType是Constants::DIRECT,当$headers不传递时,默认为null,那这里不是始终抛WebmanRabbitMQException了?

chaz6chez commented 1 year ago

已修复