TestMq.php 1.6 KB

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