This article mainly introduces about the Activemq Stomp Class code, has certain reference value, now shares to everybody, has the need friend can refer to
This library is used to enhance the IDE and to automatically prompt the Stomp class
<?phpclass stomp{/** * constructor * Stomp constructor. * @param string $broker: Connection address, such as: tcp://localhost:61613 * @param string $username: Username, admin * @param string By default $PASSW Ord: Password: The default is admin * @param array $headers: header, such as [' Client-id ' + $clientId], etc. */Public function __construct (string $ broker,string $username = "admin", string $password = "Admin", array $headers =[]) {}/** * get connection ID */Public function GetSessionID (): string{}/** * Set timeout time * @param int $seconds: Seconds part * @param int $microseconds: milliseconds Sub */Public function setreadtimeout (int $seconds =10,int $microseconds =0) {}/** * get time-out * @return Array * Array (2) {["SEC"]=> Int (2) ["USEC"]=> int (0)} */Public Function getreadtimeout (): Arra Y {}/** * Gets the last error * @return String */Public Function error (): string{}/** * Send Message * @param string $queue: queue name * @param mixed $msg: Message contents * @param array $heaDERs: Header * @return BOOL: SUCCEEDED */Public function Send (string $queue, mixed $msg, array $headers =[]): bool{}/* * * Subscribe to a queue and call Readframe to get to the message * @param $queue: queue name * @param $headers: Array of header parameters * @return BOOL: */Publ IC function Subscribe (string $queue, array $headers =[]): bool{}/** * Cancel a subscription * @param string $queue * @pa Ram Array $headers * @return BOOL */Public Function unsubscribe (string $queue, array $headers =[]): bool {} /** * Determine if this queue has a message * @return BOOL */Public Function hasframe (): bool{}/** * Read Next message * Obje CT (stompframe) #2 (3) {["command"]=> string (7) "MESSAGE" ["Headers"]=> Array (5) {["Message-id"]=> String "Id:php.net-55293-1257226743606-4:2:-1:1:1" ["Destination"]=> string (Ten) "/queue/foo" ["Timesta MP "]=> string" 1257226805828 "[" Expires "]=> string (1)" 0 "[" Priority "]=> string (1)" 0 "} ["Body"]=> string(3) "Bar"} */Public Function readframe (): stompframe{}/** * Acknowledgment message * @param mixed $frame: Message frame * @param array $headers: header, can not fill * @return bool: Confirm success or failure */Public Function ack (mixed $frame, array $headers =[]): b ool {}/** * start transaction * * try {$stomp = new Stomp (' tcp://localhost:61613 '); } catch (Stompexception $e) {die (' Connection failed: '. $e->getmessage ()); }//begin a transaction $stomp->begin (' t1 '); Send a message to the queue $stomp->send ('/queue/foo ', ' Bar ', Array (' transaction ' = ' T1 ')); Rollback $stomp->abort (' t1 '); Close conection unset ($stomp); ?> * @param string $transactionId: Transaction ID, create it yourself, guarantee uniqueness * @param array $headers */Public function begin (Strin G $transactionId, array $headers =[]) {}/** * COMMIT TRANSACTION * * try {$stomp = new Stomp (' tcp://localhost:61 613 '); } catch (Stompexception $e) {die (' Connection failed: '. $e->getMessage ()); }//begin a transaction $stomp->begin (' t1 '); Send a message to the queue $stomp->send ('/queue/foo ', ' Bar ', Array (' transaction ' = ' T1 ')); Rollback $stomp->commit (' t1 '); Close conection unset ($stomp); ?> * @param string $transactionId: Transaction ID, created by itself, guaranteed uniqueness * @param array $headers */Public Function commit () { }/** * ROLLBACK TRANSACTION * * try {$stomp = new Stomp (' tcp://localhost:61613 '); } catch (Stompexception $e) {die (' Connection failed: '. $e->getmessage ()); }//begin a transaction $stomp->begin (' t1 '); Send a message to the queue $stomp->send ('/queue/foo ', ' Bar ', Array (' transaction ' = ' T1 ')); Rollback $stomp->abort (' t1 '); Close conection unset ($stomp); ?> * @param string $transactionId: Transaction ID, create it yourself, guarantee uniqueness * @param array $headers */Public Function abort (strin G $transactioNid,array $headers =[]) {}}
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!