Skip to content

Commit

Permalink
add docs http
Browse files Browse the repository at this point in the history
  • Loading branch information
Fungx committed Dec 28, 2023
1 parent 3a4ecc2 commit 1935a59
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 0 deletions.
67 changes: 67 additions & 0 deletions docs/design-document/03-connect/04-http-connector.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# HTTP

## HTTP Source Connector

### Configuration

Before using HTTP source connector, you need to configure the server.
- Please configure `sourceEnable` to `true` in `/resource/server-config.yml` to enable source functionality.
- Please configure the source connector in `/resource/source-config.yml`, only the configuration under `connectorConfig` is described here:
- `connectorName`, name of the connector.
- (required) `path`, path of the API.
- (required) `port`, port of the API.
- `idleTimeout`, idle TCP connection timeout in seconds. A connection will timeout and be closed if no data is received nor sent within the `idleTimeout` seconds. The default is 0, which means don't timeout.

### Startup

1. start EventMesh Runtime
2. start eventmesh-connector-http

When finished, the HTTP source connector will act as an HTTP server.

### Sending messages

You can send messages to the source connector via HTTP.

```yaml
connectorConfig:
connectorName: httpSource
path: /test
port: 3755
idleTimeout: 5
```
The above example configures a URL `http://localhost:3755/test` in `source-config.yml`.

You can send messages in `binary` mode or `structured` mode as specified in [cloudevent-spec](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/http-protocol-binding.md).

Here are two examples:

1. Sending a message in `binary` mode.

```shell
curl --location --request POST 'http://localhost:3755/test' \
--header 'ce-id: 1' \
--header 'ce-specversion: 1.0' \
--header 'ce-type: com.example.someevent' \
--header 'ce-source: /mycontext' \
--header 'ce-subject: test_topic' \
--header 'Content-Type: text/plain' \
--data-raw 'testdata'
```

2. Sending a message in `structured` mode.

```shell
curl --location --request POST 'http://localhost:3755/test' \
--header 'Content-Type: application/cloudevents+json' \
--data-raw '{
"id": "1",
"specversion": "1.0",
"type": "com.example.someevent",
"source": "/mycontext",
"subject":"test_topic",
"datacontenttype":"text/plain",
"data": "testdata"
}'
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# HTTP

## HTTP Source Connector

### 配置

使用 HTTP source connector 前,需要进行 server 的配置。
- 请在 `/resource/server-config.yml` 中配置 `sourceEnable``true` 以开启 source 功能。
- 请在 `/resource/source-config.yml`中配置 source connector, 在此仅说明 `connectorConfig` 下的配置:
- `connectorName`, connector 的名称
- (必需) `path`, 接口的路径
- (必需) `port`, 接口的端口
- `idleTimeout`, 空闲 TCP 连接超时时间,单位为秒。超过 `idleTimeout` 秒没有进行数据接收或发送的连接将会发生超时并被关闭。默认为 0, 不会发生超时。

### 启动

1. 启动 EventMesh Runtime
2. 启动 eventmesh-connector-http

完成后,HTTP source connector 会作为一个 HTTP 服务器对外提供服务。

### 发送消息

你可以通过 HTTP 向 source connector 发送消息。

```yaml
connectorConfig:
connectorName: httpSource
path: /test
port: 3755
idleTimeout: 5
```
上述的例子在`source-config.yml`中配置了一个 URL `http://localhost:3755/test`.

你可以按照 [cloudevent-spec](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/http-protocol-binding.md) 中的规定,以`binary`模式或者`structured`模式发送消息。

这里是两个例子:

以`binary`模式发送消息。

```shell
curl --location --request POST 'http://localhost:3755/test' \
--header 'ce-id: 1' \
--header 'ce-specversion: 1.0' \
--header 'ce-type: com.example.someevent' \
--header 'ce-source: /mycontext' \
--header 'ce-subject: test_topic' \
--header 'Content-Type: text/plain' \
--data-raw 'testdata'
```

以`structured`模式发送消息。

```shell
curl --location --request POST 'http://localhost:3755/test' \
--header 'Content-Type: application/cloudevents+json' \
--data-raw '{
"id": "1",
"specversion": "1.0",
"type": "com.example.someevent",
"source": "/mycontext",
"subject":"test_topic",
"datacontenttype":"text/plain",
"data": "testdata"
}'
```

0 comments on commit 1935a59

Please sign in to comment.