PHP code example of lpb / hyperf-rocketmq

1. Go to this page and download the library: Download lpb/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/ */

    

lpb / hyperf-rocketmq example snippets


#[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());
    }
}