Skip to content

Commit

Permalink
Merge pull request #132 from jeromegamez/client-properties-support
Browse files Browse the repository at this point in the history
Add support for setting client properties
  • Loading branch information
WyriHaximus authored May 19, 2024
2 parents 464507a + 5a0e944 commit 6cdf0ed
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 9 additions & 1 deletion src/Bunny/AbstractClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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");
}

/**
Expand Down

0 comments on commit 6cdf0ed

Please sign in to comment.