IT. Expert System.

PHP

Examples


Examples

Example #1 Object oriented style

<?php

$queue  
'/queue/foo';
$msg    'bar';

/* connection */
try {
    
$stomp = new Stomp('tcp://localhost:61613');
} catch(
StompException $e) {
    die(
'Connection failed: ' $e->getMessage());
}

/* send a message to the queue 'foo' */
$stomp->send($queue$msg);

/* subscribe to messages from the queue 'foo' */
$stomp->subscribe($queue);

/* read a frame */
$frame $stomp->readFrame();

if (
$frame->body === $msg) {
    
var_dump($frame);

    
/* acknowledge that the frame was received */
    
$stomp->ack($frame);
}

/* close connection */
unset($stomp);

?>

The above example will output something similar to:

 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" } 

Example #2 Procedural style

<?php

$queue  
'/queue/foo';
$msg    'bar';

/* connection */
$link stomp_connect('ssl://localhost:61612');

/* check connection */
if (!$link) {
    die(
'Connection failed: ' stomp_connect_error());
}

/* begin a transaction */
stomp_begin($link't1');

/* send a message to the queue 'foo' */
stomp_send($link$queue$msg, array('transaction' => 't1'));

/* commit a transaction */
stomp_commit($link't1');

/* subscribe to messages from the queue 'foo' */
stomp_subscribe($link$queue);

/* read a frame */
$frame stomp_read_frame($link);

if (
$frame['body'] === $msg) {
    
var_dump($frame);

    
/* acknowledge that the frame was received */
    
stomp_ack($link$frame['headers']['message-id']);
}

/* close connection */
stomp_close($link);

?>

The above example will output something similar to:

 array(3) { ["command"]=> string(7) "MESSAGE" ["body"]=> string(3) "bar" ["headers"]=> array(6) {  ["transaction"]=>  string(2) "t1"  ["message-id"]=>  string(41) "ID:php.net-55293-1257226743606-4:3:-1:1:1"  ["destination"]=>  string(10) "/queue/foo"  ["timestamp"]=>  string(13) "1257227037059"  ["expires"]=>  string(1) "0"  ["priority"]=>  string(1) "0" } } 



Content

Android Reference

Java basics

Java Enterprise Edition (EE)

Java Standard Edition (SE)

SQL

HTML

PHP

CSS

Java Script

MYSQL

JQUERY

VBS

REGEX

C

C++

C#

Design patterns

RFC (standard status)

RFC (proposed standard status)

RFC (draft standard status)

RFC (informational status)

RFC (experimental status)

RFC (best current practice status)

RFC (historic status)

RFC (unknown status)

IT dictionary

License.
All information of this service is derived from the free sources and is provided solely in the form of quotations. This service provides information and interfaces solely for the familiarization (not ownership) and under the "as is" condition.
Copyright 2016 © ELTASK.COM. All rights reserved.
Site is optimized for mobile devices.
Downloads: 346 / 96392400. Delta: 0.03748 с