-
-
Notifications
You must be signed in to change notification settings - Fork 62
Connectivity
This Stomp client supports various connectivity methods helping you achieve more flexibility in how you connect to your broker (or brokers).
The Failover transport allows you to set URIs of multiple brokers and define basic parameters of how the client should attempt to connect to those brokers (in case it fails to connect for the first time). More information on the Failover transport and how ActiveMQ implements it could be found at the following URL.
PHP Stomp client uses the same configuration syntax as ActiveMQ. So instead of connecting to the broker by using standard broker URL, such as
$stomp = new Stomp('tcp://localhost:61613');you can use composite URLs. For example
$stomp = new Stomp('failover://(tcp://localhost:61614,tcp://localhost:61613)?randomize=false');Now instead of trying to connect to the single broker, the client will execute reconnection logic if needed. For the previous example, if we don't have a broker connector running on port 61614 it will try to connect on port 61613. If you look at PHP , you'll find messages similar to these
Warning: fsockopen(): unable to connect to tcp://localhost:61614
(Connection refused) in
.../src/Stomp/Stomp.php on line 201
Warning: Could not connect to localhost:61614 (1/10) in
.../src/Stomp/Stomp.php on line 204
This connectivity option allows you to use this client in a clustered broker environment.
Currently, you can only use the randomize parameter to specify whether you want to use random algorithm when choosing broker from the list.
If none of your defined brokers could be connected, a ConnectionException will be thrown.
You can instruct this client to use SSL when connecting to brokers that support this feature. For example, you can add another transport connector for ActiveMQ like this
<transportConnector name="stomp+ssl" uri="stomp+ssl://localhost:61612"/>and then you can connect to it by using the following syntax for the broker URL
$stomp = new Stomp('ssl://localhost:61612');SSL connections can be used as a part of failover URLs. For example
$stomp = new Stomp('failover://(tcp://localhost:61614,ssl://localhost:61612)?randomize=false');The full example of the PHP Stomp client connectivity options can be found in examples/connectivity.php.