Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for setting client properties #132

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading