php + activemq 消息中间件

参考链接:

1,php ActiveMQ的安装与使用  : https://www.cnblogs.com/jkko123/p/6684047.html

2,php 通过stomp协议连接ActiveMQ  :https://www.cnblogs.com/jkko123/p/6685728.html

3,php ActiveMQ的发送消息,与处理消息 : https://www.cnblogs.com/jkko123/p/6685902.html

stomp-php / stomp-php

   github: https://github.com/stomp-php/stomp-php

composer 安装stomp 扩展 

1),composer.json 添加

"require": {
    "stomp-php/stomp-php": "2.*"
},

2),执行 composer update

示例:

// make a connection
$con = new Stomp("failover://(tcp://192.168.25.193:61613,ssl://192.168.25.193:61612)?randomize=false");
// connect
$con->connect();
// send a message to the queue
$con->send("/queue/test", "test003");
echo "Sent message with body 'test003'\n";
// subscribe to the queue
$con->subscribe("/queue/test");
// receive a message from the queue
$msg = $con->readFrame();

// do what you want with the message
if ( $msg != null) {
    echo "Received message with body '$msg->body'\n";
    // mark the message as received in the queue
    $con->ack($msg);
} else {
    echo "Failed to receive a message\n";
}

// disconnect
$con->disconnect();

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值