À propos du code de la classe ActiveMQ Stomp

不言
Libérer: 2023-04-02 10:40:01
original
1612 Les gens l'ont consulté

Cet article présente principalement le code de la classe activemq stomp, qui a une certaine valeur de référence. Maintenant, je le partage avec tout le monde. Les amis dans le besoin peuvent s'y référer

Cette bibliothèque est utilisée pour. améliorer l'idée, peut automatiquement inviter la classe Stomp

<?php
class Stomp
{
    /**
     * 构造器
     * Stomp constructor.
     * @param string $broker:连接地址,如:tcp://localhost:61613
     * @param string $username:用户名,默认为admin
     * @param string $password:密码:默认为admin
     * @param array $headers:头,如[&#39;client-id&#39;=>$clientId]等
     */
    public function __construct(string $broker,string $username="admin",string $password="admin",array $headers=[])
    {
    }

    /**
     * 获取连接id
     */
    public function getSessionId():string{

    }
    /**
     * 设置超时时间
     * @param int $seconds:秒部分
     * @param int $microseconds:毫秒部分
     */
    public function setReadTimeout(int $seconds=10,int $microseconds=0){}

    /**
     * 获取超时时间
     * @return array
     * array(2) {
    ["sec"]=>
    int(2)
    ["usec"]=>
    int(0)
    }
     */
    public function getReadTimeout():array {

    }

    /**
     * 获取最后的一次错误
     * @return string
     */
    public function error():string{

    }


    /**
     * 发送消息
     * @param string $queue:队列名
     * @param mixed $msg:消息内容
     * @param array $headers:头
     * @return bool:是否成功
     */
    public function send(string $queue,mixed $msg,array $headers=[]):bool{

    }

    /**
     * 订阅某个队列,然后调用readFrame可以获取到消息
     * @param $queue:队列名
     * @param $headers:头参数数组
     * @return bool:
     */
    public function subscribe(string $queue,array $headers=[]):bool{

    }

    /**
     * 取消某个订阅
     * @param string $queue
     * @param array $headers
     * @return bool
     */
    public function unsubscribe(string $queue,array $headers=[]):bool {

    }

    /**
     * 判断此队列是否还有消息
     * @return bool
     */
    public function hasFrame():bool{

    }

    /**
     * 读取下一条消息
     * object(StompFrame)#2 (3) {
    ["command"]=>
    string(7) "MESSAGE"
    ["headers"]=>
    array(5) {
    ["message-id"]=>
    string(41) "ID:php.net-55293-1257226743606-4:2:-1:1:1"
    ["destination"]=>
    string(10) "/queue/foo"
    ["timestamp"]=>
    string(13) "1257226805828"
    ["expires"]=>
    string(1) "0"
    ["priority"]=>
    string(1) "0"
    }
    ["body"]=>
    string(3) "bar"
    }
     */
    public function readFrame():StompFrame{

    }

    /**
     * 确认消息
     * @param mixed $frame:消息帧
     * @param array $headers:头,可不填
     * @return bool:确认成功或者失败
     */
    public function ack(mixed $frame, array $headers=[]):bool {

    }

    /**
     * 开始事务
     *
     *
    try {
    $stomp = new Stomp(&#39;tcp://localhost:61613&#39;);
    } catch(StompException $e) {
    die(&#39;Connection failed: &#39; . $e->getMessage());
    }

    //begin a transaction
    $stomp->begin(&#39;t1&#39;);

    //send a message to the queue
    $stomp->send(&#39;/queue/foo&#39;, &#39;bar&#39;, array(&#39;transaction&#39; => &#39;t1&#39;));

    // rollback
    $stomp->abort(&#39;t1&#39;);

    // close conection
    unset($stomp);
    ?>
     * @param string $transactionId:事务id,自己创建,保证唯一性
     * @param array $headers
     */
    public function begin(string $transactionId,array $headers=[]){

    }
    /**
     * 提交事务
     *
     *
    try {
    $stomp = new Stomp(&#39;tcp://localhost:61613&#39;);
    } catch(StompException $e) {
    die(&#39;Connection failed: &#39; . $e->getMessage());
    }

    //begin a transaction
    $stomp->begin(&#39;t1&#39;);

    //send a message to the queue
    $stomp->send(&#39;/queue/foo&#39;, &#39;bar&#39;, array(&#39;transaction&#39; => &#39;t1&#39;));

    // rollback
    $stomp->commit(&#39;t1&#39;);

    // close conection
    unset($stomp);
    ?>
     * @param string $transactionId:事务id,自己创建,保证唯一性
     * @param array $headers
     */
    public function commit(){

    }

    /**
     * 回滚事务
     *
     *
        try {
        $stomp = new Stomp(&#39;tcp://localhost:61613&#39;);
        } catch(StompException $e) {
        die(&#39;Connection failed: &#39; . $e->getMessage());
        }

        //begin a transaction
        $stomp->begin(&#39;t1&#39;);

        //send a message to the queue
        $stomp->send(&#39;/queue/foo&#39;, &#39;bar&#39;, array(&#39;transaction&#39; => &#39;t1&#39;));

        // rollback
        $stomp->abort(&#39;t1&#39;);

        // close conection
        unset($stomp);
        ?>
     * @param string $transactionId:事务id,自己创建,保证唯一性
     * @param array $headers
     */
    public function abort(string $transactionId,array $headers=[]){

    }
}
Copier après la connexion

Ce qui précède est l'intégralité du contenu de cet article, j'espère qu'il sera utile à l'apprentissage de chacun, plus de contenu connexe Veuillez faire attention au site Web chinois PHP !

Recommandations associées :

À propos des ajouts, suppressions et modifications du framework Yii

Héritage et surcharge de méthodes des classes PHP

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!