问一个rabbitmq的问题 没有加入队列和消费

框架hyperf 按照插件composer require hyperf/amqp

问一个rabbitmq的问题 没有加入队列和消费

问一个rabbitmq的问题 没有加入队列和消费

问一个rabbitmq的问题 没有加入队列和消费

问一个rabbitmq的问题 没有加入队列和消费

问一个rabbitmq的问题 没有加入队列和消费

问一个rabbitmq的问题 没有加入队列和消费
有哪位大神知道是为啥吗求解,第一次玩rabbitmq 方法都试完了看日志也不报错

本作品采用《CC 协议》,转载必须注明作者和本文链接
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
讨论数量: 10

消费者那里注解不用写两次 如果你是php8用原生的注解就好了 贴的信息太少其他的没看出啥问题 可以先按照文档写个demo试一下正不正常

2年前 评论
lijizheng (楼主) 2年前
kolin (作者) 2年前

file@kolin 两个注释是只需要一个吗?

2年前 评论
kolin 2年前
lijizheng (作者) (楼主) 2年前

<?php

declare(strict_types=1);

namespace App\Amqp\Consumer;

use App\Model\Customer; use App\Model\CustomerAddress; use Hyperf\Amqp\Result; use Hyperf\Amqp\Annotation\Consumer; use Hyperf\Amqp\Message\ConsumerMessage; use Hyperf\DbConnection\Db; use PhpAmqpLib\Message\AMQPMessage; use Hyperf\Logger\LoggerFactory; use Ramsey\Uuid\Uuid;

/**

  • @Consumer(exchange="customer", routingKey="customer", queue="customer", name="CustomerConsumer", nums=1)

  • / class CustomerConsumer extends ConsumerMessage { private $logger;

    public function __construct(LoggerFactory $loggerFactory) {

      $this->logger = $loggerFactory->get('rabbitmq');

    }

    public function consumeMessage($data, AMQPMessage $message): string {

      Db::beginTransaction();
      try {
          if(!Customer::query()->where('ios_guid',$data['ios_guid'])->exists()){
              $customer=new Customer();
              $customer->Guid=Uuid::uuid4()->getHex();
              $customer->ios_guid=$data['ios_guid'];
              $customer->Name=$data['name'];
              $customer->Email=$data['email'];
              $customer->Phone=$data['phone'];
              $customer->company_name=$data['company_name'];
              $customer->equipment_no=$data['equipment_no'];
              $customer->tax_number=$data['tax_number'];
              $customer->selling_price=$data['selling_price'];
              $customer->remark=$data['remark'];
              $customer->is_ipad=$data['is_ipad']??1;
              $customer->save();
          }else{
              Customer::query()
                  ->where('ios_guid',$data['ios_guid'])
                  ->update([
                      'ios_guid'=>$data['ios_guid'],
                      'Name'=>$data['name'],
                      'Email'=>$data['email'],
                      'Phone'=>$data['phone'],
                      'company_name'=>$data['company_name'],
                      'equipment_no'=>$data['equipment_no'],
                      'tax_number'=>$data['tax_number'],
                      'selling_price'=>$data['selling_price'],
                      'remark'=>$data['remark'],
                      'is_ipad'=>$data['is_ipad']??1,
                  ]);
          }
          if($customer){
              if(!CustomerAddress::query()
                  ->where('CustomerGuid',$customer->Guid)
                  ->exists()){
                  $customeraddress=new CustomerAddress();
                  $customeraddress->Guid=Uuid::uuid4()->getHex();
                  $customeraddress->CustomerGuid=$customer->Guid;
                  $customeraddress->Address1=$data['address'];
                  $customeraddress->City=$data['city'];
                  $customeraddress->Province=$data['province'];
                  $customeraddress->CreateTime=date('Y-m-d H:i:s',time());
                  $customeraddress->save();
              }else{
                  CustomerAddress::query()
                      ->where('CustomerGuid',$customer->Guid)
                      ->update([
                          'CustomerGuid'=>$customer->Guid,
                          'Address1'=>$data['address'],
                          'City'=>$data['city'],
                          'Province'=>$data['province'],
                          'CreateTime'=>date('Y-m-d H:i:s',time())
                      ]);
              }
          }
          Db::commit();
          $this->logger->info('Received and processed message:成功');
          return Result::ACK;
      }catch (\Exception $exception){
          Db::rollBack();
          $this->logger->info('Received and processed message:'.$exception->getMessage());
          return Result::DROP;
      }

    } } @kolin 这样还是不行

2年前 评论
lijizheng (作者) (楼主) 2年前
kolin 2年前
lijizheng (作者) (楼主) 2年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!