Download the PHP package basis-company/nats without Composer
On this page you can find all versions of the php package basis-company/nats. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nats
Nats client for php
Feel free to contribute or give any feedback.
- Nats client for php
- Installation
- Connecting
- Connecting with TLS
- Connecting with JWT
- Publish Subscribe
- Request Response
- JetStream Api Usage
- Microservices
- Key Value Storage
- Performance
- Configuration Options
Installation
The recommended way to install the library is through Composer:
The NKeys functionality requires Ed25519, which is provided in libsodium
extension or sodium_compat
package.
Connecting
Connecting with TLS
Typically, when connecting to a cluster with TLS enabled the connection settings do not change. The client lib will automatically switch over to TLS 1.2. However, if you're using a self-signed certificate you may have to point to your local CA file using the tlsCaFile setting.
When connecting to a nats cluster that requires the client to provide TLS certificates use the tlsCertFile and tlsKeyFile to point at your local TLS certificate and private key file.
Nats Server documentation for:
Connection settings when connecting to a nats server that has TLS and TLS Client verify enabled.
Connecting with JWT
To use NKey with JWT, simply provide them in the Configuration
options as jwt
and nkey
.
You can also provide a credentials file with CredentialsParser
Publish Subscribe
Request Response
There is a simple wrapper over publish and feedback processing, so payload can be constructed manually same way.
JetStream Api Usage
Microservices
The services feature provides a simple way to create microservices that leverage NATS.
In the example below, you will see an example of creating an index function for the posts microservice. The request can be accessed under "v1.posts" and then individual post by "v1.posts.{post_id}".
Key Value Storage
Performance
Testing on AMD Ryzen 5 3600X with nats running in docker gives about 370k rps for publish and 360k rps for receive in non-verbose mode.
You can run tests on your environment.
Configuration Options
The following is the list of configuration options and default values.
Option | Default | Description |
---|---|---|
inboxPrefix |
"_INBOX" |
Sets de prefix for automatically created inboxes |
jwt |
Token for JWT Authentication. Alternatively you can use CredentialsParser | |
nkey |
Ed25519 based public key signature used for NKEY Authentication. | |
pass |
Sets the password for a connection. | |
pedantic |
false |
Turns on strict subject format checks. |
pingInterval |
2 |
Number of seconds between client-sent pings. |
port |
4222 |
Port to connect to (only used if servers is not specified). |
timeout |
1 | Number of seconds the client will wait for a connection to be established. |
token |
Sets a authorization token for a connection. | |
tlsHandshakeFirst |
false |
If true, the client performs the TLS handshake immediately after connecting, without waiting for the server’s INFO message. |
tlsKeyFile |
TLS 1.2 Client key file path. | |
tlsCertFile |
TLS 1.2 Client certificate file path. | |
tlsCaFile |
TLS 1.2 CA certificate filepath. | |
user |
Sets the username for a connection. | |
verbose |
false |
Turns on +OK protocol acknowledgements. |