Skip to content

Commit 8f4726c

Browse files
committed
update README.md
1 parent db0718f commit 8f4726c

File tree

2 files changed

+53
-57
lines changed

2 files changed

+53
-57
lines changed

README-CN.md

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ while ($running) {
247247
## Schema
248248

249249
- 目前只支持 `INT8``INT16``INT32``INT64``DOUBLE``STRING``JSON`,以下代码以 `JSON Schema` 为示例
250+
- https://avro.apache.org/docs/1.11.1/specification/
251+
- https://pulsar.apache.org/docs/2.11.x/schema-overview/
250252

251253
- `model.php`
252254

@@ -262,21 +264,40 @@ class Person
262264
}
263265
```
264266

265-
- Consumer Statement Schema
267+
- 生产者配置`Schema`
266268

267-
```php
269+
```php
270+
<?php
271+
$define = '{"type":"record","name":"Person","fields":[{"name":"id","type":"int"},{"name":"name","type":"string"},{"name":"age","type":"int"}]}';
272+
$schema = new \Pulsar\Schema\SchemaJson($define, [
273+
'key' => 'value',
274+
]);
275+
276+
// ... some code
277+
$producerOptions->setSchema($schema);
278+
$producer = new \Pulsar\Producer('xx',$options);
279+
$producer->connect();
268280

269-
// JSON schema
270-
// @see https://avro.apache.org/docs/1.11.1/specification/
271-
// @see https://pulsar.apache.org/docs/2.11.x/schema-overview/
281+
$person = new Person();
282+
$person->id = 1;
283+
$person->name = 'Tony';
284+
$person->age = 18;
272285

286+
// 可以直接发送 $person 对象
287+
$id = $producer->send($person);
288+
```
289+
290+
- 消费者配置`Schema`
291+
292+
```php
293+
<?php
273294
$define = '{"type":"record","name":"Person","fields":[{"name":"id","type":"int"},{"name":"name","type":"string"},{"name":"age","type":"int"}]}';
274295

275296
$schema = new \Pulsar\Schema\SchemaJson($define, [
276297
'key' => 'value',
277298
]);
278299

279-
// ... some code
300+
// ... 省略一些初始化的代码
280301
$consumerOptions->setSchema($schema);
281302
$consumer = new \Pulsar\Consumer('pulsar://xxx',$consumerOptions);
282303
$consumer->connect();
@@ -298,29 +319,6 @@ while (true) {
298319

299320
```
300321

301-
- Producer Statement Schema
302-
303-
```php
304-
305-
$define = '{"type":"record","name":"Person","fields":[{"name":"id","type":"int"},{"name":"name","type":"string"},{"name":"age","type":"int"}]}';
306-
$schema = new \Pulsar\Schema\SchemaJson($define, [
307-
'key' => 'value',
308-
]);
309-
310-
// ... some code
311-
$producerOptions->setSchema($schema);
312-
$producer = new \Pulsar\Producer('xx',$options);
313-
$producer->connect();
314-
315-
$person = new Person();
316-
$person->id = 1;
317-
$person->name = 'Tony';
318-
$person->age = 18;
319-
320-
// directly send Person Object No need to manually convert to json string
321-
$id = $producer->send($person);
322-
```
323-
324322
## Reader
325323

326324
```php

README.md

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,8 @@ while ($running) {
251251

252252
- Currently only supports `INT8``INT16``INT32``INT64``DOUBLE``STRING``JSON`,The following code uses `JSON Schema`
253253
as an example
254+
- https://avro.apache.org/docs/1.11.1/specification/
255+
- https://pulsar.apache.org/docs/2.11.x/schema-overview/
254256

255257
- `model.php`
256258

@@ -266,14 +268,33 @@ class Person
266268
}
267269
```
268270

269-
- Consumer Statement Schema
271+
- Producer Statement Schema
270272

271-
```php
273+
```php
274+
<?php
275+
$define = '{"type":"record","name":"Person","fields":[{"name":"id","type":"int"},{"name":"name","type":"string"},{"name":"age","type":"int"}]}';
276+
$schema = new \Pulsar\Schema\SchemaJson($define, [
277+
'key' => 'value',
278+
]);
272279

273-
// JSON schema
274-
// @see https://avro.apache.org/docs/1.11.1/specification/
275-
// @see https://pulsar.apache.org/docs/2.11.x/schema-overview/
280+
// ... some code
281+
$producerOptions->setSchema($schema);
282+
$producer = new \Pulsar\Producer('xx',$options);
283+
$producer->connect();
276284

285+
$person = new Person();
286+
$person->id = 1;
287+
$person->name = 'Tony';
288+
$person->age = 18;
289+
290+
// directly send Person Object No need to manually convert to json string
291+
$id = $producer->send($person);
292+
```
293+
294+
- Consumer Statement Schema
295+
296+
```php
297+
<?php
277298
$define = '{"type":"record","name":"Person","fields":[{"name":"id","type":"int"},{"name":"name","type":"string"},{"name":"age","type":"int"}]}';
278299

279300
$schema = new \Pulsar\Schema\SchemaJson($define, [
@@ -302,29 +323,6 @@ while (true) {
302323

303324
```
304325

305-
- Producer Statement Schema
306-
307-
```php
308-
309-
$define = '{"type":"record","name":"Person","fields":[{"name":"id","type":"int"},{"name":"name","type":"string"},{"name":"age","type":"int"}]}';
310-
$schema = new \Pulsar\Schema\SchemaJson($define, [
311-
'key' => 'value',
312-
]);
313-
314-
// ... some code
315-
$producerOptions->setSchema($schema);
316-
$producer = new \Pulsar\Producer('xx',$options);
317-
$producer->connect();
318-
319-
$person = new Person();
320-
$person->id = 1;
321-
$person->name = 'Tony';
322-
$person->age = 18;
323-
324-
// directly send Person Object No need to manually convert to json string
325-
$id = $producer->send($person);
326-
```
327-
328326
## Reader
329327

330328
```php

0 commit comments

Comments
 (0)