Skip to content

Instantly share code, notes, and snippets.

@sinkovsky
Created August 12, 2010 18:28
Show Gist options
  • Save sinkovsky/521431 to your computer and use it in GitHub Desktop.
Save sinkovsky/521431 to your computer and use it in GitHub Desktop.
class StompClient extends Stomp
{
var $config;
var $server;
var $failover_servers;
public function __construct() {
global $HP;
$config_string = file_get_contents($HP['topdir']."/conf/activemq.json");
$this->config = json_decode($config_string, true);
foreach ( array_keys($this->config) as $s ) {
$this->failover_servers[$s] = 0;
}
$this->server = 'master';
$this->connect();
}
public function failover() {
foreach ( $this->failover_servers as $s => $count ) {
if ( $s != $this->server and $count != 1 ) {
$this->server = $s;
$this->failover_servers[$s] = 1;
$this->connect();
return 1;
}
}
return 0;
}
public function connect() {
$connect_string = sprintf('tcp://%s:%s', $this->config[$this->server]['host'], $this->config[$this->server]['port']);
parent::__construct($connect_string);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment