Table of Contents
This article mainly introduces the activemq stomp class code, which has certain reference value. Now I share it with everyone. Friends in need can refer to it" >This article mainly introduces the activemq stomp class code, which has certain reference value. Now I share it with everyone. Friends in need can refer to it
This library is used to enhance ide, can automatically prompt the stomp class
Home Backend Development PHP Tutorial About activemq stomp class code

About activemq stomp class code

Jul 04, 2018 pm 01:53 PM

This article mainly introduces the activemq stomp class code, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

This library is used to enhance ide, can automatically prompt the stomp class

<?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=[]){

    }
}
Copy after login

The above is the entire content of this article, I hope it will be helpful to everyone's learning, please pay attention to more related content PHP Chinese website!

Related recommendations:

About the additions, deletions and modifications of Yii framework

Inheritance and method overloading of PHP classes

The above is the detailed content of About activemq stomp class code. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP error: Unable to declare class repeatedly, solution! PHP error: Unable to declare class repeatedly, solution! Aug 25, 2023 pm 04:13 PM

PHP error: Unable to declare class repeatedly, solution! It is common for developers to encounter problems. In PHP development, we often encounter a common error: the class cannot be declared repeatedly. This problem seems simple, but if not solved in time, the code will not execute correctly. This article will introduce the cause of this problem and provide a solution for your reference. When we define a class in PHP code, if the same class is defined multiple times in the same file or multiple files, an error that the class cannot be declared repeatedly will occur. This is

Naming conventions in PHP: How to use camel case naming for classes, methods and variables Naming conventions in PHP: How to use camel case naming for classes, methods and variables Jul 30, 2023 pm 02:43 PM

Naming conventions in PHP: How to use camelCase notation to name classes, methods, and variables In PHP programming, good naming conventions are an important coding practice. It improves code readability and maintainability, and makes teamwork smoother. In this article, we will explore a common naming convention: camelCase and provide some examples of how to use it in PHP to name classes, methods, and variables. 1. What is camel case nomenclature? CamelCase is a common naming convention in which the first letter of each word is capitalized,

Packaging technology and application in PHP Packaging technology and application in PHP Oct 12, 2023 pm 01:43 PM

Encapsulation technology and application encapsulation in PHP is an important concept in object-oriented programming. It refers to encapsulating data and operations on data together in order to provide a unified access interface to external programs. In PHP, encapsulation can be achieved through access control modifiers and class definitions. This article will introduce encapsulation technology in PHP and its application scenarios, and provide some specific code examples. 1. Encapsulated access control modifiers In PHP, encapsulation is mainly achieved through access control modifiers. PHP provides three access control modifiers,

Class not found in Java - How to solve java.lang.ClassNotFoundException? Class not found in Java - How to solve java.lang.ClassNotFoundException? Jun 25, 2023 am 10:37 AM

During the Java development process, sometimes you will encounter an error: java.lang.ClassNotFoundException. It says that the required class file cannot be found in the Java Virtual Machine (JVM). This error will cause the program to not run properly, and if not resolved in time, will delay the development progress. This article will introduce the reasons and solutions for classes not found in Java. 1. Reason 1. The class path is wrong. In Java, the package path and class path are very important. If the classpath is set incorrectly or the class file

How to use Attributes to add custom annotations to classes in PHP8? How to use Attributes to add custom annotations to classes in PHP8? Oct 18, 2023 am 10:16 AM

How to use Attributes to add custom annotations to classes in PHP8? Custom annotations are a way to add metadata to a class or method, which can help us obtain and process additional information on a specific class or method at runtime. In PHP8, the concept of Attributes was introduced, which allows us to easily add custom annotations to classes. This article will introduce how to use Attributes to implement custom annotations for classes in PHP8 and provide specific code examples. In PHP8, since

'Introduction to Object-Oriented Programming in PHP: From Concept to Practice' 'Introduction to Object-Oriented Programming in PHP: From Concept to Practice' Feb 25, 2024 pm 09:04 PM

What is object-oriented programming? Object-oriented programming (OOP) is a programming paradigm that abstracts real-world entities into classes and uses objects to represent these entities. Classes define the properties and behavior of objects, and objects instantiate classes. The main advantage of OOP is that it makes code easier to understand, maintain and reuse. Basic Concepts of OOP The main concepts of OOP include classes, objects, properties and methods. A class is the blueprint of an object, which defines its properties and behavior. An object is an instance of a class and has all the properties and behaviors of the class. Properties are characteristics of an object that can store data. Methods are functions of an object that can operate on the object's data. Advantages of OOP The main advantages of OOP include: Reusability: OOP can make the code more

PHP Code Encapsulation Tips: How to Use Classes and Objects to Encapsulate Reusable Code Blocks PHP Code Encapsulation Tips: How to Use Classes and Objects to Encapsulate Reusable Code Blocks Jul 29, 2023 pm 11:19 PM

PHP code encapsulation skills: How to use classes and objects to encapsulate reusable code blocks Summary: During development, we often encounter code blocks that need to be reused. In order to improve the maintainability and reusability of the code, we can use class and object encapsulation techniques to encapsulate these code blocks. This article explains how to use classes and objects to encapsulate reusable blocks of code and provides several concrete code examples. Advantages of using classes and objects to encapsulate. Using classes and objects to encapsulate has the following advantages: 1.1 Improve the maintainability of code by reducing duplication

PHP closure class PHP closure class Aug 19, 2023 am 11:01 AM

Introducing anonymous functions (also called lambdas) that return objects of class Closure. This class has some additional methods that provide further control over anonymous functions. SyntaxClosure{ /*Methods*/ private__construct(void) publicstaticbind(Closure$closure,object$newthis[,mixed$newscope="static"

See all articles