PHP code example of happyr / stomp-bundle

1. Go to this page and download the library: Download happyr/stomp-bundle 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/ */

    

happyr / stomp-bundle example snippets


    // app/AppKernel.php

    public function registerBundles()
    {
        $bundles = array(
            // ...
            new HappyR\StompBundle\HappyRStompBundle(),
        );
    }
    

//get the connection
$con = $this->container->get('happyr.stomp.broker');

// send a message to the queue
$con->send("/queue/test", "test");
echo "Sent message with body 'test'\n";

// subscribe to the queue
$con->subscribe("/queue/test");

// receive a message from the queue
$msg = $con->readFrame();

// do what you want with the message
if ( $msg != null) {
    echo "Received message with body '$msg->body'\n";

    // mark the message as received in the queue
    $con->ack($msg);
} else {
    echo "Failed to receive a message\n";
}

// disconnect
$con->disconnect();

    php composer.phar