| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Str;
- use App\Http\Api\Mq;
- use App\Models\Discussion;
- use App\Http\Resources\DiscussionResource;
- use App\Models\SentPr;
- use App\Http\Resources\SentPrResource;
- use App\Services\RabbitMQService;
- class TestMq extends Command
- {
- /**
- * The name and signature of the console command.
- * php artisan test:mq
- * @var string
- */
- protected $signature = 'test:mq {--discussion=} {--pr=}';
- protected $publish;
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = 'Command description';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return int
- */
- public function handle()
- {
- if (\App\Tools\Tools::isStop()) {
- return 0;
- }
- $publish = app(RabbitMQService::class);
- $this->publish = $publish;
- $this->publish->publishMessage('ai_translate', ['text' => 'hello']);
- Mq::publish('hello', ['hello world']);
- $discussion = $this->option('discussion');
- if ($discussion && Str::isUuid($discussion)) {
- Mq::publish('discussion', new DiscussionResource(Discussion::find($discussion)));
- }
- $pr = $this->option('pr');
- if ($pr && Str::isUuid($pr)) {
- Mq::publish('suggestion', new SentPrResource(SentPr::where('uid', $pr)->first()));
- }
- return 0;
- }
- }
|