From e9d51d341a0d6fb5764c5bd4289b22f78b4400dd Mon Sep 17 00:00:00 2001 From: Fungx <38498093+Fungx@users.noreply.github.com> Date: Thu, 28 Dec 2023 19:12:54 +0800 Subject: [PATCH] Add http connector docs (#169) --- .../03-connect/04-http-connector.md | 67 +++++++++++++++++++ .../03-connect/04-http-connector.md | 67 +++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 docs/design-document/03-connect/04-http-connector.md create mode 100644 i18n/zh/docusaurus-plugin-content-docs/current/design-document/03-connect/04-http-connector.md diff --git a/docs/design-document/03-connect/04-http-connector.md b/docs/design-document/03-connect/04-http-connector.md new file mode 100644 index 0000000000..3aeeb5b82a --- /dev/null +++ b/docs/design-document/03-connect/04-http-connector.md @@ -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" +}' +``` diff --git a/i18n/zh/docusaurus-plugin-content-docs/current/design-document/03-connect/04-http-connector.md b/i18n/zh/docusaurus-plugin-content-docs/current/design-document/03-connect/04-http-connector.md new file mode 100644 index 0000000000..95287d5c9e --- /dev/null +++ b/i18n/zh/docusaurus-plugin-content-docs/current/design-document/03-connect/04-http-connector.md @@ -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" +}' +``` \ No newline at end of file