Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
qiqizjl committed Aug 18, 2021
1 parent 1bc9736 commit 3f6f8d5
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.cn.md
Expand Up @@ -21,8 +21,8 @@ PHP Kafka 客户端,支持 PHP-FPM、Swoole 环境使用。
- [x] PHP-FPM、Swoole 智能环境识别兼容
- [x] 生产者类
- [x] 消费者类
- [x] SASL 鉴权
- [ ] SSL 加密通信
- [ ] SASL 鉴权
- [ ] 更多功能的封装及测试用例编写

## 环境要求
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -21,8 +21,8 @@ The communication protocol is based on the JSON file in Java. PHP Kafka client s
- [x] PHP-FPM and Swoole compatible
- [x] Producer
- [x] Consumer
- [x] SASL
- [ ] SSL
- [ ] SASL
- [ ] More features and test cases

## Environment
Expand Down
26 changes: 26 additions & 0 deletions doc/consumer.en.md
Expand Up @@ -40,6 +40,7 @@ Class `longlang\phpkafka\Consumer\ConsumerConfig`
| minBytes | Min bytes | `1` |
| maxBytes | Max bytes | `128 * 1024 * 1024` |
| maxWait | The maximum time. (unit: second, decimal) | `1` |
| sasl | SASL authentication Info. If the field is null, it will not authenticate with SASL [detail](#SASL-Support) | `[]`|

## Asynchronous (callback)

Expand Down Expand Up @@ -90,3 +91,28 @@ while(true) {
sleep(1);
}
```

## SASL Support
### Configuration
| Key | Description | Default |
| - | - | - |
| type | SASL Authentication Type. PLAIN is ``\longlang\phpkafka\Sasl\PlainSasl::class``| ''|
| username | username | '' |
| password | password | '' |

**Example**
```php
use longlang\phpkafka\Consumer\Consumer;
use longlang\phpkafka\Consumer\ConsumerConfig;

$config = new ConsumerConfig();
// .... Your Othor Config
$config->setSasl([
"type"=>\longlang\phpkafka\Sasl\PlainSasl::class,
"username"=>"admin",
"password"=>"admin-secret"
]);
$consumer = new Consumer($config);
// .... Your Business Code
```

25 changes: 25 additions & 0 deletions doc/consumer.md
Expand Up @@ -40,6 +40,7 @@
| minBytes | 最小字节数 | `1` |
| maxBytes | 最大字节数 | `128 * 1024 * 1024` |
| maxWait | 最大等待时间,单位:秒 | `1` |
| sasl | SASL身份认证信息。为空则不发送身份认证信息 [详情](#SASL支持) | `[]`|

## 异步消费(回调)

Expand Down Expand Up @@ -90,3 +91,27 @@ while(true) {
sleep(1);
}
```

## SASL支持
### 相关配置
|参数名|说明|默认值|
| - | - | - |
| type | SASL授权对应的类。PLAIN为``\longlang\phpkafka\Sasl\PlainSasl::class``| ''|
| username | 账号 | '' |
| password | 密码 | '' |

**代码示例:**
```php
use longlang\phpkafka\Consumer\Consumer;
use longlang\phpkafka\Consumer\ConsumerConfig;

$config = new ConsumerConfig();
// .... 你的其他配置
$config->setSasl([
"type"=>\longlang\phpkafka\Sasl\PlainSasl::class,
"username"=>"admin",
"password"=>"admin-secret"
]);
$consumer = new Consumer($config);
// .... 你的业务代码
```
24 changes: 24 additions & 0 deletions doc/producer.en.md
Expand Up @@ -29,6 +29,7 @@ Class `longlang\phpkafka\Producer\ProducerConfig`
| partitioner | Partitioning strategy | Default: `\longlang\phpkafka\Producer\Partitioner\DefaultPartitioner` |
| produceRetry | Produce message retries allowed if matching an error code. | `3` |
| produceRetrySleep | Produce message retry sleep time. (unit: second) | `0.1` |
| sasl | SASL authentication Info. If the field is null, it will not authenticate with SASL [detail](#SASL-Support) | `[]`|

**Default partitioning strategy:**

Expand Down Expand Up @@ -79,3 +80,26 @@ $producer->sendBatch([
new ProduceMessage($topic, 'v2', 'k2', $partition1),
]);
```

## SASL Support
### Configuration
| Key | Description | Default |
| - | - | - |
| type | SASL Authentication Type. PLAIN is ``\longlang\phpkafka\Sasl\PlainSasl::class``| ''|
| username | username | '' |
| password | password | '' |

**Example**
```php
use longlang\phpkafka\Producer\ProducerConfig;

$config = new ProducerConfig();
// .... Your Other Config
$config->setSasl([
"type"=>\longlang\phpkafka\Sasl\PlainSasl::class,
"username"=>"admin",
"password"=>"admin-secret"
]);
$producer = new Producer($config);
// .... Your Business Code
```
26 changes: 26 additions & 0 deletions doc/producer.md
Expand Up @@ -29,6 +29,7 @@
| partitioner | 分区策略 | 默认策略:`\longlang\phpkafka\Producer\Partitioner\DefaultPartitioner` |
| produceRetry | 生产消息,匹配预设的错误码时,自动重试次数 | `3` |
| produceRetrySleep | 生产消息重试延迟,单位:秒 | `0.1` |
| sasl | SASL身份认证信息。为空则不发送身份认证信息 [详情](#SASL支持) | `[]`|

**默认分区策略:**

Expand Down Expand Up @@ -79,3 +80,28 @@ $producer->sendBatch([
new ProduceMessage($topic, 'v2', 'k2', $partition1),
]);
```



## SASL支持
### 相关配置
|参数名|说明|默认值|
| - | - | - |
| type | SASL授权对应的类。PLAIN为``\longlang\phpkafka\Sasl\PlainSasl::class``| ''|
| username | 账号 | '' |
| password | 密码 | '' |

**代码示例:**
```php
use longlang\phpkafka\Producer\ProducerConfig;

$config = new ProducerConfig();
// .... 你的其他配置
$config->setSasl([
"type"=>\longlang\phpkafka\Sasl\PlainSasl::class,
"username"=>"admin",
"password"=>"admin-secret"
]);
$producer = new Producer($config);
// .... 你的业务代码
```
4 changes: 3 additions & 1 deletion src/Config/CommonConfig.php
Expand Up @@ -182,8 +182,10 @@ public function getSasl(): array
return $this->sasl;
}

public function setSasl(array $sasl): void
public function setSasl(array $sasl): self
{
$this->sasl = $sasl;

return $this;
}
}
4 changes: 1 addition & 3 deletions tests/TestUtil.php
Expand Up @@ -24,7 +24,7 @@ public static function getHost(): string

public static function getPort(): int
{
return (int) (getenv('KAFKA_PORT') ?: 9090);
return (int) (getenv('KAFKA_PORT') ?: 9092);
}

public static function getSasl(): array
Expand All @@ -50,8 +50,6 @@ public static function createKafkaClient(string $class = null): ClientInterface
public static function getControllerClient(): ClientInterface
{
$client = self::createKafkaClient();
//$client->getConfig()->setSa
//sl([]);
$client->connect();
$request = new MetadataRequest();
/** @var MetadataResponse $response */
Expand Down

0 comments on commit 3f6f8d5

Please sign in to comment.