PHP code example of grimkirill / stomp

1. Go to this page and download the library: Download grimkirill/stomp library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

grimkirill / stomp example snippets



/**
 * Create connection
 */
$client = new \Stomp\Client(array('tcp://127.0.0.1:61613'), array(
        'login' => 'admin',
        'passcode' => 'password',
        'host' => '/',
        'queue_prefix' => '/queue/',
    ));
        
$client->send('queue_destination', 'hello message');    

$client->subscribe('queue_destination');
while ($message = $client->readMessage()) {
    echo $message->getBody();
    $message->ack();
}



ent = new \Stomp\Client('tcp://127.0.0.1:61613', array('login' => 'admin', 'passcode' => 'password'));

$consumer = new \Stomp\Helper\Consumer($client, '/queue/testing');

$endTime = new \DateTime('+30 second');
$condition = function () use ($endTime) {
    return ((new DateTime()) < $endTime);
};

$consumer->run(function($data, $headers) {
    var_dump($data);
    print_r($headers);
    return date('c');
}, $condition);



ent = new \Stomp\Client('tcp://127.0.0.1:61613', array('login' => 'admin', 'passcode' => 'password'));

$rpc = new \Stomp\Helper\Rpc($client, '/queue/testing');

var_dump($rpc->call('Ping')); // string(25) "2015-03-13T10:22:27+00:00"