##send
send($queue, $msg." ". date("Y-m-d H:i:s"));
// sleep(1);
// }
// } catch(StompException $e) {
// die('Connection failed: ' . $e->getMessage());
// }class mqsend
{
public static $config = array(
'url' => 'tcp://127.0.0.1:61613',
'id' => '',
'pswd' => '',
'queue' => 'sms',
'enable' => TRUE
);public function sendMq()
{
$item = '{ "mobile":"1300000", "content":"您好!您的验证码为112233", "callback":"demo.xx.com/sms/callback" }';
try {
// die(self::$config['url']);
$stomp = new Stomp(self::$config['url']);
// while (true) {$stomp->send(self::$config['queue'], $item." ". date("Y-m-d H:i:s"));
// sleep(1);
// }
} catch(StompException $e) {
die('Connection failed: ' . $e->getMessage());
}
}}
$obj = new mqsend();
$obj->sendMq();
##get
subscribe($queue);
// while (true) {
// if ($stomp->hasFrame()) {
// $frame = $stomp->readFrame();
// if ($frame != NULL) {
// print "Received: " . $frame->body . " - time now is " . date("Y-m-d H:i:s"). "\n";
// $stomp->ack($frame);
// }
// } else {
// print "No frames to read\n";
// }
// }
// } catch(StompException $e) {
// die('Connection failed: ' . $e->getMessage());
// }
class mqget
{
public static $config = array(
'url' => 'tcp://127.0.0.1:61613',
'id' => '',
'pswd' => '',
'queue' => 'sms',
'enable' => TRUE
);public function getMq(){
try {
$stomp = new Stomp(self::$config['url']);
$stomp->subscribe(self::$config['queue']);
while (true) {
if ($stomp->hasFrame()) {
$frame = $stomp->readFrame();
if ($frame != NULL) {
print "Received: " . $frame->body . " - time now is " . date("Y-m-d H:i:s"). "\n";
$stomp->ack($frame);
}
} else {
print "No frames to read\n";
}
}
} catch(StompException $e) {
die('Connection failed: ' . $e->getMessage());
}
}}
$obj = new mqget();
$obj->getMq();
##注意项目
1,每个请求方式对应的端口不一样,这块要注意下
"openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=10485760000"/>
##报错
2018-06-15 14:40:56,265 | WARN | Transport Connection to: tcp://14.20.89.57:4553 failed: java.io.IOException: Frame size of 1 GB larger than max allowed 100 MB | org.apache.activemq.broker.TransportConnection.Transport | ActiveMQ Transport: tcp:///14.20.89.57:4553@61616修改配置文件apache-activemq-5.9.0-bin\apache-activemq-5.9.0\conf\activemq.xml 把maxFrameSize 调大一些.