Jump to content

Php Connect Stomp, Activemq


Signalman

Recommended Posts

Ok, I am new to this forum, and also new to php, so apologies in advance if I have posted this in the wrong forum, or of it has been answered previously (although I did search prior to posting).

 

The setup I have is running windows xp, using activemq, STOMP and php.

 

I have installed activemq , and started it running, this would appear to be confirmed by the fact that I can see it in Internet explorer.

 

I have downloaded STOMP and as I am unsure how to insert a link to a library in the php code, I have put everything in the one directory (editing the STOMP files where they specify a sub directory).

 

When i run the sample php code, it does not have the desired effect, but generates the following in the IE screen :-

 

 

connect(); // 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(); ?>

 

 

I have tried numerous things to get this to work, without success. I am sure it is something simple, once you know.

 

Any assistance would be appreciated.

Thanks in advance

Link to comment
Share on other sites

The tag is <? As copied from the example. The complete code is below :-

 

<?

// include a library

require_once("Stomp.php");

// make a connection

$con = new Stomp("tcp://localhost:61613");

// connect

$con->connect();

// 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();

?>

 

 

I have tried a 'hello world' programme and that seems to work ok, however that did have the tag of <?php at the start. From your question, I am guessing that there is a difference ?

 

Link to comment
Share on other sites

Thanks very much, I have changed the tag to include php and whilst the code is not totally working, it is being processed as I would expect. I can now continue getting the code to run, now it is at least being processed.

 

I guess I have shown that I am very new to Php.

 

Thanks for your assistance with something as basic as this.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.