Skip to content

Commit

Permalink
add http docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Fungx committed Dec 16, 2023
1 parent b85a58c commit 9e5833f
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 0 deletions.
60 changes: 60 additions & 0 deletions eventmesh-connectors/eventmesh-connector-http/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# eventmesh-connector-http

## 1 HTTP Source Connector

### 1.1 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.

### 1.2 Startup

1. start eventmesh-runtime
2. start eventmesh-connector-http

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

### 1.3 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 [coudevent-spec](https://github.com/cloudevents/spec/blob/v1.0.2/cloudevents/bindings/http-protocol-binding.md).

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'
```

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"
}'
```
59 changes: 59 additions & 0 deletions eventmesh-connectors/eventmesh-connector-http/README_CN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# eventmesh-connector-http

## 1 HTTP Source Connector

### 1.1 配置
使用 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.2 启动

1. 启动 eventmesh-runtime
2. 启动 eventmesh-connector-http

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

### 1.3 发送消息
你可以通过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`模式发送消息。(`batched`模式仍未支持)

以`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 9e5833f

Please sign in to comment.