Skip to content

Commit

Permalink
feat: add support for Psr18ClientDiscovery (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
EJTJ3 authored Jan 13, 2024
1 parent 1d64472 commit 69bbfb2
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
35 changes: 33 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
## WORK IN PROGRESS!!
<h1 align="center">Nats monitoring</h1>

<p align="center">
<img src="https://www.gitbook.com/cdn-cgi/image/width=36,dpr=2,height=36,fit=contain,format=auto/https%3A%2F%2F683899388-files.gitbook.io%2F~%2Ffiles%2Fv0%2Fb%2Fgitbook-legacy-files%2Fo%2Fspaces%252F-LqMYcZML1bsXrN3Ezg0%252Favatar.png%3Fgeneration%3D1571848018902627%26alt%3Dmedia">
</p>

<p align="center">
<img src="http://poser.pugx.org/ejtj3/nats-monitoring/v" alt="Latest Stable Version">
<img src="http://poser.pugx.org/ejtj3/nats-monitoring/downloads" alt="Total Downloads">
<img src="http://poser.pugx.org/ejtj3/nats-monitoring/license" alt="License">
</p>

# Nats monitoring

```shell
$ composer require ejtj3/nats-monitoring jms/serializer
```

```php
use EJTJ3\NatsMonitoring\Jms\Serializer\Handler\NatsDateImmutableHandler;
use EJTJ3\NatsMonitoring\Jms\Serializer\Handler\NatsDateIntervalHandler;
Expand All @@ -10,6 +25,7 @@ use JMS\Serializer\Handler\HandlerRegistry;
use JMS\Serializer\SerializerBuilder;
use Symfony\Component\HttpClient\Psr18Client;

// build serializer
$serializerBuilder = new SerializerBuilder();
$serializerBuilder->configureHandlers(static function (HandlerRegistry $registry): void {
$registry->registerSubscribingHandler(new NatsDateIntervalHandler());
Expand All @@ -26,5 +42,20 @@ $requestOptions = new ConnectionRequest();
$requestOptions->setAuth(true);

$connections = $client->getConnections('https://demo.nats.io:8222', $requestOptions);
```

## Available methods

| Name | Route | Method |
|---------------|:---------:|-----------------------------------------------------------------------:|
| General | /varz | `$client->getGeneralSettings('https://demo.nats.io:8222')` |
| Jetstream | /jsz | `$client->getJetstream('https://demo.nats.io:8222')` |
| Connections | /connz | `$client->getConnections('https://demo.nats.io:8222')` |
| Accounts | /accountz | `$client->getAccounts('https://demo.nats.io:8222')` |
| Account stats | /accstatz | `$client->getAccountStats('https://demo.nats.io:8222')` |
| Subscriptions | /subsz | `$client->getSubscriptions('https://demo.nats.io:8222')` |
| Routes | /routez | `$client->getRoutez('https://demo.nats.io:8222')` |
| Leafnodes | /leafz | `$client->getLeafnodes('https://demo.nats.io:8222')` |
| Gateways | /gatewayz | Not yet implemented |
| HealthProbe | /leafz | `$client->getHealth('https://demo.nats.io:8222')` |

```
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
"jms/serializer": "^3.0",
"psr/http-client": "^1.0",
"php-http/discovery": "^1.19",
"nyholm/psr7": "^1.8"
"psr/http-factory": "^1.0"
},
"require-dev": {
"symfony/var-dumper": "^6.3",
"jms/serializer": "3.28.0",
"symfony/http-client": "6.4.*",
"phpunit/phpunit": "^10.0",
"friendsofphp/php-cs-fixer": "^3.41",
"phpstan/phpstan": "^1.10",
"phpro/grumphp-shim": "^2.3"
"phpro/grumphp-shim": "^2.3",
"nyholm/psr7": "^1.8"
},
"config": {
"allow-plugins": {
Expand Down
8 changes: 5 additions & 3 deletions src/NatsMonitoringClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use EJTJ3\NatsMonitoring\Model\LeafnodeResponse;
use EJTJ3\NatsMonitoring\Model\RoutesResponse;
use EJTJ3\NatsMonitoring\Model\SubscriptionResponse;
use Http\Discovery\Psr18ClientDiscovery;
use JMS\Serializer\SerializerInterface;
use Psr\Http\Client\ClientExceptionInterface;
use Psr\Http\Client\ClientInterface;
Expand All @@ -39,11 +40,14 @@ final class NatsMonitoringClient

private const ROUTE_LEAFNODE = 'leafz';

private readonly ClientInterface $client;

public function __construct(
private readonly SerializerInterface $serializer,
private readonly ClientInterface $client,
ClientInterface $client = null,
private readonly RequestBuilder $requestBuilder = new RequestBuilder(),
) {
$this->client = $client ?? Psr18ClientDiscovery::find();
}

/**
Expand All @@ -62,8 +66,6 @@ public function getLeafnodes(string $server): LeafnodeResponse
return $this->doRequest($server, self::ROUTE_LEAFNODE, LeafnodeResponse::class);
}

/// ALLES HIER ONDER MOT NOG

public function getRoutez(string $server): RoutesResponse
{
return $this->doRequest($server, self::ROUTE_ROUTEZ, RoutesResponse::class);
Expand Down

0 comments on commit 69bbfb2

Please sign in to comment.