1. Go to this page and download the library: Download uncleqiu/hyperf-rocketmq library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
declare(strict_types=1);
namespace App\Controller;
use App\Producer\DemoProducer;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Uncleqiu\HyperfRocketMQ\Producer;
#[Controller]
class IndexController extends AbstractController
{
#[Inject(Producer::class)]
protected Producer $producer;
#[RequestMapping("index")]
public function index()
{
$message = new DemoProducer(['a' => 1, 'b' =>2]);
$this->producer->produce($message);
return $this->response->json([]);
}
}