Skip to content

Commit

Permalink
More examples in demo for multiple hosts connections
Browse files Browse the repository at this point in the history
  • Loading branch information
hairyhum committed Apr 20, 2018
1 parent 4e55d9f commit f6243b8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions demo/amqp_connect_multiple_hosts.php
Expand Up @@ -2,6 +2,7 @@

include(__DIR__ . '/config.php');
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Connection\AMQPSocketConnection;
use PhpAmqpLib\Connection\AMQPSSLConnection;

define('CERTS_PATH', '/git/rabbitmqinaction/av_scratchwork/openssl');
Expand Down Expand Up @@ -36,6 +37,40 @@
'heartbeat' => 0
]);


// Use empty options array for defaults
$connection = AMQPStreamConnection::create_connection([
['host' => HOST, 'port' => PORT, 'user' => USER, 'password' => PASS, 'vhost' => VHOST],
['host' => HOST, 'port' => 5673, 'user' => USER, 'password' => PASS, 'vhost' => VHOST],
['host' => HOST, 'port' => 5674, 'user' => USER, 'password' => PASS, 'vhost' => VHOST]
],
[]);

// Options keys are different for different connection types
$connection = AMQPSocketConnection::create_connection([
['host' => HOST, 'port' => PORT, 'user' => USER, 'password' => PASS, 'vhost' => VHOST],
['host' => HOST, 'port' => 5673, 'user' => USER, 'password' => PASS, 'vhost' => VHOST],
['host' => HOST, 'port' => 5674, 'user' => USER, 'password' => PASS, 'vhost' => VHOST]
],
[
'insist' => false,
'login_method' => 'AMQPLAIN',
'login_response' => null,
'locale' => 'en_US',
'read_timeout' => 3,
'keepalive' => false,
'write_timeout' => 3,
'heartbeat' => 0
]);

// Use empty options array for defaults
$connection = AMQPSocketConnection::create_connection([
['host' => HOST, 'port' => PORT, 'user' => USER, 'password' => PASS, 'vhost' => VHOST],
['host' => HOST, 'port' => 5673, 'user' => USER, 'password' => PASS, 'vhost' => VHOST],
['host' => HOST, 'port' => 5674, 'user' => USER, 'password' => PASS, 'vhost' => VHOST]
], []);


/*
For SSL connections you should set 'ssl_options' in the options array
*/
Expand Down
1 change: 1 addition & 0 deletions demo/connection_recovery_consume.php
Expand Up @@ -17,6 +17,7 @@
*/

function connect() {
// If you want a better load-balancing, you cann reshuffle the list.
return AMQPStreamConnection::create_connection([
['host' => HOST, 'port' => PORT1, 'user' => USER, 'password' => PASS, 'vhost' => VHOST],
['host' => HOST, 'port' => PORT2, 'user' => USER, 'password' => PASS, 'vhost' => VHOST],
Expand Down

0 comments on commit f6243b8

Please sign in to comment.