# lmq **Repository Path**: differentman/lmq ## Basic Information - **Project Name**: lmq - **Description**: [已迁移至:https://github.com/shanliu/lmq] 消息队列封装,使消息队列使用保持一致,从而系统在使用消息队列时无需为切换消息队列系统而修改业务逻辑代码 已支持REDIS,kafka 阿里云MQS Gearman接口 - **Primary Language**: PHP - **License**: Not specified - **Default Branch**: master - **Homepage**: https://github.com/shanliu/lmq - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2018-05-29 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 消息队列封装 >封装消息队列,实现对外使用使保持一致接口 >Gearman kafka redis 为非可靠消息[当消息处理失败不会再次发起] stomp mqs 为可靠消息[消息处理失败会再次发起] 使用示例: 1. 实现消息体接口 ``` class omsg extends \LSYS\MQ\Message{ protected $_order_id; protected $_product_id; public function set_order_id($order_id){ $this->_order_id=$order_id; return $this; } public function set_product_id($product_id){ $this->_product_id=$product_id; return $this; } public function serialize () {//需要实现方法 return json_encode(array($this->_order_id,$this->_product_id)); } public function unserialize ($serialized) {//需要实现方法 list($this->_order_id,$this->_product_id)=json_decode($serialized,true); } public function exec(){//接收到消息时候执行的代码 print_r($this->_order_id); print_r($this->_product_id); } } ``` 2. 消息生产 ``` \LSYS\MQ::instance()->push(omsg::factory()->set_order_id(1)->set_product_id(1)); ``` 3. 消息处理 ``` //为cli运行 define('LSYS_MQ_LIMIT',100);//执行多少次后重启 define('LSYS_MQ_USER','nobody');//执行用户 require __DIR__.'/../src/unix_utils.php'; require_once __DIR__."/Bootstarp.php"; require_once __DIR__."/msq.php"; ini_set('memory_limit','32M'); MQ::instance()->listen(); ``` 备注: > aliyun 消息处理参见 aliyun.php