MqEmpty.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Http\Api\Mq;
  4. use App\Tools\Tools;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\Log;
  7. class MqEmpty extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'mq:empty';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command description';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. if (Tools::isStop()) {
  38. return 0;
  39. }
  40. $exchange = 'router';
  41. $queue = 'ai_translate';
  42. $this->info(" [*] Waiting for {$queue}. To exit press CTRL+C");
  43. Log::debug("mq worker {$queue} start.");
  44. Mq::worker(
  45. $exchange,
  46. $queue,
  47. function ($message) {
  48. $this->info('new message');
  49. sleep(3);
  50. return 0;
  51. }
  52. );
  53. return 0;
  54. }
  55. }