Created
August 12, 2010 18:28
-
-
Save sinkovsky/521431 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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