Skip to content

Commit 3e5176e

Browse files
committed
README.md
1 parent 915596c commit 3e5176e

File tree

2 files changed

+73
-2
lines changed

2 files changed

+73
-2
lines changed

README-CN.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,31 @@ while ($running) {
281281
}
282282
```
283283

284+
## TLS
285+
286+
- 证书配置请参考[官方文档](https://pulsar.apache.org/docs/next/security-tls-transport/)
287+
288+
- 示例
289+
290+
```php
291+
$tls = new \Pulsar\TLSOptions('./cert.pem','./cert.key.pem');
292+
293+
// CA Cert
294+
$tls->setTrustCertsFilePath('./ca.cart.pem');
295+
296+
// optional
297+
$tls->setAllowInsecureConnection(false);
298+
$tls->setValidateHostname(true);
299+
$options->setTLS($tls);
300+
301+
$consumer = new \Pulsar\Consumer('pulsar+ssl://localhost:6651',$options);
302+
//$producer = new \Pulsar\Producer('pulsar+ssl://localhost:6651',$options);
303+
304+
// or https
305+
$consumer = new \Pulsar\Consumer('https://localhost:8081',$options);
306+
//$producer = new \Pulsar\Producer('https://localhost:8081',$options);
307+
```
308+
284309
## Schema
285310

286311
- 目前只支持 `INT8``INT16``INT32``INT64``DOUBLE``STRING``JSON`,以下代码以 `JSON Schema` 为示例
@@ -436,6 +461,11 @@ $reader->close();
436461
* DELAY_SECONDS
437462
* SEQUENCE_ID
438463
* PROPERTIES
464+
* TLSOption (v1.3.0)
465+
* __construct(string $certFilePath, string $keyFilePath)
466+
* setTrustCertsFilePath()
467+
* setValidateHostname()
468+
* setAllowInsecureConnection()
439469

440470
## MessageNotFound 错误码(v1.2.1)
441471

README.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [Installation](#Installation)
99
* [Producer](#Producer)
1010
* [Consumer](#Consumer)
11+
* [TLS](#TLS)
1112
* [Schema](#Schema)
1213
* [Reader](#Reader)
1314
* [Options](#Options)
@@ -47,6 +48,7 @@ composer require ikilobyte/pulsar-client-php
4748
```php
4849
<?php
4950

51+
use Pulsar\Authentication\Basic;
5052
use Pulsar\Authentication\Jwt;
5153
use Pulsar\Compression\Compression;
5254
use Pulsar\Producer;
@@ -58,9 +60,12 @@ require_once __DIR__ . '/vendor/autoload.php';
5860
$options = new ProducerOptions();
5961

6062
// If permission authentication is available
61-
// Only JWT authentication is currently supported
63+
// use JWT authentication
6264
$options->setAuthentication(new Jwt('token'));
6365

66+
// use Basic authentication
67+
//$options->setAuthentication(new Basic('user','password'));
68+
6469
$options->setConnectTimeout(3);
6570
$options->setTopic('persistent://public/default/demo');
6671
$options->setCompression(Compression::ZLIB);
@@ -141,6 +146,7 @@ $producer->send('body',[
141146
<?php
142147

143148
use Pulsar\Authentication\Jwt;
149+
use Pulsar\Authentication\Basic;
144150
use Pulsar\Consumer;
145151
use Pulsar\ConsumerOptions;
146152
use Pulsar\SubscriptionType;
@@ -151,9 +157,12 @@ require_once __DIR__ . '/vendor/autoload.php';
151157
$options = new ConsumerOptions();
152158

153159
// If permission authentication is available
154-
// Only JWT authentication is currently supported
160+
// use JWT authentication
155161
$options->setAuthentication(new Jwt('token'));
156162

163+
// use Basic authentication
164+
//$options->setAuthentication(new Basic('user','password'));
165+
157166
$options->setConnectTimeout(3);
158167
$options->setTopic('persistent://public/default/demo');
159168
$options->setSubscription('logic');
@@ -282,6 +291,33 @@ while ($running) {
282291
}
283292
```
284293

294+
## TLS
295+
296+
- Refer to the official [documentation](https://pulsar.apache.org/docs/next/security-tls-transport/) for certificate
297+
configuration
298+
299+
- Example
300+
301+
```php
302+
$tls = new \Pulsar\TLSOptions('./cert.pem','./cert.key.pem');
303+
304+
// CA Cert
305+
$tls->setTrustCertsFilePath('./ca.cart.pem');
306+
307+
// optional
308+
$tls->setAllowInsecureConnection(false);
309+
$tls->setValidateHostname(true);
310+
$options->setTLS($tls);
311+
312+
$consumer = new \Pulsar\Consumer('pulsar+ssl://localhost:6651',$options);
313+
//$producer = new \Pulsar\Producer('pulsar+ssl://localhost:6651',$options);
314+
315+
316+
// or https
317+
$consumer = new \Pulsar\Consumer('https://localhost:8081',$options);
318+
//$producer = new \Pulsar\Producer('https://localhost:8081',$options);
319+
```
320+
285321
## Schema
286322

287323
- Currently only supports `INT8``INT16``INT32``INT64``DOUBLE``STRING``JSON`,The following code uses `JSON Schema`
@@ -439,6 +475,11 @@ $reader->close();
439475
* DELAY_SECONDS
440476
* SEQUENCE_ID
441477
* PROPERTIES
478+
* TLSOption (v1.3.0)
479+
* __construct(string $certFilePath, string $keyFilePath)
480+
* setTrustCertsFilePath()
481+
* setValidateHostname()
482+
* setAllowInsecureConnection()
442483

443484
## MessageNotFound ErrCode (v1.2.1)
444485

0 commit comments

Comments
 (0)