TestMq.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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()
  32. {
  33. parent::__construct();
  34. }
  35. /**
  36. * Execute the console command.
  37. *
  38. * @return int
  39. */
  40. public function handle()
  41. {
  42. if (\App\Tools\Tools::isStop()) {
  43. return 0;
  44. }
  45. $publish = app(RabbitMQService::class);
  46. $this->publish = $publish;
  47. $this->publish->publishMessage('ai_translate', ['text' => 'hello']);
  48. Mq::publish('hello', ['hello world']);
  49. $discussion = $this->option('discussion');
  50. if ($discussion && Str::isUuid($discussion)) {
  51. Mq::publish('discussion', new DiscussionResource(Discussion::find($discussion)));
  52. }
  53. $pr = $this->option('pr');
  54. if ($pr && Str::isUuid($pr)) {
  55. Mq::publish('suggestion', new SentPrResource(SentPr::where('uid', $pr)->first()));
  56. }
  57. return 0;
  58. }
  59. }