This is an automated email from the ASF dual-hosted git repository.
mikexue pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new 013512bd7 [ISSUE#4552] Add example for spring connector sdk. (#4553)
013512bd7 is described below
commit 013512bd7a29e6c9e910b8b7f0f3f806189249de
Author: yanrongzhen <[email protected]>
AuthorDate: Mon Nov 13 16:06:33 2023 +0800
[ISSUE#4552] Add example for spring connector sdk. (#4553)
* Feat: Add example for spring.
* fix: Remove exclude configuration.
* fix: fix log
---
eventmesh-examples/build.gradle | 1 +
.../spring/SpringBootDemoApplication.java | 29 ++++++++++
.../eventmesh/spring/pub/SpringPubController.java | 62 ++++++++++++++++++++++
.../eventmesh/spring/sub/SpringSubHandler.java | 34 ++++++++++++
.../src/main/resources/server-config.yml | 19 +++++++
.../src/main/resources/sink-config.yml | 28 ++++++++++
.../src/main/resources/source-config.yml | 28 ++++++++++
7 files changed, 201 insertions(+)
diff --git a/eventmesh-examples/build.gradle b/eventmesh-examples/build.gradle
index 91a3a2b8b..9ef70836b 100644
--- a/eventmesh-examples/build.gradle
+++ b/eventmesh-examples/build.gradle
@@ -25,6 +25,7 @@ dependencies {
implementation project(":eventmesh-sdks:eventmesh-sdk-java")
implementation project(":eventmesh-common")
implementation project(":eventmesh-storage-plugin:eventmesh-storage-api")
+ implementation project(":eventmesh-connectors:eventmesh-connector-spring")
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'io.netty:netty-all'
implementation "io.cloudevents:cloudevents-core"
diff --git
a/eventmesh-examples/src/main/java/org/apache/eventmesh/spring/SpringBootDemoApplication.java
b/eventmesh-examples/src/main/java/org/apache/eventmesh/spring/SpringBootDemoApplication.java
new file mode 100644
index 000000000..954deb070
--- /dev/null
+++
b/eventmesh-examples/src/main/java/org/apache/eventmesh/spring/SpringBootDemoApplication.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.spring;
+
+import org.springframework.boot.SpringApplication;
+import org.springframework.boot.autoconfigure.SpringBootApplication;
+
+@SpringBootApplication
+public class SpringBootDemoApplication {
+
+ public static void main(String[] args) {
+ SpringApplication.run(SpringBootDemoApplication.class, args);
+ }
+}
diff --git
a/eventmesh-examples/src/main/java/org/apache/eventmesh/spring/pub/SpringPubController.java
b/eventmesh-examples/src/main/java/org/apache/eventmesh/spring/pub/SpringPubController.java
new file mode 100644
index 000000000..b7ea8890e
--- /dev/null
+++
b/eventmesh-examples/src/main/java/org/apache/eventmesh/spring/pub/SpringPubController.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.spring.pub;
+
+import org.apache.eventmesh.common.utils.JsonUtils;
+import
org.apache.eventmesh.connector.spring.source.connector.SpringSourceConnector;
+import org.apache.eventmesh.openconnect.api.callback.SendExcepionContext;
+import org.apache.eventmesh.openconnect.api.callback.SendMessageCallback;
+import org.apache.eventmesh.openconnect.api.callback.SendResult;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RestController;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@RestController
+@RequestMapping("/spring")
+public class SpringPubController {
+
+ @Autowired
+ private SpringSourceConnector springSourceConnector;
+
+ @RequestMapping("/pub")
+ public String publish() {
+ final Map<String, String> content = new HashMap<>();
+ content.put("content", "testSpringPublishMessage");
+ springSourceConnector.send(JsonUtils.toJSONString(content), new
SendMessageCallback() {
+
+ @Override
+ public void onSuccess(SendResult sendResult) {
+ log.info("Spring source worker send message to EventMesh
success! msgId={}, topic={}",
+ sendResult.getMessageId(), sendResult.getTopic());
+ }
+
+ @Override
+ public void onException(SendExcepionContext sendExcepionContext) {
+ log.info("Spring source worker send message to EventMesh
failed!", sendExcepionContext.getCause());
+ }
+ });
+ return "success!";
+ }
+}
diff --git
a/eventmesh-examples/src/main/java/org/apache/eventmesh/spring/sub/SpringSubHandler.java
b/eventmesh-examples/src/main/java/org/apache/eventmesh/spring/sub/SpringSubHandler.java
new file mode 100644
index 000000000..0dba81acf
--- /dev/null
+++
b/eventmesh-examples/src/main/java/org/apache/eventmesh/spring/sub/SpringSubHandler.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.eventmesh.spring.sub;
+
+import org.apache.eventmesh.connector.spring.sink.EventMeshListener;
+
+import org.springframework.stereotype.Component;
+
+import lombok.extern.slf4j.Slf4j;
+
+@Slf4j
+@Component
+public class SpringSubHandler {
+
+ @EventMeshListener
+ public void onMessage(String message) {
+ log.info("[SPRING--MESSAGE-RECEIVED], data={}", message);
+ }
+}
diff --git a/eventmesh-examples/src/main/resources/server-config.yml
b/eventmesh-examples/src/main/resources/server-config.yml
new file mode 100644
index 000000000..5f66dd0f6
--- /dev/null
+++ b/eventmesh-examples/src/main/resources/server-config.yml
@@ -0,0 +1,19 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+sourceEnable: true
+sinkEnable: true
diff --git a/eventmesh-examples/src/main/resources/sink-config.yml
b/eventmesh-examples/src/main/resources/sink-config.yml
new file mode 100644
index 000000000..e49b73b98
--- /dev/null
+++ b/eventmesh-examples/src/main/resources/sink-config.yml
@@ -0,0 +1,28 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+pubSubConfig:
+ meshAddress: 127.0.0.1:10000
+ subject: TEST-TOPIC-SPRING
+ idc: FT
+ env: PRD
+ group: springSink
+ appId: 5033
+ userName: springSinkUser
+ passWord: springPassWord
+sinkConnectorConfig:
+ connectorName: springSink
diff --git a/eventmesh-examples/src/main/resources/source-config.yml
b/eventmesh-examples/src/main/resources/source-config.yml
new file mode 100644
index 000000000..db7dd9f91
--- /dev/null
+++ b/eventmesh-examples/src/main/resources/source-config.yml
@@ -0,0 +1,28 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+pubSubConfig:
+ meshAddress: 127.0.0.1:10000
+ subject: TEST-TOPIC-SPRING
+ idc: FT
+ env: PRD
+ group: springSource
+ appId: 5033
+ userName: springSourceUser
+ passWord: springPassWord
+sourceConnectorConfig:
+ connectorName: springSource
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]