Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #4665] Optimize and sync recent new connectors' docs #4668

Merged
merged 12 commits into from
Dec 17, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ public class EventMeshMessageTest {

@Test
public void testGetProp() {
EventMeshMessage message = createLiteMessage();
EventMeshMessage message = createEventMeshMessage();
Assertions.assertEquals(2L, message.getProp().size());
}

@Test
public void testSetProp() {
EventMeshMessage message = createLiteMessage();
EventMeshMessage message = createEventMeshMessage();
Map<String, String> prop = new HashMap<>();
prop.put("key3", "value3");
message.setProp(prop);
Expand All @@ -43,27 +43,27 @@ public void testSetProp() {

@Test
public void testAddProp() {
EventMeshMessage message = createLiteMessage();
EventMeshMessage message = createEventMeshMessage();
message.addProp("key3", "value3");
Assertions.assertEquals(3L, message.getProp().size());
Assertions.assertEquals("value1", message.getProp("key1"));
}

@Test
public void testGetPropKey() {
EventMeshMessage message = createLiteMessage();
EventMeshMessage message = createEventMeshMessage();
Assertions.assertEquals("value1", message.getProp("key1"));
}

@Test
public void testRemoveProp() {
EventMeshMessage message = createLiteMessage();
EventMeshMessage message = createEventMeshMessage();
message.removePropIfPresent("key1");
Assertions.assertEquals(1L, message.getProp().size());
Assertions.assertNull(message.getProp("key1"));
}

private EventMeshMessage createLiteMessage() {
private EventMeshMessage createEventMeshMessage() {
Map<String, String> prop = new HashMap<>();
prop.put("key1", "value1");
prop.put("key2", "value2");
Expand Down
36 changes: 33 additions & 3 deletions eventmesh-connectors/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,52 @@

## Connector

A connector is a bridge that interacts with a specific external service or underlying data source (e.g., Databases) on behalf of user applications. A connector is either a Source or a Sink.
A connector is an image or instance that interacts with a specific external service or underlying data source (e.g., Databases) on behalf of user applications. A connector is either a Source or a Sink.

## Source

A source connector obtains data from an underlying data producer, and delivers it to targets after original data has been transformed into CloudEvents. It doesn't limit the way how a source retrieves data. (e.g., A source may pull data from a message queue or act as an HTTP server waiting for data sent to it).

CloudEvents is a specification for describing event data in common formats to provide interoperability across services, platforms and systems.

## Sink

A sink connector receives CloudEvents and does some specific business logics. (e.g., A MySQL Sink extracts useful data from CloudEvents and writes them to a MySQL database).

## CloudEvents

A specification for describing event data in common formats to provide interoperability across services, platforms and systems.

## Implements

Add a new connector by implementing the source/sink interface using [eventmesh-openconnect-java](https://github.com/apache/eventmesh/tree/master/eventmesh-openconnect/eventmesh-openconnect-java).

## Technical Solution

### Structure and process

![source-sink connector architecture](https://raw.githubusercontent.com/apache/eventmesh-site/master/static/images/design-document/connector-architecture.png)

### Design Detail

![eventmesh-connect-detail](https://raw.githubusercontent.com/apache/eventmesh-site/master/static/images/design-document/connector-design-detail.png)

### Description

#### Worker

Worker is divided into Source Worker and Sink Worker, which are triggered by the `Application` class and implement the methods of the `ConnectorWorker` interface respectively, which include the worker's running life cycle, and the worker carries the running of the connector. Workers can be lightweight and independent through mirroring Running, the eventmesh-sdk-java module is integrated internally, and the CloudEvents protocol is used to interact with EventMesh. Currently, the TCP client is used by default. In the future, support for dynamic configuration can be considered.

#### Connector

Connectors are divided into Source Connector and Sink Connector. Connectors have their own configuration files and run independently. Workers perform reflective loading and configuration analysis to complete Connector initialization and subsequent operation. Source Connector implements the poll method, and Sink Connector implements The put method uniformly uses `ConnectorRecord` to carry data. Both Source Connector and Sink Connector can operate independently.

#### ConnectorRecord with CloudEvents

`ConnectorRecord` is a connector layer data protocol. When workers interact with EventMesh, a protocol adapter needs to be developed to convert `ConnectorRecord` to CloudEvents protocol.

#### Registry

The Registry module is responsible for storing the synchronization progress of synchronizing data of different Connector instances, ensuring high availability between multiple Connector images or instances.

## Connector Status

| Connector Name | Source | Sink |
Expand Down
36 changes: 33 additions & 3 deletions eventmesh-connectors/README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,52 @@

## 连接器类型

一个连接器就是一座桥梁,代表用户应用程序与特定的外部服务或底层数据源(例如数据库)进行交互。连接器的类型可以是源(Source)或汇(Sink)。
连接器是代表用户应用程序与特定外部服务或底层数据源(例如数据库)交互的镜像或实例。连接器的类型可以是源(Source)或汇(Sink)。

## 数据源(Source 端)

源连接器从底层数据生产者获取数据,并在原始数据被转换为 CloudEvents 后将其传递给目标。源连接器不限制源如何检索数据(例如,源可以从消息队列中获取数据,也可以充当等待接收数据的 HTTP 服务器)。

CloudEvents 是一种以通用格式描述事件数据的规范,以提供服务、平台和系统之间的互操作性。

## 数据汇(Sink 端)

汇连接器接收 CloudEvents 并执行特定的业务逻辑(例如,MySQL 的汇连接器从 CloudEvents 中提取有用的数据,并将其写入 MySQL 数据库)。

## CloudEvents

CloudEvents 是一种以通用格式描述事件数据的规范,以提供服务、平台和系统之间的互操作性。

## 实现连接器

使用 [eventmesh-openconnect-java](https://github.com/apache/eventmesh/tree/master/eventmesh-openconnect/eventmesh-openconnect-java) 实现 Source/Sink 接口即可添加新的连接器。

## 技术方案

### 结构与处理流程

![source-sink connector architecture](https://raw.githubusercontent.com/apache/eventmesh-site/master/static/images/design-document/connector-architecture.png)

### 详细设计

![eventmesh-connect-detail](https://raw.githubusercontent.com/apache/eventmesh-site/master/static/images/design-document/connector-design-detail.png)

### 描述

#### Worker

Worker 分为 Source Worker 与 Sink Worker,由`Application`类进行触发运行,分别实现了`ConnectorWorker`接口的方法,其中包含了 worker 的运行生命周期,worker 承载了 connector 的运行。Worker 可以通过镜像的方式轻量的独立运行,内部集成了 eventmesh-sdk-java 模块,采用 CloudEvents 协议与 EventMesh 进行交互,目前默认采用 TCP 客户端,后续可以考虑支持动态可配。

#### Connector

Connector 分为 Source Connector 与 Sink Connector,connector 有各自的配置文件,以及独立运行的方式,通过 worker 进行反射加载与配置解析,完成 Connector 的初始化以及后续运行工作,其中 Source Connector 实现 poll 方法,Sink Connector 实现 put 方法,统一使用`ConnectorRecord`承载数据。Source Connector 与 Sink Connector 均可独立运行。

#### ConnectorRecord with CloudEvents

`ConnectorRecord`为 connector 层数据协议,当 worker 与 EventMesh 进行交互时需开发协议适配器进行`ConnectorRecord`到 CloudEvents 的协议转换。

#### Registry

`Registry`模块负责存储同步不同 Connector 实例的数据的同步进度,确保多个 Connector 镜像或实例之间的高可用。

## 连接器实现状态

| 连接器名称 | 源 | 汇 |
Expand Down
22 changes: 15 additions & 7 deletions eventmesh-connectors/eventmesh-connector-dingtalk/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# eventmesh-connector-dingtalk
# DingTalk

## DingtalkSinkConnector:from eventmesh to dingtalk。
## DingtalkSinkConnector: From EventMesh to DingTalk

1. launch your eventmesh-runtime.
1. launch your EventMesh Runtime.
2. enable sinkConnector and check `sink-config.yml`.
3. send a message to eventmesh with the topic defined in `pubSubConfig.subject`
3. send a message to EventMesh with the topic defined in `pubSubConfig.subject`

```yaml
pubSubConfig:
# default port is 10000
meshAddress: 127.0.0.1:10000
# default port 10000
meshAddress: your.eventmesh.server:10000
subject: TEST-TOPIC-DINGTALK
idc: FT
env: PRD
Expand All @@ -23,4 +24,11 @@ sinkConnectorConfig:
appSecret: dingTalkAppSecret
openConversationId: dingTalkOpenConversationId
robotCode: dingTalkRobotCode
```
```

### CloudEvent Attributes

When using the eventmesh-connector-dingtalk sinking event, you need to add the corresponding extension filed in CloudEvent:

- When key=`dingtalktemplatetype`, value=`text`/`markdown`, indicating the text type of the event.
- When text type is markdown, you can add extension: key=`dingtalkmarkdownmessagetitle`, value indicates the title of the event.
22 changes: 15 additions & 7 deletions eventmesh-connectors/eventmesh-connector-dingtalk/README_CN.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
# eventmesh-connector-dingtalk
# 钉钉

## DingtalkSinkConnector:从 eventmesh 到 dingtalk。
## DingtalkSinkConnector:从 EventMesh 到钉钉

1. 启动你的 eventmesh-runtime
1. 启动你的 EventMesh Runtime
2. 启用 sinkConnector 并检查 `sink-config.yml`。
3. 向 eventmesh 发送带有在 `pubSubConfig.subject` 中定义的主题消息。
3. 使用在 `pubSubConfig.subject` 中指定的 Topic,向 EventMesh 发送消息。

```yaml
pubSubConfig:
# 默认端口10000
meshAddress: 127.0.0.1:10000
# 默认端口 10000
meshAddress: your.eventmesh.server:10000
subject: TEST-TOPIC-DINGTALK
idc: FT
env: PRD
Expand All @@ -23,4 +24,11 @@ sinkConnectorConfig:
appSecret: dingTalkAppSecret
openConversationId: dingTalkOpenConversationId
robotCode: dingTalkRobotCode
```
```

### CloudEvent 属性

使用 eventmesh-connector-dingtalk 下沉事件时,需要在 CloudEvent 中添加对应的 extension filed:

- 当 key=`dingtalktemplatetype`时,value=`text`/`markdown`,表明该事件的文本类型。
- 当文本类型 `dingtalktemplatetype` 为 markdown 时,可以为文本设置标题。添加 extension:key=`dingtalkmarkdownmessagetitle`,value 为该事件的标题。
9 changes: 7 additions & 2 deletions eventmesh-connectors/eventmesh-connector-http/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# eventmesh-connector-http
# HTTP

## 1 HTTP Source Connector

Expand All @@ -14,27 +14,31 @@ Before using HTTP source connector, you need to configure the server.

### 1.2 Startup

1. start eventmesh-runtime
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 [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' \
Expand All @@ -47,6 +51,7 @@ curl --location --request POST 'http://localhost:3755/test' \
```

2. Sending a message in `structured` mode.

```shell
curl --location --request POST 'http://localhost:3755/test' \
--header 'Content-Type: application/cloudevents+json' \
Expand Down
24 changes: 15 additions & 9 deletions eventmesh-connectors/eventmesh-connector-http/README_CN.md
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
# eventmesh-connector-http
# 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, 不会发生超时。
- `connectorName`, connector 的名称
- (必需) `path`, 接口的路径
- (必需) `port`, 接口的端口
- `idleTimeout`, 空闲 TCP 连接超时时间,单位为秒。超过 `idleTimeout` 秒没有进行数据接收或发送的连接将会发生超时并被关闭。默认为 0, 不会发生超时。

### 1.2 启动

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

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

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

你可以通过 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`模式发送消息。
上述的例子在`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' \
Expand All @@ -46,6 +51,7 @@ curl --location --request POST 'http://localhost:3755/test' \
```

以`structured`模式发送消息。

```shell
curl --location --request POST 'http://localhost:3755/test' \
--header 'Content-Type: application/cloudevents+json' \
Expand Down
15 changes: 8 additions & 7 deletions eventmesh-connectors/eventmesh-connector-lark/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# eventmesh-connector-lark
# Feishu/Lark

## Lark Sink Server Config And Start

Before using eventmesh-connector-lark to sink events, you need to configure the server.
- Please customize `sinkEnable`=`true`/`false` in `/resource/server-config.yml` to turn on/off the sink function.

- Please customize `sinkEnable``=`true`/`false` in `/resource/server-config.yml` to turn on/off the sink function.
- Regarding `/resource/sink-config.yml`, only the configuration under `sinkConnectorConfig` is explained here:
- `connectorName`, specify the connector name
- (required) `appId`, the appId obtained from lark
Expand All @@ -14,22 +15,22 @@ Before using eventmesh-connector-lark to sink events, you need to configure the
- `maxRetryTimes`, the maximum number of retransmissions when the sink event fails. The default is 3 times.
- `retryDelayInMills`, when the sink event fails, the time interval for retransmitting the event. Default is 1s, unit is milliseconds.


## Sink CloudEvent To Lark

When using the eventmesh-connector-lark sinking event, you need to add the corresponding extension filed in CloudEvent:
- When key=`templatetype4lark`, value=`text`/`markdown`, indicating the text type of the event
- When the text type is markdown, you can add extension: key=`markdownmessagetitle4lark`, value indicates the title of the event.
- When key=`atusers4lark`, value=`id-0,name-0;id-1,name-1`, indicating that the event requires `@`certain users

- When key=`templatetype4lark`, value=`text`/`markdown`, indicating the text type of the event.
- When text type is markdown, you can add extension: key=`markdownmessagetitle4lark`, value indicates the title of the event.
- When key=`atusers4lark`, value=`id-0,name-0;id-1,name-1`, indicating that the event requires `@`certain users.
- It is recommended to use **open_id** for id.
- When the text is of text type, the id can be **open_id/union_id/user_id**; when the text is of markdown type, the id can be **open_id/user_id**. In particular, when the application type is [custom robot](https://open.larksuite.com/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN) and the text is of markdown type, only the use of **open_id** to `@` the user is supported.
- When the text is of text type and the id is invalid, name will be used instead for display; when the text is of markdown type and the id is invalid, an exception will be thrown directly (you should try to ensure the correctness of the id, and name can be considered omitted).
- When key=`atall4lark`, value=`true`/`false`, indicating that the event requires `@` everyone.


## Lark Open Platform API

For the Lark open platform API involved in this module, please click the following link:

- **Send Message**, please [view here](https://open.larksuite.com/document/server-docs/im-v1/message/create?appId=cli_a5e1bc31507ed00c)
- **text**, please [view here](https://open.larksuite.com/document/server-docs/im-v1/message-content-description/create_json#c9e08671)
- **markdown**, please [view here](https://open.larksuite.com/document/common-capabilities/message-card/message-cards-content/using-markdown-tags)
Loading
Loading