> For the complete documentation index, see [llms.txt](https://rocketmq-1.gitbook.io/rocketmq-connector/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rocketmq-1.gitbook.io/rocketmq-connector/rocketmq-connect/rocketmq-runtime/restful-jie-kou.md).

# RESTful 接口

connector 创建、启动、停止；集群的信息获取

## RESTful API

## &#x20;请求模板

<mark style="color:blue;">`GET`</mark> `http://{ip地址}:{port}/connectors/:connector-name?config=:config`

#### Path Parameters

| Name        | Type   | Description       |
| ----------- | ------ | ----------------- |
| ip地址        | string | runtime 运行的IP地址   |
| port        | string | 端口号，默认为8081       |
| connector名称 | string | 一个唯一的标识，stopAll除外 |

#### Query Parameters

| Name   | Type   | Description        |
| ------ | ------ | ------------------ |
| config | object | 　　connector实例的具体参数 |

{% tabs %}
{% tab title="200 返回结果" %}

```
success
```

{% endtab %}
{% endtabs %}

{% hint style="warning" %}
以下API为了表示方便，进行以下规定，具体的部署请对应设置请求模板即可

* **ip = localhost**
* **port = 8081**
* **connector-name = connector-example**
* **config = {**"connector-class":"org.apache.rocketmq.connect.file.FileSourceConnector","topic":"fileTopic","filename":"/opt/source-file/source-file.txt"**}**
  {% endhint %}

 更多Connector参数请具体参考对应Connector的设置说明

* 样例1 [file-connector参数说明](/rocketmq-connector/quick-start/file-connector.md#can-shu-shuo-ming)
* 样例2 [replicator参数说明](broken://pages/-LtPn_yhLjbKaKyEbTbL)

## 启动或创建一个connector

<mark style="color:blue;">`GET`</mark> `http://localhost:8081/connectors/:connector-name?config=:config`

**启动一个存在的connector或者创建一个新的connector并启动**\
注：这里将模板的参数已经赋值

#### Path Parameters

| Name           | Type   | Description                       |
| -------------- | ------ | --------------------------------- |
| connector-name | string | connector名称，如上文的connector-example |

#### Query Parameters

| Name   | Type   | Description              |
| ------ | ------ | ------------------------ |
| config | object | Connector具体参数,如上文的config |

{% tabs %}
{% tab title="200 返回结果" %}

```markup
<!-- 如果成功 -->
success

<!-- 如果存在同名Connector -->
Connector with same config already exist.

<!-- 失败 -->
fail
```

{% endtab %}
{% endtabs %}

## 停止一个connector

<mark style="color:blue;">`GET`</mark> `http://localhost:8081/connectors/:connector-name/stop`

**停止一个运行的connector并删除对应的设置**

#### Path Parameters

| Name           | Type   | Description |
| -------------- | ------ | ----------- |
| connector-name | string | connector名称 |

{% tabs %}
{% tab title="200 如果一个connector存在则停止删除，否则不进行操作" %}

```
success
```

{% endtab %}
{% endtabs %}

## 获取connector状态

<mark style="color:blue;">`GET`</mark> `http://localhost:8081/connectors/:connector-name/status`

获取一个connector的状态

#### Path Parameters

| Name           | Type   | Description |
| -------------- | ------ | ----------- |
| connector-name | string | connector名称 |

{% tabs %}
{% tab title="200 返回的状态有两种" %}

```markup
<!-- 如果在运行 -->
runing

<!-- 如果没在运行-->
not runing
```

{% endtab %}
{% endtabs %}

## 重新加载plugin目录下的Connector文件

<mark style="color:blue;">`GET`</mark> `http://localhost:8081/plugin/reload`

重新加载plugin目录下的Connector文件，用于在runtime运行过程中新增Connector实例

{% tabs %}
{% tab title="200 重新扫描plugin目录，加载类文件" %}

```
NFO qtp1564984895-14 - Loading plugin from: /usr/local/connector-plugins/rocketmq-replicator-0.1.0-SNAPSHOT.jar
2019-12-09 11:11:33 INFO qtp1564984895-14 - Loading plugin from: /usr/local/connector-plugins/rocketmq-connect-sample-0.0.1-SNAPSHOT.jar
```

{% endtab %}
{% endtabs %}

## 获取某个connector的配置信息

<mark style="color:blue;">`GET`</mark> `http://localhost:8081/connectors/:connector-name/config`

获取某个connector的配置信息

#### Path Parameters

| Name           | Type   | Description |
| -------------- | ------ | ----------- |
| connector-name | string | connector名称 |

{% tabs %}
{% tab title="200 获取某个connector的配置信息" %}

```
ConnectorConfigs:{"properties":{"xxx"}}
TaskConfigs:[{"properties":{"xxx"}}]
```

{% endtab %}
{% endtabs %}

## 停止并删除所有的connector和所有配置信息

<mark style="color:blue;">`GET`</mark> `http://localhost:8081/connectors/stopAll`

停止并删除所有的connector和所有配置信息

{% tabs %}
{% tab title="200 删除成功" %}

```
success
```

{% endtab %}
{% endtabs %}

## 获取所有connector和task配置信息&#x20;

<mark style="color:blue;">`GET`</mark> `http://localhost:8081/getConfigInfo`

获取所有的配置信息

{% tabs %}
{% tab title="200 获取到所有的配置信息" %}

```
ConnectorConfigs:{"xxx":{xxx}}
TaskConfigs:{"xxx":[xxx]}
```

{% endtab %}
{% endtabs %}

## 获取集群信息

<mark style="color:blue;">`GET`</mark> `http://localhost:8081/getClusterInfo`

获取集群信息

{% tabs %}
{% tab title="200 返回集群的具体信息" %}

```
["172.xx.2.1x@23953","172.xx.1x.x@53324"]
```

{% endtab %}
{% endtabs %}

## 获取负载信息

<mark style="color:blue;">`GET`</mark> `http://localhost:8081/getAllocatedInfo`

获取当前worker的负载信息

{% tabs %}
{% tab title="200 " %}

```
working connectors:{xxx}
working tasks:[xxx]
```

{% endtab %}
{% endtabs %}
