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 dec34f353 [ISSUE 4346] Fix start error and some code optimization. 
(#4347)
dec34f353 is described below

commit dec34f35361eba180c74240d6b2a0df1429ad6da
Author: Alonexc <[email protected]>
AuthorDate: Fri Aug 11 09:34:13 2023 +0800

    [ISSUE 4346] Fix start error and some code optimization. (#4347)
    
    * fix start error and some code optimization.
    
    * fix code style
---
 .../eventmesh/grpc/sub/app/controller/SubController.java       |  3 ---
 .../org/apache/eventmesh/grpc/sub/app/service/SubService.java  |  9 ++++-----
 .../org/apache/eventmesh/http/demo/sub/service/SubService.java |  8 ++++----
 .../src/main/java/org/apache/eventmesh/util/Utils.java         | 10 ++++++++++
 .../protocol/cloudevents/CloudEventsProtocolAdaptor.java       |  3 +--
 5 files changed, 19 insertions(+), 14 deletions(-)

diff --git 
a/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/sub/app/controller/SubController.java
 
b/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/sub/app/controller/SubController.java
index af14e09af..fa9beb158 100644
--- 
a/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/sub/app/controller/SubController.java
+++ 
b/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/sub/app/controller/SubController.java
@@ -17,7 +17,6 @@
 
 package org.apache.eventmesh.grpc.sub.app.controller;
 
-import org.apache.eventmesh.common.protocol.http.common.ProtocolKey;
 import org.apache.eventmesh.common.utils.JsonUtils;
 import org.apache.eventmesh.grpc.sub.app.service.SubService;
 
@@ -43,9 +42,7 @@ public class SubController {
 
     @RequestMapping(value = "/test", method = RequestMethod.POST)
     public String subTest(final HttpServletRequest request) {
-        final String protocolType = 
request.getHeader(ProtocolKey.PROTOCOL_TYPE);
         final String content = request.getParameter("content");
-
         if (log.isInfoEnabled()) {
             log.info("=======receive message======= {}", content);
         }
diff --git 
a/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/sub/app/service/SubService.java
 
b/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/sub/app/service/SubService.java
index 99d840fa2..68fe873ef 100644
--- 
a/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/sub/app/service/SubService.java
+++ 
b/eventmesh-examples/src/main/java/org/apache/eventmesh/grpc/sub/app/service/SubService.java
@@ -21,6 +21,7 @@ import static 
org.apache.eventmesh.common.ExampleConstants.ENV;
 import static org.apache.eventmesh.common.ExampleConstants.IDC;
 import static org.apache.eventmesh.common.ExampleConstants.SERVER_PORT;
 import static org.apache.eventmesh.common.ExampleConstants.SUB_SYS;
+import static org.apache.eventmesh.util.Utils.getURL;
 
 import org.apache.eventmesh.client.grpc.config.EventMeshGrpcClientConfig;
 import org.apache.eventmesh.client.grpc.consumer.EventMeshGrpcConsumer;
@@ -28,7 +29,6 @@ import org.apache.eventmesh.common.ExampleConstants;
 import org.apache.eventmesh.common.protocol.SubscriptionItem;
 import org.apache.eventmesh.common.protocol.SubscriptionMode;
 import org.apache.eventmesh.common.protocol.SubscriptionType;
-import org.apache.eventmesh.common.utils.IPUtils;
 import org.apache.eventmesh.grpc.pub.eventmeshmessage.AsyncPublishInstance;
 import org.apache.eventmesh.util.Utils;
 
@@ -62,11 +62,10 @@ public class SubService implements InitializingBean {
         }
     }
 
-    private final String localIp = IPUtils.getLocalAddress();
     private final String localPort = properties.getProperty(SERVER_PORT);
     private final String eventMeshIp = 
properties.getProperty(ExampleConstants.EVENTMESH_IP);
     private final String eventMeshGrpcPort = 
properties.getProperty(ExampleConstants.EVENTMESH_GRPC_PORT);
-    private final String url = "http://"; + localIp + ":" + localPort + 
"/sub/test";
+    private final String url = getURL(localPort, "/sub/test");
 
     // CountDownLatch size is the same as messageSize in 
AsyncPublishInstance.java (Publisher)
     private final CountDownLatch countDownLatch = new 
CountDownLatch(AsyncPublishInstance.MESSAGE_SIZE);
@@ -114,7 +113,7 @@ public class SubService implements InitializingBean {
     @PreDestroy
     public void cleanup() {
         if (log.isInfoEnabled()) {
-            log.info("start destory ....");
+            log.info("start destroy....");
         }
 
         try {
@@ -129,7 +128,7 @@ public class SubService implements InitializingBean {
         }
 
         if (log.isInfoEnabled()) {
-            log.info("end destory.");
+            log.info("end destroy....");
         }
     }
 
diff --git 
a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/service/SubService.java
 
b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/service/SubService.java
index 88f66a874..1b4131a21 100644
--- 
a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/service/SubService.java
+++ 
b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/service/SubService.java
@@ -21,6 +21,7 @@ import static 
org.apache.eventmesh.common.ExampleConstants.ENV;
 import static org.apache.eventmesh.common.ExampleConstants.IDC;
 import static org.apache.eventmesh.common.ExampleConstants.SERVER_PORT;
 import static org.apache.eventmesh.common.ExampleConstants.SUB_SYS;
+import static org.apache.eventmesh.util.Utils.getURL;
 
 import org.apache.eventmesh.client.http.conf.EventMeshHttpClientConfig;
 import org.apache.eventmesh.client.http.consumer.EventMeshHttpConsumer;
@@ -66,11 +67,10 @@ public class SubService implements InitializingBean {
     @Override
     public void afterPropertiesSet() throws Exception {
         properties = 
Utils.readPropertiesFile(ExampleConstants.CONFIG_FILE_NAME);
-        final String localIP = IPUtils.getLocalAddress();
         final String localPort = properties.getProperty(SERVER_PORT);
         final String eventmeshIP = 
properties.getProperty(ExampleConstants.EVENTMESH_IP);
         final String eventmeshHttpPort = 
properties.getProperty(ExampleConstants.EVENTMESH_HTTP_PORT);
-        final String testURL = "http://"; + localIP + ":" + localPort + 
"/sub/test";
+        final String testURL = getURL(localPort, "/sub/test");
 
         final String eventMeshIPPort = eventmeshIP + ":" + eventmeshHttpPort;
         final EventMeshHttpClientConfig eventMeshClientConfig = 
EventMeshHttpClientConfig.builder()
@@ -103,7 +103,7 @@ public class SubService implements InitializingBean {
     @PreDestroy
     public void cleanup() {
         if (log.isInfoEnabled()) {
-            log.info("start destory ....");
+            log.info("start destroy....");
         }
 
         try {
@@ -121,7 +121,7 @@ public class SubService implements InitializingBean {
         }
 
         if (log.isInfoEnabled()) {
-            log.info("end destory.");
+            log.info("end destroy....");
         }
     }
 
diff --git 
a/eventmesh-examples/src/main/java/org/apache/eventmesh/util/Utils.java 
b/eventmesh-examples/src/main/java/org/apache/eventmesh/util/Utils.java
index 7e0ca9699..fead0db9b 100644
--- a/eventmesh-examples/src/main/java/org/apache/eventmesh/util/Utils.java
+++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/util/Utils.java
@@ -18,6 +18,7 @@
 package org.apache.eventmesh.util;
 
 import org.apache.eventmesh.common.ExampleConstants;
+import org.apache.eventmesh.common.utils.IPUtils;
 
 import org.apache.commons.lang3.SystemUtils;
 
@@ -92,4 +93,13 @@ public class Utils {
         }
     }
 
+    /**
+     * @param port server port
+     * @param path path
+     * @return url
+     */
+    public static String getURL(String port, String path) {
+        return "http://"; + IPUtils.getLocalAddress() + ":" + port + path;
+    }
+
 }
diff --git 
a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
 
b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
index 31103fda7..92c9710f0 100644
--- 
a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
+++ 
b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptor.java
@@ -87,7 +87,7 @@ public class CloudEventsProtocolAdaptor<T extends 
ProtocolTransportObject>
         org.apache.eventmesh.common.protocol.http.header.Header header,
         Body body) throws ProtocolHandleException {
 
-        switch (RequestCode.valueOf(requestCode)) {
+        switch (RequestCode.get(Integer.parseInt(requestCode))) {
             case MSG_BATCH_SEND:
                 return SendMessageBatchProtocolResolver.buildEvent(header, 
body);
             case MSG_BATCH_SEND_V2:
@@ -98,7 +98,6 @@ public class CloudEventsProtocolAdaptor<T extends 
ProtocolTransportObject>
             default:
                 throw new ProtocolHandleException(String.format("unsupported 
requestCode: %s", requestCode));
         }
-
     }
 
     @Override


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to