I managed to setup a vps and stomp client on plesk. Took me some time but got there.
I have managed to get some code together however it connects to server and subscribes to the topic ok, however I am unable to read any messages. Can anyone assist? here is my code so far:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Check if the Stomp extension is installed
if (!extension_loaded('stomp')) {
die('Stomp extension not installed. Please install and enable it to proceed.');
}
// Network Rail Stomp Handler example by ian13
$server = "tcp://
datafeeds.networkrail.co.uk:61618";
$user = "*****@******.
co.uk"; // removed for obvious reasons
$password = "************";
// removed for obvious reasons
$channel = "RTPPM_ALL";
try {
// Create a new Stomp connection
$stomp = new Stomp($server, $user, $password);
// Check if the connection was successful
if (!$stomp) {
die('Connection failed: ' . stomp_connect_error());
} else {
echo "<p>Connected</p>";
}
// Subscribe to the topic
//$con->subscribe("/topic/" . $channel);
$stomp->subscribe("/topic/".$channel);
// Check if the subscription was successful
if (!$stomp) {
die('Subscription failed: ' . stomp_connect_error());
} else {
echo "<p>Subscribed to /topic/{$channel}</p>";
}
// Receive a message from the topic
$msg = $stomp->readFrame();
var_dump($msg);
// Do what you want with the message
if ($msg != null) {
echo "<p>Received message with body '$msg->body'</p>";
// Mark the message as received in the queue
$stomp->ack($msg);
} else {
echo "<p>Failed to receive a message</p>";
}
// Disconnect
unset($stomp);
echo "<p>Connection closed</p>";
} catch (StompException $e) {
// Catch any Stomp-related exceptions
die('Stomp Exception: ' . $e->getMessage());
} catch (Exception $e) {
// Catch any other exceptions
die('Exception: ' . $e->getMessage());
}