zoukankan      html  css  js  c++  java
  • php使用activemq

    一、下载:

    http://activemq.apache.org/activemq-5140-release.html

    二、安装

    tar -zxvf apache-activemq-5.15.3-bin.tar.gz
    cd apache-activemq-5.14.0
    cd bin
    ./activemq start
    

    三、防火墙端口

    <
    8161(web管理页面端口)
    61616(activemq服务监控端口)
    

    四、web管理页面

    默用户名密码 admin/admin 
    
     
    image.png

    五 使用

    使用stomp-php

    <?php
    require __DIR__ . '/../vendor/autoload.php';
    
    
    // 引入库
    use FuseSourceStompStomp;
    
    // 创建连接
    $con = new Stomp("tcp://localhost:61613");
    
    // 连接
    $con->connect();
    //发送消息到队列
    $con->send("/queue/test", "test");
    $con->send("/queue/test", "test", array('persistent' => 'true'));//支持持久化
    
    echo "Sent message with body 'test'
    ";
    // 订阅队列
    $con->subscribe("/queue/test");
    // 从队列中接收消息
    $msg = $con->readFrame();
    
    // 执行自定义任务
    if ($msg != null) {
        echo "Received message with body '$msg->body'
    ";
        // 将消息标记为在队列中收到
        $con->ack($msg);
    } else {
        echo "Failed to receive a message
    ";
    }
    
    
    // 关闭连接
    $con->disconnect();
    ?>
    

    使用扩展Stomp

    <?php
        $queue  = 'msg_notify';
        $msg    = json_encode(array(
            'uid'=>100,
            'email'=>'xxx@baidu.com',
            'address'=>'beijing',
        ),JSON_UNESCAPED_UNICODE);
    
        /* 连接 */
        try {
            $stomp = new Stomp('tcp://localhost:61613');
        } catch(StompException $e) {
            die('Connection failed: ' . $e->getMessage());
        }
    
        /* 向队列“Foo”发送消息*/
        $stomp->send($queue, $msg,array('persistent'=> true));
    
        /* 订阅来自“Foo”队列的消息 */
        $stomp->subscribe($queue);
    
        /* 读取数据 */
        $frame = $stomp->readFrame();
    
        if ($frame->body === $msg) {
            var_dump($frame->body);
            /* 确认接收到*/
            $stomp->ack($frame);
        }
    
        /* 连接关闭 */
        unset($stomp);
  • 相关阅读:
    GCD
    Android仿人人客户端(v5.7.1)——对从服务器端(网络)获取的图片进行本地双缓存处理(编码实现)
    systimestamp
    byte数组之间的赋值,byte和TCHAR数组的赋值
    如何修改hotspot默认信道
    Wifi的密码长度有何限制
    微信心跳机制
    如何内置iperf到手机中
    如何adb shell进入ctia模式
    本周推荐10款免费的网站模板设计
  • 原文地址:https://www.cnblogs.com/setevn/p/14584662.html
Copyright © 2011-2022 走看看