美文网首页
hyperf3.0--amqp 投递者简单复用

hyperf3.0--amqp 投递者简单复用

作者: geeooooz | 来源:发表于2023-06-26 18:12 被阅读0次

    Index控制器中:

    <?php
    
    declare(strict_types=1);
    /**
     * This file is part of Hyperf.
     *
     * @link     https://www.hyperf.io
     * @document https://hyperf.wiki
     * @contact  group@hyperf.io
     * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
     */
    namespace App\Controller;
    use Hyperf\Context\ApplicationContext;
    use App\Amqp\Producer\DemoProducer;
    use Hyperf\Amqp\Producer;
    use Hyperf\Di\Annotation\Inject;
    
    class IndexController extends AbstractController
    {
        #[Inject]
        protected Producer $producer;
    
        public function index()
        {
            $message = new DemoProducer(110);
            $producer = ApplicationContext::getContainer()->get(Producer::class);
            $result = $producer->produce($message);
            var_dump($result);
        }
    }
    
    

    投递类修改:

    <?php
    
    declare(strict_types=1);
    
    namespace App\Amqp\Producer;
    
    use Hyperf\Amqp\Message\ProducerMessage;
    
    class DemoProducer extends ProducerMessage
    {
        public function __construct($data,$setting)
        {
            $this->setExchange($setting['exchange']);
            $this->setRoutingKey($setting['routingKey']);
            $this->payload = $data;
        }
    }
    
    

    相关文章

      网友评论

          本文标题:hyperf3.0--amqp 投递者简单复用

          本文链接:https://www.haomeiwen.com/subject/dxkgydtx.html