当前位置:Gxlcms > PHP教程 > 关于activemqstomp类代码

关于activemqstomp类代码

时间:2021-07-01 10:21:17 帮助过:16人阅读

这篇文章主要介绍了关于activemq stomp类代码,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

此库用来增强ide,能对stomp类进行自动提示

  1. <?php
  2. class Stomp
  3. {
  4. /**
  5. * 构造器
  6. * Stomp constructor.
  7. * @param string $broker:连接地址,如:tcp://localhost:61613
  8. * @param string $username:用户名,默认为admin
  9. * @param string $password:密码:默认为admin
  10. * @param array $headers:头,如['client-id'=>$clientId]等
  11. */
  12. public function __construct(string $broker,string $username="admin",string $password="admin",array $headers=[])
  13. {
  14. }
  15. /**
  16. * 获取连接id
  17. */
  18. public function getSessionId():string{
  19. }
  20. /**
  21. * 设置超时时间
  22. * @param int $seconds:秒部分
  23. * @param int $microseconds:毫秒部分
  24. */
  25. public function setReadTimeout(int $seconds=10,int $microseconds=0){}
  26. /**
  27. * 获取超时时间
  28. * @return array
  29. * array(2) {
  30. ["sec"]=>
  31. int(2)
  32. ["usec"]=>
  33. int(0)
  34. }
  35. */
  36. public function getReadTimeout():array {
  37. }
  38. /**
  39. * 获取最后的一次错误
  40. * @return string
  41. */
  42. public function error():string{
  43. }
  44. /**
  45. * 发送消息
  46. * @param string $queue:队列名
  47. * @param mixed $msg:消息内容
  48. * @param array $headers:头
  49. * @return bool:是否成功
  50. */
  51. public function send(string $queue,mixed $msg,array $headers=[]):bool{
  52. }
  53. /**
  54. * 订阅某个队列,然后调用readFrame可以获取到消息
  55. * @param $queue:队列名
  56. * @param $headers:头参数数组
  57. * @return bool:
  58. */
  59. public function subscribe(string $queue,array $headers=[]):bool{
  60. }
  61. /**
  62. * 取消某个订阅
  63. * @param string $queue
  64. * @param array $headers
  65. * @return bool
  66. */
  67. public function unsubscribe(string $queue,array $headers=[]):bool {
  68. }
  69. /**
  70. * 判断此队列是否还有消息
  71. * @return bool
  72. */
  73. public function hasFrame():bool{
  74. }
  75. /**
  76. * 读取下一条消息
  77. * object(StompFrame)#2 (3) {
  78. ["command"]=>
  79. string(7) "MESSAGE"
  80. ["headers"]=>
  81. array(5) {
  82. ["message-id"]=>
  83. string(41) "ID:php.com-55293-1257226743606-4:2:-1:1:1"
  84. ["destination"]=>
  85. string(10) "/queue/foo"
  86. ["timestamp"]=>
  87. string(13) "1257226805828"
  88. ["expires"]=>
  89. string(1) "0"
  90. ["priority"]=>
  91. string(1) "0"
  92. }
  93. ["body"]=>
  94. string(3) "bar"
  95. }
  96. */
  97. public function readFrame():StompFrame{
  98. }
  99. /**
  100. * 确认消息
  101. * @param mixed $frame:消息帧
  102. * @param array $headers:头,可不填
  103. * @return bool:确认成功或者失败
  104. */
  105. public function ack(mixed $frame, array $headers=[]):bool {
  106. }
  107. /**
  108. * 开始事务
  109. *
  110. *
  111. try {
  112. $stomp = new Stomp('tcp://localhost:61613');
  113. } catch(StompException $e) {
  114. die('Connection failed: ' . $e->getMessage());
  115. }
  116. //begin a transaction
  117. $stomp->begin('t1');
  118. //send a message to the queue
  119. $stomp->send('/queue/foo', 'bar', array('transaction' => 't1'));
  120. // rollback
  121. $stomp->abort('t1');
  122. // close conection
  123. unset($stomp);
  124. ?>
  125. * @param string $transactionId:事务id,自己创建,保证唯一性
  126. * @param array $headers
  127. */
  128. public function begin(string $transactionId,array $headers=[]){
  129. }
  130. /**
  131. * 提交事务
  132. *
  133. *
  134. try {
  135. $stomp = new Stomp('tcp://localhost:61613');
  136. } catch(StompException $e) {
  137. die('Connection failed: ' . $e->getMessage());
  138. }
  139. //begin a transaction
  140. $stomp->begin('t1');
  141. //send a message to the queue
  142. $stomp->send('/queue/foo', 'bar', array('transaction' => 't1'));
  143. // rollback
  144. $stomp->commit('t1');
  145. // close conection
  146. unset($stomp);
  147. ?>
  148. * @param string $transactionId:事务id,自己创建,保证唯一性
  149. * @param array $headers
  150. */
  151. public function commit(){
  152. }
  153. /**
  154. * 回滚事务
  155. *
  156. *
  157. try {
  158. $stomp = new Stomp('tcp://localhost:61613');
  159. } catch(StompException $e) {
  160. die('Connection failed: ' . $e->getMessage());
  161. }
  162. //begin a transaction
  163. $stomp->begin('t1');
  164. //send a message to the queue
  165. $stomp->send('/queue/foo', 'bar', array('transaction' => 't1'));
  166. // rollback
  167. $stomp->abort('t1');
  168. // close conection
  169. unset($stomp);
  170. ?>
  171. * @param string $transactionId:事务id,自己创建,保证唯一性
  172. * @param array $headers
  173. */
  174. public function abort(string $transactionId,array $headers=[]){
  175. }
  176. }

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

关于Yii框架的增删改查

php类的继承与方法重载

以上就是关于activemq stomp类代码的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行