TestMq.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Str;
  5. use App\Http\Api\Mq;
  6. use App\Models\Discussion;
  7. use App\Http\Resources\DiscussionResource;
  8. use App\Models\SentPr;
  9. use App\Http\Resources\SentPrResource;
  10. use App\Services\RabbitMQService;
  11. class TestMq extends Command
  12. {
  13. /**
  14. * The name and signature of the console command.
  15. * php artisan test:mq
  16. * @var string
  17. */
  18. protected $signature = 'test:mq {--discussion=} {--pr=}';
  19. protected $publish;
  20. /**
  21. * The console command description.
  22. *
  23. * @var string
  24. */
  25. protected $description = 'Command description';
  26. /**
  27. * Create a new command instance.
  28. *
  29. * @return void
  30. */
  31. public function __construct(RabbitMQService $publish)
  32. {
  33. $this->publish = $publish;
  34. parent::__construct();
  35. }
  36. /**
  37. * Execute the console command.
  38. *
  39. * @return int
  40. */
  41. public function handle()
  42. {
  43. if (\App\Tools\Tools::isStop()) {
  44. return 0;
  45. }
  46. $this->publish->publishMessage('ai_translate', ['text' => 'hello']);
  47. Mq::publish('hello', ['hello world']);
  48. $discussion = $this->option('discussion');
  49. if ($discussion && Str::isUuid($discussion)) {
  50. Mq::publish('discussion', new DiscussionResource(Discussion::find($discussion)));
  51. }
  52. $pr = $this->option('pr');
  53. if ($pr && Str::isUuid($pr)) {
  54. Mq::publish('suggestion', new SentPrResource(SentPr::where('uid', $pr)->first()));
  55. }
  56. return 0;
  57. }
  58. }