diff --git a/README.md b/README.md index be6ea42..4ebbeb5 100644 --- a/README.md +++ b/README.md @@ -109,6 +109,29 @@ Note: invalid SSL configuration will cause connection failure. See also [common configuration variants](examples/ssl/). +### Providing client properties + +Client Connections can [present their capabilities](https://www.rabbitmq.com/connections.html#capabilities) to +a server by presenting an optional `client_properties` table when establishing a connection. + +For example, a connection name may be provided by setting the +[`connection_name` property](https://www.rabbitmq.com/connections.html#client-provided-names): + +```php +$connection = [ + 'host' => 'HOSTNAME', + 'vhost' => 'VHOST', // The default vhost is / + 'user' => 'USERNAME', // The default user is guest + 'password' => 'PASSWORD', // The default password is guest + 'client_properties' => [ + 'connection_name' => 'My connection', + ], +]; + +$bunny = new Client($connection); +$bunny->connect(); +``` + ### Publish a message Now that we have a connection with the server we need to create a channel and declare a queue to communicate over before we can publish a message, or subscribe to a queue for that matter. diff --git a/src/Bunny/AbstractClient.php b/src/Bunny/AbstractClient.php index 9c4d1c0..f3b3524 100644 --- a/src/Bunny/AbstractClient.php +++ b/src/Bunny/AbstractClient.php @@ -138,6 +138,14 @@ public function __construct(array $options = []) $this->options['heartbeat_callback'] = $options['heartbeat_callback']; } + if (!isset($options['client_properties'])) { + $options['client_properties'] = []; + } + + if (!is_array($options['client_properties'])) { + throw new InvalidArgumentException('Client properties must be an array'); + } + $this->options = $options; $this->init(); @@ -353,7 +361,7 @@ protected function authResponse(MethodConnectionStartFrame $start) ], $responseBuffer); $responseBuffer->discard(4); - return $this->connectionStartOk([], "AMQPLAIN", $responseBuffer->read($responseBuffer->getLength()), "en_US"); + return $this->connectionStartOk($this->options['client_properties'], "AMQPLAIN", $responseBuffer->read($responseBuffer->getLength()), "en_US"); } /**