1. Go to this page and download the library: Download lsys/mqs 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/ */
lsys / mqs example snippets
use LSYS\MQS\Sender\SendCall;
use LSYS\MQS\MQSender;
use LSYS\MQS\DataCode\Simple;
use LSYS\DI\SingletonCallback;
(function(){
//你的具体的消息队列服务器,这里使用REDIS
$redismq=\LSYS\Redis\DI::get()->redisMQ();
return new MQSender(new SendCall(function($topic,$msg,$dealy)use($redismq){
//根据你实际的MQ服务器进行发送
return $redismq->push($topic,$msg,$dealy);
}),new Simple("MQ"));
}));
});
//具体的调用部分
var_dump(\LSYS\MQS\DI::get()->mq_sender()->send(user_runer1::class,[uniqid(),uniqid()]));
use LSYS\MQS\DataCode\Simple;
use LSYS\MQS\MQListen;
h ($topics as $k=>$topic){
$listen[$topic]=new MQListen(new Simple($topic));
switch ($topic){
case 'MQ':
$listen[$topic]->set_runer($topic,[user1::class,user2::class]);//设置指定主题的执行类
break;
default: unset($topics[$k]);
}
}
$redismq=\LSYS\Redis\DI::get()->redisMQ();//得到REDIS MQ对象 在redis上实现
while (true){
$data=$redismq->pop($topics,FALSE,$ack);//从MQ里取消息
if(count($data)!=2)continue;
list($topic,$msg)=$data;
$result=$listen[$topic]->exec($topic, $msg);//执行消费,上面绑定的,执行错误返回异常对象
$error=false;
foreach ($result as $v){
if ($v instanceof Exception)$error=true;
}
if(!$error)$redismq->ack($topics,$ack,$data);//未发送异常,确认消费
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.