Skip to content

Commit

Permalink
feat(share connection): move connection.yaml into connections folder
Browse files Browse the repository at this point in the history
Signed-off-by: Jianxiang Ran <rxan_embedded@163.com>
  • Loading branch information
superrxan authored and ngjaying committed Oct 21, 2021
1 parent c488f27 commit 7dbd431
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 103 deletions.
36 changes: 19 additions & 17 deletions docs/en_US/rules/sources/edgex.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,37 +89,39 @@ The port of EdgeX message bus, default value is ``5573``.

### connectionSelector

specify the stream to reuse the connection to EdgeX message bus. The connection profile located in ``connection.yaml``.
specify the stream to reuse the connection to EdgeX message bus. The connection profile located in ``connections/connection.yaml``.
```yaml
mqtt:
mqtt_conf1: #connection key
servers: [tcp://127.0.0.1:1883]
username: ekuiper
password: password
#certificationPath: /var/kuiper/xyz-certificate.pem
#privateKeyPath: /var/kuiper/xyz-private.pem.key
#insecureSkipVerify: false
#protocolVersion: 3
clientid: ekuiper
mqtt_conf2: #connection key
servers: ["tcp://127.0.0.1:1883"]

edgex:
edgex_conf1: #connection key
redisMsgBus: #connection key
protocol: redis
server: 127.0.0.1
port: 6379
type: redis
# Below is optional configurations settings for mqtt
# type: mqtt
# optional:
# ClientId: client1
# Username: user1
# Password: password
# Qos: 1
# KeepAlive: 5000
# Retained: true/false
# ConnectionPayload:
# CertFile:
# KeyFile:
# CertPEMBlock:
# KeyPEMBlock:
# SkipCertVerify: true/false
```
There is one configuration group for EdgeX message bus in the example, user need use ``edgex.edgex_conf1`` as the selector.
There is one configuration group for EdgeX message bus in the example, user need use ``edgex.redisMsgBus`` as the selector.
For example
```yaml
#Global Edgex configurations
default:
protocol: tcp
server: localhost
port: 5573
connectionSelector: edgex.edgex_conf1
connectionSelector: edgex.redisMsgBus
topic: events
messageType: event
# optional:
Expand Down
26 changes: 13 additions & 13 deletions docs/en_US/rules/sources/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ The location of private key path. It can be an absolute path, or a relative path

### connectionSelector

specify the stream to reuse the connection to mqtt broker. The connection profile located in ``connection.yaml``.
specify the stream to reuse the connection to mqtt broker. The connection profile located in ``connections/connection.yaml``.
```yaml
mqtt:
mqtt_conf1: #connection key
localConnection: #connection key
servers: [tcp://127.0.0.1:1883]
username: ekuiper
password: password
Expand All @@ -63,17 +63,17 @@ mqtt:
#insecureSkipVerify: false
#protocolVersion: 3
clientid: ekuiper
mqtt_conf2: #connection key
servers: ["tcp://127.0.0.1:1883"]

edgex:
edgex_conf1: #connection key
protocol: redis
server: 127.0.0.1
port: 6379
type: redis
cloudConnection: #connection key
servers: ["tcp://broker.emqx.io:1883"]
username: user1
password: password
#certificationPath: /var/kuiper/xyz-certificate.pem
#privateKeyPath: /var/kuiper/xyz-private.pem.ke
#insecureSkipVerify: false
#protocolVersion: 3

```
There are two configuration groups for mqtt in the example, user need use ``mqtt.mqtt_conf1`` or ``mqtt.mqtt_conf2`` as the selector.
There are two configuration groups for mqtt in the example, user need use ``mqtt.localConnection`` or ``mqtt.cloudConnection`` as the selector.
For example
```yaml
#Global MQTT configurations
Expand All @@ -84,7 +84,7 @@ default:
#password: password
#certificationPath: /var/kuiper/xyz-certificate.pem
#privateKeyPath: /var/kuiper/xyz-private.pem.key
connectionSelector: mqtt.mqtt_conf1
connectionSelector: mqtt.localConnection
```
*Note*: once specify the connectionSelector in specific configuration group , all connection related parameters will be ignored , in this case ``servers: [tcp://127.0.0.1:1883]``
Expand Down
36 changes: 19 additions & 17 deletions docs/zh_CN/rules/sources/edgex.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,38 @@ EdgeX 消息总线的端口,缺省为 `5573`

## connectionSelector

复用 EdgeX 源连接。连接配置信息位于 ``connection.yaml``.
复用 EdgeX 源连接。连接配置信息位于 ``connections/connection.yaml``.
```yaml
mqtt:
mqtt_conf1: #connection key
servers: [tcp://127.0.0.1:1883]
username: ekuiper
password: password
#certificationPath: /var/kuiper/xyz-certificate.pem
#privateKeyPath: /var/kuiper/xyz-private.pem.key
#insecureSkipVerify: false
#protocolVersion: 3
clientid: ekuiper
mqtt_conf2: #connection key
servers: ["tcp://127.0.0.1:1883"]

edgex:
edgex_conf1: #connection key
redisMsgBus: #connection key
protocol: redis
server: 127.0.0.1
port: 6379
type: redis
# Below is optional configurations settings for mqtt
# type: mqtt
# optional:
# ClientId: client1
# Username: user1
# Password: password
# Qos: 1
# KeepAlive: 5000
# Retained: true/false
# ConnectionPayload:
# CertFile:
# KeyFile:
# CertPEMBlock:
# KeyPEMBlock:
# SkipCertVerify: true/false
```
对于 EdgeX 连接,这里有一个配置组。用户应该使用 ``edgex.edgex_conf1`` 来作为参数。举例如下:
对于 EdgeX 连接,这里有一个配置组。用户应该使用 ``edgex.redisMsgBus`` 来作为参数。举例如下:
```yaml
#Global Edgex configurations
default:
protocol: tcp
server: localhost
port: 5573
connectionSelector: edgex.edgex_conf1
connectionSelector: edgex.redisMsgBus
topic: events
messageType: event
```
Expand Down
25 changes: 12 additions & 13 deletions docs/zh_CN/rules/sources/mqtt.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ MQTT 连接密码。如果指定了 `certificationPath` 或者 `privateKeyPath`

### connectionSelector

复用 MQTT 源连接。连接配置信息位于 ``connection.yaml``.
复用 MQTT 源连接。连接配置信息位于 ``connections/connection.yaml``.
```yaml
mqtt:
mqtt_conf1: #connection key
localConnection: #connection key
servers: [tcp://127.0.0.1:1883]
username: ekuiper
password: password
Expand All @@ -63,17 +63,16 @@ mqtt:
#insecureSkipVerify: false
#protocolVersion: 3
clientid: ekuiper
mqtt_conf2: #connection key
servers: ["tcp://127.0.0.1:1883"]
edgex:
edgex_conf1: #connection key
protocol: redis
server: 127.0.0.1
port: 6379
type: redis
cloudConnection: #connection key
servers: ["tcp://broker.emqx.io:1883"]
username: user1
password: password
#certificationPath: /var/kuiper/xyz-certificate.pem
#privateKeyPath: /var/kuiper/xyz-private.pem.ke
#insecureSkipVerify: false
#protocolVersion: 3
```
对于 MQTT 连接,这里有两个配置组。用户应该使用 ``mqtt.mqtt_conf1`` 或者 ``mqtt.mqtt_conf2`` 来作为参数。举例如下:
对于 MQTT 连接,这里有两个配置组。用户应该使用 ``mqtt.localConnection`` 或者 ``mqtt.cloudConnection`` 来作为参数。举例如下:
```yaml
#Global MQTT configurations
default:
Expand All @@ -83,7 +82,7 @@ default:
#password: password
#certificationPath: /var/kuiper/xyz-certificate.pem
#privateKeyPath: /var/kuiper/xyz-private.pem.key
connectionSelector: mqtt.mqtt_conf
connectionSelector: mqtt.localConnection
```
*注意*: 相应配置组一旦指定 connectionSelector 参数,所有关于连接的参数都会被忽略. 上面例子中,`` servers: [tcp://127.0.0.1:1883]`` 会被忽略。

Expand Down
25 changes: 20 additions & 5 deletions etc/connection.yaml → etc/connections/connection.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mqtt:
mqtt_conf1: #connection key
localConnection: #connection key
servers: [tcp://127.0.0.1:1883]
username: ekuiper
password: password
Expand All @@ -8,11 +8,18 @@ mqtt:
#insecureSkipVerify: false
#protocolVersion: 3
clientid: ekuiper
mqtt_conf2: #connection key
servers: ["tcp://127.0.0.1:1883"]
cloudConnection: #connection key
servers: ["tcp://broker.emqx.io:1883"]
username: user1
password: password
#certificationPath: /var/kuiper/xyz-certificate.pem
#privateKeyPath: /var/kuiper/xyz-private.pem.ke
#insecureSkipVerify: false
#protocolVersion: 3


edgex:
edgex_conf1: #connection key
redisMsgBus: #connection key
protocol: redis
server: 127.0.0.1
port: 6379
Expand All @@ -31,4 +38,12 @@ edgex:
# KeyFile:
# CertPEMBlock:
# KeyPEMBlock:
# SkipCertVerify: true/false
# SkipCertVerify: true/false
mqttMsgBus: #connection key
protocol: tcp
server: 127.0.0.1
port: 1883
topic: events
type: mqtt
optional:
ClientId: "client1"
8 changes: 5 additions & 3 deletions internal/topo/connection/connect_selector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

var SUPPORTE_CONTYPE = []string{"mqtt", "edgex"}

const CONNECTION_CONF = "connections/connection.yaml"

type ConSelector struct {
ConnSelectorCfg string

Expand All @@ -24,8 +26,8 @@ func (c *ConSelector) Init() error {
if len(conTypeSel) != 2 {
return fmt.Errorf("not a valid connection selector : %s", c.ConnSelectorCfg)
}
c.Type = conTypeSel[0]
c.CfgKey = conTypeSel[1]
c.Type = strings.ToLower(conTypeSel[0])
c.CfgKey = strings.ToLower(conTypeSel[1])
return nil
}

Expand All @@ -36,7 +38,7 @@ func (c *ConSelector) ReadCfgFromYaml() (props map[string]interface{}, err error
)

cfg := make(map[string]interface{})
err = conf.LoadConfigByName("connection.yaml", &cfg)
err = conf.LoadConfigByName(CONNECTION_CONF, &cfg)
if err != nil {
return nil, err
}
Expand Down
Loading

0 comments on commit 7dbd431

Please sign in to comment.