Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
starsz committed Sep 30, 2022
1 parent abdb95e commit 2d8f189
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
9 changes: 1 addition & 8 deletions apisix/plugins/kafka-logger.lua
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ function _M.log(conf, ctx)
end

-- reuse producer via lrucache to avoid unbalanced partitions of messages in kafka
local length = conf.broker_list and core.table.nkeys(conf.broker_list) or #conf.brokers
local broker_list = core.table.new(length, 0)
local broker_list = core.table.clone(conf.brokers or {})
local broker_config = {}

if conf.broker_list then
Expand All @@ -239,12 +238,6 @@ function _M.log(conf, ctx)
end
end

if conf.broker then
for _, broker in ipairs(conf.brokers) do
core.table.insert(broker_list, broker)
end
end

broker_config["request_timeout"] = conf.timeout * 1000
broker_config["producer_type"] = conf.producer_type
broker_config["required_acks"] = conf.required_acks
Expand Down
2 changes: 1 addition & 1 deletion docs/en/latest/plugins/kafka-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ It might take some time to receive the log data. It will be automatically sent a

| Name | Type | Required | Default | Valid values | Description |
| ---------------------- | ------- | -------- | -------------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| broker_list | deprecated | True | | | Use `brokers` instead. List of Kafka brokers. (nodes). |
| broker_list | object | True | | | Deprecated, use `brokers` instead. List of Kafka brokers. (nodes). |
| brokers | array | True | | | List of Kafka brokers (nodes). |
| brokers.host | string | True | | | The host of Kafka broker, e.g, `192.168.1.1`. |
| brokers.port | integer | True | | [0, 65535] | The port of Kafka broker |
Expand Down
29 changes: 20 additions & 9 deletions docs/zh/latest/plugins/kafka-logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ description: API 网关 Apache APISIX 的 kafka-logger 插件用于将日志作

| 名称 | 类型 | 必选项 | 默认值 | 有效值 | 描述 |
| ---------------------- | ------- | ------ | -------------- | --------------------- | ------------------------------------------------ |
| broker_list | object || | | 需要推送的 Kafka 的 broker 列表。 |
| broker_list | object || | | 已废弃,使用 brokers 代替。需要推送的 Kafka 的 broker 列表。 |
| brokers | array || | | 需要推送的 Kafka 的 broker 列表。 |
| brokers.host | string || | | Kafka broker 的节点 host 配置, 例如 `192.168.1.1` |
| brokers.port | string || | | Kafka broker 的节点端口配置 |
| kafka_topic | string || | | 需要推送的 topic。 |
| producer_type | string || async | ["async", "sync"] | 生产者发送消息的模式。 |
| required_acks | integer || 1 | [0, 1, -1] | 生产者在确认一个请求发送完成之前需要收到的反馈信息的数量。该参数是为了保证发送请求的可靠性。该属性的配置与 Kafka `acks` 属性相同,具体配置请参考 [Apache Kafka 文档](https://kafka.apache.org/documentation/#producerconfigs_acks)|
Expand Down Expand Up @@ -162,10 +165,12 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \
{
"plugins": {
"kafka-logger": {
"broker_list" :
{
"127.0.0.1":9092
},
"brokers" : [
{
"host": "127.0.0.1",
"port": 9092
}
],
"kafka_topic" : "test2",
"key" : "key1"
}
Expand All @@ -183,10 +188,16 @@ curl http://127.0.0.1:9180/apisix/admin/routes/1 \
该插件还支持一次推送到多个 Broker,示例如下:

```json
{
"127.0.0.1":9092,
"127.0.0.1":9093
}
"brokers" : [
{
"host" :"127.0.0.1",
"port" : 9092
},
{
"host" :"127.0.0.1",
"port" : 9093
}
],
```

## 测试插件
Expand Down

0 comments on commit 2d8f189

Please sign in to comment.