I'm trying to get a queue from activemq using a PHP client. I included in the project a stomp library. Here is my project tree:
TestPhp/
├── PhpInfo.php
├── SimpleStompConsumer.php
└── Stomp
├── Exception
| └── StompException.php
├── ExceptionInterface.php
├── Frame.php
├── Message
│ ├── Bytes.php
│ └── Map.php
├── Message.php
└── Stomp.php
and here is my code
<?php
$path = "/var/www/test/TestPhp/Stomp/Stomp.php";
require_once($path);
$con = new Stomp("tcp://localhost:61613");
$con->connect();
$con->subscribe("/queue/test");
$msg = $con->readFrame();
if( $msg != null) {
echo "Received message with body '$msg->body'\n";
$con->ack($msg);
} else {
echo "Failed to receive a message\n";
}
$con->disconnect();
?>
When I run the php file I get the following error and I don' know what to do.
PHP Fatal error: Class 'Stomp' not found in /var/www/test/TestPhp/SimpleStompConsumer.php on line 5
PHP Stack trace: PHP 1. {main}() /var/www/test/TestPhp/SimpleStompConsumer.php:0
I'd appreciate any directives. Thanks.
Edit:
Library is called Stomp. Here is the github link and the download link
Edit:
Change $con = new Stomp("tcp://localhost:61613");
to $con = new FuseSource\Stomp\Stomp("tcp://localhost:61613");
$con = new FuseSource\Stomp\Stomp("tcp://localhost:61613");
ERROR returned:
PHP Fatal error: Class 'FuseSource\Stomp\Exception\StompException' not found in /var/www/test/TestPhp/Stomp/Stomp.php on line 174
PHP Stack trace:
PHP 1. {main}() /var/www/test/TestPhp/SimpleStompConsumer.php:0
PHP 2. FuseSource\Stomp\Stomp->connect() /var/www/test/TestPhp/SimpleStompConsumer.php:6
PHP 3. FuseSource\Stomp\Stomp->_makeConnection() /var/www/test/TestPhp/Stomp/Stomp.php:195
Stomp library is a composer package, so you need composer class loader or any other PSR-0 compatible, see this https://getcomposer.org/doc/01-basic-usage.md.
Example PSR-0 class loader from PHP-Fig: https://gist.github.com/jwage/221634
require_once 'path_to_spl_class_loader.php';
$loader = new SplClassLoader('FuseSource\Stomp', __DIR__.'/Stomp');
$loader->register();
new FuseSource\Stomp\Stomp();
Besides it's namespaced class, add this line to you file:
use FuseSource\Stomp\Stop;
new Stomp();
Or use
new FuseSource\Stomp\Stomp();