123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- declare(strict_types=1);
- namespace App\Command;
- use App\Amqp\Producer\DelayDirectProducer;
- use App\Amqp\Producer\MqProducer;
- use Hyperf\Amqp\Producer;
- use Hyperf\Command\Command as HyperfCommand;
- use Hyperf\Command\Annotation\Command;
- use Hyperf\Context\ApplicationContext as ContextApplicationContext;
- use Hyperf\Utils\ApplicationContext;
- use Psr\Container\ContainerInterface;
- /**
- * @Command
- */
- #[Command]
- class DelayCommand extends HyperfCommand
- {
- /**
- * @var ContainerInterface
- */
- protected $container;
- public function __construct(ContainerInterface $container)
- {
- $this->container = $container;
- parent::__construct('demo:queue');
- }
- public function configure()
- {
- parent::configure();
- $this->setDescription('生产消息发布 ');
- }
- public function handle()
- {
- for ($i = 0; $i < 100; $i++) {
- $data = [
- "ss" => 122,
- "num" => $i,
- "number" => mt_rand(1111, 9999),
- "time" => time(),
- ];
- $message = new MqProducer($data);
- $producer = ContextApplicationContext::getContainer()->get(Producer::class);
- $ret = $producer->produce($message);
- }
- print_r($ret);
- $this->line('Hello Hyperf!', 'info');
- exit();
- }
- }
|