php - Fatal error: Uncaught Error: Class 'Stomp' not found -


i've downloaded library available in: https://github.com/dejanb/stomp-php

and implemented following code:

<?php     use fusesource\stomp\stomp;    (...) $data=array($data1,$data2, $data3, $data4); $json = json_encode($data, true);   $user = getenv("activemq_user");  if( !$user ) $user = "admin";  $password = getenv("activemq_password"); if( !$password ) $password = "password";  $destination  = '/topic/event'; $messages = 10000; $size = 256;  $data = "calls"; $body = $data; for($i=0; $i< $size; $i++) {   $body .= $data[ $i % 26]; }  try {   $url = 'tcp://localhost:61613';   $con = new stomp($url, $user, $password);    for($i=0; $i< $messages; $i++) {     $con->send($destination, $body);     if( $i%1000 == 0 ) {       echo "sent ".$i." messages\n";     }   }    $stomp->send($destination, "shutdown");  } catch(stompexception $e) {   echo $e->getmessage(); } } 

and error:

fatal error: uncaught error: class 'stomp' not found in /opt/lampp/htdocs/skeleton-application/test.php:80

update: reinstalled using composer suggested @ https://github.com/stomp-php/stomp-php.

i required autoloader using

<?php require __dir__ . '/../vendor/autoload.php'; 

and added following imports

use stomp\client; use stomp\statefulstomp; use stomp\network\connection; use stomp\transport\message; 

still same error... need special activemq broker or something? ran through console... still nothing

apart confusion package use, our code has following problems:

  • you haven't imported classes using, , thus, php cannot find classes within root namespace
  • you passing in parameters constructors , other methods aren't used, or have wrong type
  • you apparently have undefined variables (for example, $stomp undefined, or it's missing code example)

i suggest tackling these problems 1 one.

using fusesource/stomp-php

import classes using

adjust list of imports (these use statements) include classes referencing in code example:

use fusesource\stomp\exception\stompexception; use fusesource\stomp\stomp; 

if there more classes package code example omits, include them in imports well.

remove unnecessary parameters

when create instance of fusesource\stomp\stomp, passing in parameters constructor doesn't use.

change

$con = new stomp($url, $user, $password); 

to

$con = new stomp($url); 

undefined variables

you have line of code reference undefined variable $stomp, intend use $con instead.

change

$stomp->send($destination, "shutdown"); 

to

$con->send($destination, new message("shutdown")); 

using stomp-php/stomp-php

import classes using

adjust list of imports (these use statements) include classes referencing in code example:

use stomp\client; use stomp\exception\stompexception; use stomp\statefulstomp; use stomp\transport\message; 

if there more classes package code example omits, include them in imports well.

remove unnecessary parameters

the constructor of stomp\stomp\statefulstomp has different signature of fusesource\stomp.

change

$con = new stomp($url, $user, $password); 

to

$con = new statefulstomp(new client($url)); 

adjust parameters required type

the signature of send() has changed.

change

$con->send($destination, $body); 

to

$con->send($destination, new message($body));         

undefined variables

you have line of code reference undefined variable $stomp, intend use $con instead.

change

$stomp->send($destination, "shutdown"); 

to

$con->send($destination, new message("shutdown")); 

for reference, see:


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -