composer require lpb/hyperf-rocketmq
php bin/hyperf.php vendor:publish lpb/hyperf-rocketmq
#[Producer(poolName: "default", topic: "test_topic", groupId: "test_group", messageTag: "tMsgKey", properties: ["a" => 1])]
class DemoProducer extends ProducerMessage
{
public function __construct(array $data)
{
// 设置消息内容
$this->setPayload($data);
}
}
#[Consumer(name: "Consumer", poolName: "default", topic: "test_topic", groupId: "test_group", messageTag: "tMsgKey")]
class DemoConsumer extends ConsumerMessage
{
public function consumeMessage(RocketMQMessage $message): void
{
var_dump($message->getMessageId());
var_dump($this->unserialize($message->getMessageBody()));
var_dump($message->getPublishTime());
}
}