我用這個(gè)官方大大這個(gè)月發(fā)的demo一直提示我連接失敗
https://wenda.workerman.net/question/5741
這個(gè)是我設(shè)置的參數(shù)
我用阿里官方提供的stomp demo是可以連上的
另外官方大大是否可以提供個(gè)阿里云 消息隊(duì)列 RocketMQ 版 的workman demo 官方只提供了http的 tcp暫時(shí)沒有
https://help.aliyun.com/document_detail/114448.html?spm=a2c4g.11186623.6.589.4a107e80jcLzas
那個(gè)問題解決了
是主題不存在導(dǎo)致的 現(xiàn)在 一啟動(dòng)就斷開連接
代碼示例
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Workerman\Worker;
use Workerman\Stomp\Client;
$worker = new Worker();
$worker->onWorkerStart = function(){
$accessKey = "x";
$accessSecret = "x";
$consumerGroupId = "DEFAULT_GROUP";
//iotInstanceId:購買的實(shí)例請?zhí)顚憣?shí)例ID,公共實(shí)例請?zhí)羁兆址?"。
$iotInstanceId = "";
$timeStamp = round(microtime(true) * 1000);
//簽名方法:支持hmacmd5,hmacsha1和hmacsha256。
$signMethod = "hmacsha1";
$clientId = "client-1";
//userName組裝方法,請參見AMQP客戶端接入說明文檔。
//若使用二進(jìn)制傳輸,則userName需要添加encode=base64參數(shù),服務(wù)端會(huì)將消息體base64編碼后再推送。具體添加方法請參見下一章節(jié)“二進(jìn)制消息體說明”。
$userName = $clientId . "|authMode=aksign"
. ",signMethod=" . $signMethod
. ",timestamp=" . $timeStamp
. ",authId=" . $accessKey
. ",iotInstanceId=" . $iotInstanceId
. ",consumerGroupId=" . $consumerGroupId
. "|";
$signContent = "authId=" . $accessKey . "×tamp=" . $timeStamp;
//計(jì)算簽名,password組裝方法,請參見AMQP客戶端接入說明文檔。
$password = base64_encode(hash_hmac("sha1", $signContent, $accessSecret, $raw_output = TRUE));
$client = new Client('stomp://xxx.iot-amqp.cn-shanghai.aliyuncs.com:61614', array(
'debug' => true,
'login' => $userName,
'passcode' => $password,
'heart_beat' => 30000,
'ssl' => ['verify_peer' => true, 'verify_peer_name' => false],
));
$client->onConnect = function(Client $client) {
$client->subscribe('/topic/#', function(Client $client, $data) {
var_export($data);
});
};
$client->onError = function ($e) {
echo $e;
};
$client->connect();
};
Worker::runAll();
只要有消息過來 就直接斷開了 然后重連