diff --git a/README.md b/README.md index e176173aae..70a32fc7da 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Apache EventMesh (incubating) +# Apache EventMesh (incubating) [![CI status](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml/badge.svg)](https://github.com/apache/incubator-eventmesh/actions/workflows/ci.yml) [![CodeCov](https://codecov.io/gh/apache/incubator-eventmesh/branch/develop/graph/badge.svg)](https://codecov.io/gh/apache/incubator-eventmesh) [![Language grade: Java](https://img.shields.io/lgtm/grade/java/g/apache/incubator-eventmesh.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/apache/incubator-eventmesh/context:java) @@ -16,12 +16,14 @@ EventMesh(incubating) is a dynamic event-driven application runtime used to deco **Multi-runtime:** ![architecture1](docs/images/eventmesh-arch3.png) + **Orchestration:** ![architecture1](docs/images/eventmesh-orchestration.png) **Federation:** ![architecture1](docs/images/eventmesh-federation.png) + **Components:** * **eventmesh-runtime** : an middleware to transmit events between event producers and consumers, support cloud native apps and microservices. @@ -71,4 +73,4 @@ Mailing Lists: | ---- | ---- |---- | ---- | ---- | |Users |User support and questions mailing list| [Subscribe](mailto:users-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:users-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?users@eventmesh.apache.org)| |Development |Development related discussions| [Subscribe](mailto:dev-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:dev-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?dev@eventmesh.apache.org)| -|Commits |All commits to repositories| [Subscribe](mailto:commits-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:commits-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?commits@eventmesh.apache.org)| +|Commits |All commits to repositories| [Subscribe](mailto:commits-subscribe@eventmesh.incubator.apache.org) |[Unsubscribe](mailto:commits-unsubscribe@eventmesh.incubator.apache.org) |[Mail Archives](https://lists.apache.org/list.html?commits@eventmesh.apache.org)| \ No newline at end of file diff --git a/build.gradle b/build.gradle index fbd2269a60..307c53e8e7 100644 --- a/build.gradle +++ b/build.gradle @@ -29,7 +29,7 @@ buildscript { } dependencies { - classpath "gradle.plugin.com.github.spotbugs.snom:spotbugs-gradle-plugin:4.7.1" + classpath "com.github.spotbugs.snom:spotbugs-gradle-plugin:5.0.3" classpath "io.spring.gradle:dependency-management-plugin:1.0.11.RELEASE" classpath "com.github.jk1:gradle-license-report:1.17" } diff --git a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/controller/AdminController.java b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/controller/AdminController.java index 8932afd5cb..76027a1006 100644 --- a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/controller/AdminController.java +++ b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/controller/AdminController.java @@ -34,9 +34,9 @@ public AdminController() { } public void run(HttpServer server) throws IOException { - + server.createContext("/topicmanage", new TopicsHandler()); - + logger.info("EventMesh-Admin Controller server context created successfully"); } } diff --git a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/handler/TopicsHandler.java b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/handler/TopicsHandler.java index 345f4bca30..84e1ae5840 100644 --- a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/handler/TopicsHandler.java +++ b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/handler/TopicsHandler.java @@ -60,23 +60,23 @@ public void createTopicHandler(HttpExchange httpExchange) throws IOException { try { String params = NetUtils.parsePostBody(httpExchange); TopicCreateRequest topicCreateRequest = - JsonUtils.toObject(params, TopicCreateRequest.class); + JsonUtils.toObject(params, TopicCreateRequest.class); String topic = topicCreateRequest.getName(); - + if (StringUtils.isBlank(topic)) { result = "Create topic failed. Parameter topic not found."; logger.error(result); out.write(result.getBytes()); return; } - + //TBD: A new rocketmq service will be implemented for creating topics TopicResponse topicResponse = null; if (topicResponse != null) { - logger.info("create a new topic: {}", topic); + logger.info("create a new topic: {}", topic); httpExchange.getResponseHeaders().add("Content-Type", "appication/json"); httpExchange.sendResponseHeaders(200, 0); - result = JsonUtils.toJson(topicResponse); + result = JsonUtils.toJson(topicResponse); logger.info(result); out.write(result.getBytes()); return; @@ -89,7 +89,7 @@ public void createTopicHandler(HttpExchange httpExchange) throws IOException { } } catch (Exception e) { httpExchange.getResponseHeaders().add("Content-Type", "appication/json"); - httpExchange.sendResponseHeaders(500, 0); + httpExchange.sendResponseHeaders(500, 0); result = String.format("create topic failed! Server side error"); logger.error(result); out.write(result.getBytes()); diff --git a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/response/TopicResponse.java b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/response/TopicResponse.java index 1dde496bcb..41b6e6a9b2 100644 --- a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/response/TopicResponse.java +++ b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/response/TopicResponse.java @@ -27,7 +27,7 @@ public class TopicResponse { @JsonCreator public TopicResponse(@JsonProperty("topic") String topic, - @JsonProperty("created_time") String createdTime) { + @JsonProperty("created_time") String createdTime) { super(); this.topic = topic; this.createdTime = createdTime; @@ -51,12 +51,12 @@ public String getCreatedTime() { @JsonProperty("created_time") public void setCreatedTime(String createdTime) { this.createdTime = createdTime; - } + } @Override public String toString() { StringBuilder sb = new StringBuilder(); - sb.append("TopicResponse {topic=" + this.topic + ","); + sb.append("TopicResponse {topic=" + this.topic + ","); sb.append("created_time=" + this.createdTime + "}"); return sb.toString(); } diff --git a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/JsonUtils.java b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/JsonUtils.java index 69455c5db5..f502cf179e 100644 --- a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/JsonUtils.java +++ b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/JsonUtils.java @@ -25,15 +25,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -public class JsonUtils { +public class JsonUtils { - private static ObjectMapper objectMapper; + private static ObjectMapper objectMapper; static { - objectMapper = new ObjectMapper(); + objectMapper = new ObjectMapper(); objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); objectMapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); + objectMapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS); } public static byte[] serialize(String topic, Class data) throws JsonProcessingException { @@ -47,7 +47,7 @@ public static String toJson(Object obj) throws JsonProcessingException { if (obj == null) { return null; } - return objectMapper.writeValueAsString(obj); + return objectMapper.writeValueAsString(obj); } public static T toObject(String json, Class clazz) throws JsonProcessingException { diff --git a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/NetUtils.java b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/NetUtils.java index c6c7992d2e..0feedb2d81 100644 --- a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/NetUtils.java +++ b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/NetUtils.java @@ -30,14 +30,14 @@ public class NetUtils { private static final Logger logger = LoggerFactory.getLogger(NetUtils.class); - + public static String parsePostBody(HttpExchange exchange) throws IOException { StringBuilder body = new StringBuilder(); if ("post".equalsIgnoreCase(exchange.getRequestMethod()) - || "put".equalsIgnoreCase(exchange.getRequestMethod())) { - try (InputStreamReader reader = - new InputStreamReader(exchange.getRequestBody(), Consts.UTF_8)) { + || "put".equalsIgnoreCase(exchange.getRequestMethod())) { + try (InputStreamReader reader = + new InputStreamReader(exchange.getRequestBody(), Consts.UTF_8)) { char[] buffer = new char[256]; int read; while ((read = reader.read(buffer)) != -1) { diff --git a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/RequestMapping.java b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/RequestMapping.java index b093d3e9f3..174f33d4a0 100644 --- a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/RequestMapping.java +++ b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/RequestMapping.java @@ -19,10 +19,10 @@ import com.sun.net.httpserver.HttpExchange; -public class RequestMapping { +public class RequestMapping { - public static boolean postMapping(String value, HttpExchange httpExchange) { - if ("post".equalsIgnoreCase(httpExchange.getRequestMethod())) { + public static boolean postMapping(String value, HttpExchange httpExchange) { + if ("post".equalsIgnoreCase(httpExchange.getRequestMethod())) { String requestUri = httpExchange.getRequestURI().getPath(); UrlMappingPattern matcher = new UrlMappingPattern(value); return matcher.matches(requestUri); @@ -30,8 +30,8 @@ public static boolean postMapping(String value, HttpExchange httpExchange) { return false; } - public static boolean getMapping(String value, HttpExchange httpExchange) { - if ("get".equalsIgnoreCase(httpExchange.getRequestMethod())) { + public static boolean getMapping(String value, HttpExchange httpExchange) { + if ("get".equalsIgnoreCase(httpExchange.getRequestMethod())) { String requestUri = httpExchange.getRequestURI().getPath(); UrlMappingPattern matcher = new UrlMappingPattern(value); return matcher.matches(requestUri); @@ -39,8 +39,8 @@ public static boolean getMapping(String value, HttpExchange httpExchange) { return false; } - public static boolean putMapping(String value, HttpExchange httpExchange) { - if ("put".equalsIgnoreCase(httpExchange.getRequestMethod())) { + public static boolean putMapping(String value, HttpExchange httpExchange) { + if ("put".equalsIgnoreCase(httpExchange.getRequestMethod())) { String requestUri = httpExchange.getRequestURI().getPath(); UrlMappingPattern matcher = new UrlMappingPattern(value); return matcher.matches(requestUri); @@ -48,8 +48,8 @@ public static boolean putMapping(String value, HttpExchange httpExchange) { return false; } - public static boolean deleteMapping(String value, HttpExchange httpExchange) { - if ("delete".equalsIgnoreCase(httpExchange.getRequestMethod())) { + public static boolean deleteMapping(String value, HttpExchange httpExchange) { + if ("delete".equalsIgnoreCase(httpExchange.getRequestMethod())) { String requestUri = httpExchange.getRequestURI().getPath(); UrlMappingPattern matcher = new UrlMappingPattern(value); return matcher.matches(requestUri); diff --git a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/UrlMappingPattern.java b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/UrlMappingPattern.java index 0e31b13ca1..09d0eb3d67 100644 --- a/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/UrlMappingPattern.java +++ b/eventmesh-admin/eventmesh-admin-rocketmq/src/main/java/org/apache/eventmesh/admin/rocketmq/util/UrlMappingPattern.java @@ -29,8 +29,8 @@ public class UrlMappingPattern { private static final String URL_PARAMETER_REGEX = "\\{(\\w*?)\\}"; - private static final String URL_PARAMETER_MATCH_REGEX = - "\\([%\\\\w-.\\\\~!\\$&'\\\\(\\\\)\\\\*\\\\+,;=:\\\\[\\\\]@]+?\\)"; + private static final String URL_PARAMETER_MATCH_REGEX = + "\\([%\\\\w-.\\\\~!\\$&'\\\\(\\\\)\\\\*\\\\+,;=:\\\\[\\\\]@]+?\\)"; private static final Pattern URL_PARAMETER_PATTERN = Pattern.compile(URL_PARAMETER_REGEX); @@ -74,8 +74,8 @@ public boolean matches(String url) { public void compile() { acquireParamNames(); - String parsedPattern = - getUrlMappingPattern().replaceFirst(URL_FORMAT_REGEX, URL_FORMAT_MATCH_REGEX); + String parsedPattern = + getUrlMappingPattern().replaceFirst(URL_FORMAT_REGEX, URL_FORMAT_MATCH_REGEX); parsedPattern = parsedPattern.replaceAll(URL_PARAMETER_REGEX, URL_PARAMETER_MATCH_REGEX); this.compiledUrlMappingPattern = Pattern.compile(parsedPattern + URL_QUERY_STRING_REGEX); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/ThreadPoolFactory.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/ThreadPoolFactory.java index 319673d247..3e3831c3c1 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/ThreadPoolFactory.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/ThreadPoolFactory.java @@ -42,7 +42,7 @@ public static ThreadPoolExecutor createThreadPoolExecutor(int core, int max, fin public static ThreadPoolExecutor createThreadPoolExecutor(int core, int max, BlockingQueue blockingQueue, final String threadName, final boolean isDaemon) { return new ThreadPoolExecutor(core, max, 10 * 1000, TimeUnit.MILLISECONDS, blockingQueue, - new ThreadFactoryBuilder().setNameFormat(threadName).setDaemon(isDaemon).build() + new ThreadFactoryBuilder().setNameFormat(threadName).setDaemon(isDaemon).build() ); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java index 33e9ce950e..7f483a7891 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/CommonConfiguration.java @@ -17,10 +17,11 @@ package org.apache.eventmesh.common.config; -import com.google.common.base.Preconditions; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.eventmesh.common.utils.IPUtils; + +import com.google.common.base.Preconditions; public class CommonConfiguration { public String eventMeshEnv = "P"; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigurationWrapper.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigurationWrapper.java index c9e01d081e..b1eaac311b 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigurationWrapper.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/config/ConfigurationWrapper.java @@ -17,11 +17,9 @@ package org.apache.eventmesh.common.config; -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.ThreadPoolFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.BufferedReader; import java.io.File; @@ -31,6 +29,11 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Preconditions; + public class ConfigurationWrapper { public Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -64,8 +67,7 @@ public void run() { private void load() { try { logger.info("loading config: {}", file); - properties.load(new BufferedReader(new FileReader( - new File(file)))); + properties.load(new BufferedReader(new FileReader(new File(file)))); } catch (IOException e) { logger.error("loading properties [{}] error", file, e); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelector.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelector.java index fb7a992237..f04a7683c2 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelector.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelector.java @@ -19,11 +19,12 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.RandomUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * This selector use random strategy. * Each selection will randomly give one from the given list diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/Weight.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/Weight.java index e793955c5c..cba255b43d 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/Weight.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/Weight.java @@ -61,10 +61,10 @@ public AtomicInteger getCurrentWeight() { @Override public String toString() { - return "Wight{" + - "target=" + target + - ", weight=" + weight + - ", currentWeight=" + currentWeight + - '}'; + return "Wight{" + + "target=" + target + + ", weight=" + weight + + ", currentWeight=" + currentWeight + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRandomLoadBalanceSelector.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRandomLoadBalanceSelector.java index 835bc48382..5b7904e69f 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRandomLoadBalanceSelector.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRandomLoadBalanceSelector.java @@ -17,9 +17,10 @@ package org.apache.eventmesh.common.loadbalance; +import org.apache.eventmesh.common.exception.EventMeshException; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.RandomUtils; -import org.apache.eventmesh.common.exception.EventMeshException; import java.util.List; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelector.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelector.java index c0310003ad..29dcc729e9 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelector.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelector.java @@ -18,11 +18,12 @@ package org.apache.eventmesh.common.loadbalance; import org.apache.commons.collections4.CollectionUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * This selector use the weighted round robin strategy to select from list. * If the weight is greater, the probability of being selected is larger. diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionItem.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionItem.java index 0eda53ec99..b27ddb139c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionItem.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/SubscriptionItem.java @@ -60,11 +60,11 @@ public void setMode(SubscriptionMode mode) { @Override public String toString() { - return "SubscriptionItem{" + - "topic=" + topic + - ", mode=" + mode + - ", type=" + type + - '}'; + return "SubscriptionItem{" + + "topic=" + topic + + ", mode=" + mode + + ", type=" + type + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java index 4b2d7b5816..11ad66aa18 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/HttpCommand.java @@ -184,18 +184,18 @@ public void setBody(Body body) { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("httpCommand={") - .append(cmdType).append(",") - .append(httpMethod).append("/").append(httpVersion).append(",") - .append("requestCode=").append(requestCode).append(",") - .append("opaque=").append(opaque).append(","); + .append(cmdType).append(",") + .append(httpMethod).append("/").append(httpVersion).append(",") + .append("requestCode=").append(requestCode).append(",") + .append("opaque=").append(opaque).append(","); if (cmdType == CmdType.RES) { sb.append("cost=").append(resTime - reqTime).append(","); } sb.append("header=").append(header).append(",") - .append("body=").append(body) - .append("}"); + .append("body=").append(body) + .append("}"); return sb.toString(); } @@ -203,17 +203,17 @@ public String toString() { public String abstractDesc() { StringBuilder sb = new StringBuilder(); sb.append("httpCommand={") - .append(cmdType).append(",") - .append(httpMethod).append("/").append(httpVersion).append(",") - .append("requestCode=").append(requestCode).append(",") - .append("opaque=").append(opaque).append(","); + .append(cmdType).append(",") + .append(httpMethod).append("/").append(httpVersion).append(",") + .append("requestCode=").append(requestCode).append(",") + .append("opaque=").append(opaque).append(","); if (cmdType == CmdType.RES) { sb.append("cost=").append(resTime - reqTime).append(","); } sb.append("header=").append(header).append(",") - .append("bodySize=").append(body.toString().length()).append("}"); + .append("bodySize=").append(body.toString().length()).append("}"); return sb.toString(); } @@ -221,9 +221,9 @@ public String abstractDesc() { public String simpleDesc() { StringBuilder sb = new StringBuilder(); sb.append("httpCommand={") - .append(cmdType).append(",") - .append(httpMethod).append("/").append(httpVersion).append(",") - .append("requestCode=").append(requestCode).append("}"); + .append(cmdType).append(",") + .append(httpMethod).append("/").append(httpVersion).append(",") + .append("requestCode=").append(requestCode).append("}"); return sb.toString(); } @@ -233,7 +233,7 @@ public DefaultFullHttpResponse httpResponse() throws Exception { return null; } DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK, - Unpooled.wrappedBuffer(JsonUtils.serialize(this.getBody()).getBytes(Constants.DEFAULT_CHARSET))); + Unpooled.wrappedBuffer(JsonUtils.serialize(this.getBody()).getBytes(Constants.DEFAULT_CHARSET))); HttpHeaders headers = response.headers(); headers.add(HttpHeaderNames.CONTENT_TYPE, "text/plain; charset=" + Constants.DEFAULT_CHARSET); headers.add(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/BaseResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/BaseResponseBody.java index 5cb5922f19..aefa711840 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/BaseResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/BaseResponseBody.java @@ -18,11 +18,11 @@ package org.apache.eventmesh.common.protocol.http.body; +import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; + import java.util.HashMap; import java.util.Map; -import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; - public class BaseResponseBody extends Body { private Integer retCode; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/Body.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/Body.java index c6976433d8..3dc8e6c272 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/Body.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/Body.java @@ -18,8 +18,6 @@ package org.apache.eventmesh.common.protocol.http.body; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.body.client.HeartbeatRequestBody; import org.apache.eventmesh.common.protocol.http.body.client.RegRequestBody; import org.apache.eventmesh.common.protocol.http.body.client.SubscribeRequestBody; @@ -32,6 +30,8 @@ import org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody; import org.apache.eventmesh.common.protocol.http.common.RequestCode; +import java.util.Map; + public abstract class Body { public abstract Map toMap(); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatRequestBody.java index 0804098898..a26ed2d1dd 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatRequestBody.java @@ -30,9 +30,9 @@ public class HeartbeatRequestBody extends Body { - public static final String CLIENTTYPE = "clientType"; + public static final String CLIENTTYPE = "clientType"; public static final String HEARTBEATENTITIES = "heartbeatEntities"; - public static final String CONSUMERGROUP = "consumerGroup"; + public static final String CONSUMERGROUP = "consumerGroup"; private String consumerGroup; @@ -69,9 +69,9 @@ public static HeartbeatRequestBody buildBody(Map bodyParam) { body.setClientType(MapUtils.getString(bodyParam, CLIENTTYPE)); body.setConsumerGroup(MapUtils.getString(bodyParam, CONSUMERGROUP)); body.setHeartbeatEntities(JsonUtils - .deserialize(MapUtils.getString(bodyParam, HEARTBEATENTITIES), - new TypeReference>() { - })); + .deserialize(MapUtils.getString(bodyParam, HEARTBEATENTITIES), + new TypeReference>() { + })); return body; } @@ -94,10 +94,10 @@ public static class HeartbeatEntity { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("heartbeatEntity={") - .append("topic=").append(topic).append(",") - .append("serviceId=").append(serviceId).append(",") - .append("instanceId=").append(instanceId).append(",") - .append("url=").append(url).append("}"); + .append("topic=").append(topic).append(",") + .append("serviceId=").append(serviceId).append(",") + .append("instanceId=").append(instanceId).append(",") + .append("url=").append(url).append("}"); return sb.toString(); } } @@ -106,8 +106,8 @@ public String toString() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("heartbeatRequestBody={") - .append("consumerGroup=").append(consumerGroup).append(",") - .append("clientType=").append(clientType).append("}"); + .append("consumerGroup=").append(consumerGroup).append(",") + .append("clientType=").append(clientType).append("}"); return sb.toString(); } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatResponseBody.java index 2d213ce017..c9151dc658 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/HeartbeatResponseBody.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.body.client; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.Map; + public class HeartbeatResponseBody extends Body { //return code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegRequestBody.java index 21a7beb903..affffdce09 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegRequestBody.java @@ -72,8 +72,8 @@ public static RegRequestBody buildBody(Map bodyParam) { body.setClientType(MapUtils.getString(bodyParam, CLIENTTYPE)); body.setEndPoint(MapUtils.getString(bodyParam, ENDPOINT)); body.setTopics(JsonUtils.deserialize(MapUtils.getString(bodyParam, TOPICS), - new TypeReference>() { - })); + new TypeReference>() { + })); return body; } @@ -89,9 +89,9 @@ public Map toMap() { @Override public String toString() { return "regRequestBody{" - + "clientType='" + clientType + '\'' - + ", endPoint='" + endPoint + '\'' - + ", topics=" + topics - + '}'; + + "clientType='" + clientType + '\'' + + ", endPoint='" + endPoint + '\'' + + ", topics=" + topics + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegResponseBody.java index 1fc1366f31..aeb3288538 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/RegResponseBody.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.body.client; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.Map; + public class RegResponseBody extends Body { private Integer retCode; private String retMsg; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeRequestBody.java index 156cc3c5c4..df413c1c33 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeRequestBody.java @@ -71,8 +71,8 @@ public static SubscribeRequestBody buildBody(Map bodyParam) { SubscribeRequestBody body = new SubscribeRequestBody(); body.setUrl(MapUtils.getString(bodyParam, URL)); body.setTopics(JsonUtils.deserialize(MapUtils.getString(bodyParam, TOPIC), - new TypeReference>() { - })); + new TypeReference>() { + })); body.setConsumerGroup(MapUtils.getString(bodyParam, CONSUMERGROUP)); return body; } @@ -89,9 +89,9 @@ public Map toMap() { @Override public String toString() { return "subscribeBody{" - + "consumerGroup='" + consumerGroup + '\'' - + ", url='" + url + '\'' - + ", topics=" + topics - + '}'; + + "consumerGroup='" + consumerGroup + '\'' + + ", url='" + url + '\'' + + ", topics=" + topics + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeResponseBody.java index 21b70826cd..0b2f6cb3ab 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/SubscribeResponseBody.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.body.client; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.Map; + public class SubscribeResponseBody extends Body { private Integer retCode; private String retMsg; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnRegRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnRegRequestBody.java index b20f4c2d44..6fa82bda7c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnRegRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnRegRequestBody.java @@ -58,8 +58,8 @@ public static UnRegRequestBody buildBody(Map bodyParam) { UnRegRequestBody body = new UnRegRequestBody(); body.setClientType(MapUtils.getString(bodyParam, CLIENTTYPE)); body.setTopics(JsonUtils.deserialize(MapUtils.getString(bodyParam, TOPICS), - new TypeReference>() { - })); + new TypeReference>() { + })); return body; } @@ -75,9 +75,9 @@ public Map toMap() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("regRequestBody={") - .append("clientType=").append(clientType) - .append("topics=").append(topics) - .append("}"); + .append("clientType=").append(clientType) + .append("topics=").append(topics) + .append("}"); return sb.toString(); } @@ -90,9 +90,9 @@ public static class UnRegTopicEntity { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("unRegTopicEntity={") - .append("topic=").append(topic).append(",") - .append("serviceId=").append(serviceId).append(",") - .append("instanceId=").append(instanceId).append("}"); + .append("topic=").append(topic).append(",") + .append("serviceId=").append(serviceId).append(",") + .append("instanceId=").append(instanceId).append("}"); return sb.toString(); } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnRegResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnRegResponseBody.java index 325095187e..975cb35a54 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnRegResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnRegResponseBody.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.body.client; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.Map; + public class UnRegResponseBody extends Body { private Integer retCode; private String retMsg; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeRequestBody.java index 5904a964f5..ca9db6210e 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeRequestBody.java @@ -70,8 +70,8 @@ public static UnSubscribeRequestBody buildBody(Map bodyParam) { UnSubscribeRequestBody body = new UnSubscribeRequestBody(); body.setUrl(MapUtils.getString(bodyParam, URL)); body.setTopics(JsonUtils - .deserialize(MapUtils.getString(bodyParam, TOPIC), new TypeReference>() { - })); + .deserialize(MapUtils.getString(bodyParam, TOPIC), new TypeReference>() { + })); body.setConsumerGroup(MapUtils.getString(bodyParam, CONSUMERGROUP)); return body; } @@ -88,9 +88,9 @@ public Map toMap() { @Override public String toString() { return "unSubscribeRequestBody{" - + "consumerGroup='" + consumerGroup + '\'' - + ", url='" + url + '\'' - + ", topics=" + topics - + '}'; + + "consumerGroup='" + consumerGroup + '\'' + + ", url='" + url + '\'' + + ", topics=" + topics + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeResponseBody.java index d62b9d9de3..d1eeb77db5 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/client/UnSubscribeResponseBody.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.body.client; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.Map; + public class UnSubscribeResponseBody extends Body { private Integer retCode; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/PushMessageRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/PushMessageRequestBody.java index 8e24580f39..4a8feeb818 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/PushMessageRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/PushMessageRequestBody.java @@ -30,11 +30,11 @@ public class PushMessageRequestBody extends Body { - public static final String RANDOMNO = "randomNo"; - public static final String TOPIC = "topic"; - public static final String BIZSEQNO = "bizseqno"; - public static final String UNIQUEID = "uniqueId"; - public static final String CONTENT = "content"; + public static final String RANDOMNO = "randomNo"; + public static final String TOPIC = "topic"; + public static final String BIZSEQNO = "bizseqno"; + public static final String UNIQUEID = "uniqueId"; + public static final String CONTENT = "content"; public static final String EXTFIELDS = "extFields"; private String randomNo; @@ -108,8 +108,8 @@ public static PushMessageRequestBody buildBody(final Map bodyPar if (StringUtils.isNotBlank(extFields)) { pushMessageRequestBody.setExtFields( - JsonUtils.deserialize(extFields, new TypeReference>() { - })); + JsonUtils.deserialize(extFields, new TypeReference>() { + })); } return pushMessageRequestBody; } @@ -131,12 +131,12 @@ public Map toMap() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("pushMessageRequestBody={") - .append("randomNo=").append(randomNo).append(",") - .append("topic=").append(topic).append(",") - .append("bizSeqNo=").append(bizSeqNo).append(",") - .append("uniqueId=").append(uniqueId).append(",") - .append("content=").append(content).append(",") - .append("extFields=").append(extFields).append("}"); + .append("randomNo=").append(randomNo).append(",") + .append("topic=").append(topic).append(",") + .append("bizSeqNo=").append(bizSeqNo).append(",") + .append("uniqueId=").append(uniqueId).append(",") + .append("content=").append(content).append(",") + .append("extFields=").append(extFields).append("}"); return sb.toString(); } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/PushMessageResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/PushMessageResponseBody.java index a5ac0d1658..01000b0d0f 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/PushMessageResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/PushMessageResponseBody.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.body.message; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.Map; + public class PushMessageResponseBody extends Body { private Integer retCode; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageRequestBody.java index 90d83c1531..0814204e4c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageRequestBody.java @@ -30,11 +30,11 @@ public class ReplyMessageRequestBody extends Body { - public static final String ORIGTOPIC = "origtopic"; - public static final String BIZSEQNO = "bizseqno"; - public static final String UNIQUEID = "uniqueid"; - public static final String CONTENT = "content"; - public static final String EXTFIELDS = "extFields"; + public static final String ORIGTOPIC = "origtopic"; + public static final String BIZSEQNO = "bizseqno"; + public static final String UNIQUEID = "uniqueid"; + public static final String CONTENT = "content"; + public static final String EXTFIELDS = "extFields"; public static final String PRODUCERGROUP = "producergroup"; private String bizSeqNo; @@ -106,8 +106,8 @@ public static ReplyMessageRequestBody buildBody(Map bodyParam) { String extFields = MapUtils.getString(bodyParam, EXTFIELDS); if (StringUtils.isNotBlank(extFields)) { body.setExtFields( - JsonUtils.deserialize(extFields, new TypeReference>() { - })); + JsonUtils.deserialize(extFields, new TypeReference>() { + })); } body.setProducerGroup(MapUtils.getString(bodyParam, PRODUCERGROUP)); return body; @@ -117,12 +117,12 @@ public static ReplyMessageRequestBody buildBody(Map bodyParam) { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("replyMessageRequestBody={") - .append("bizSeqNo=").append(bizSeqNo).append(",") - .append("uniqueId=").append(uniqueId).append(",") - .append("origTopic=").append(origTopic).append(",") - .append("content=").append(content).append(",") - .append("producerGroup=").append(producerGroup).append(",") - .append("extFields=").append(extFields).append("}"); + .append("bizSeqNo=").append(bizSeqNo).append(",") + .append("uniqueId=").append(uniqueId).append(",") + .append("origTopic=").append(origTopic).append(",") + .append("content=").append(content).append(",") + .append("producerGroup=").append(producerGroup).append(",") + .append("extFields=").append(extFields).append("}"); return sb.toString(); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageResponseBody.java index 2f9ba960d3..342f151c0a 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/ReplyMessageResponseBody.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.body.message; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.Map; + public class ReplyMessageResponseBody extends Body { //return code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchRequestBody.java index 0b544c4712..da77955333 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchRequestBody.java @@ -31,9 +31,9 @@ public class SendMessageBatchRequestBody extends Body { - public static final String BATCHID = "batchId"; - public static final String CONTENTS = "contents"; - public static final String SIZE = "size"; + public static final String BATCHID = "batchId"; + public static final String CONTENTS = "contents"; + public static final String SIZE = "size"; public static final String PRODUCERGROUP = "producerGroup"; private String batchId; @@ -83,10 +83,10 @@ public void setProducerGroup(String producerGroup) { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("sendMessageBatchRequestBody={") - .append("batchId=").append(batchId).append(",") - .append("size=").append(size).append(",") - .append("producerGroup=").append(producerGroup).append(",") - .append("contents=").append(JsonUtils.serialize(contents)).append("}"); + .append("batchId=").append(batchId).append(",") + .append("size=").append(size).append(",") + .append("producerGroup=").append(producerGroup).append(",") + .append("contents=").append(JsonUtils.serialize(contents)).append("}"); return sb.toString(); } @@ -101,29 +101,29 @@ public static class BatchMessageEntity { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("batchMessageEntity={") - .append("bizSeqNo=").append(bizSeqNo).append(",") - .append("topic=").append(topic).append(",") - .append("msg=").append(msg).append(",") - .append("ttl=").append(ttl).append(",") - .append("tag=").append(tag).append("}"); + .append("bizSeqNo=").append(bizSeqNo).append(",") + .append("topic=").append(topic).append(",") + .append("msg=").append(msg).append(",") + .append("ttl=").append(ttl).append(",") + .append("tag=").append(tag).append("}"); return sb.toString(); } } public static SendMessageBatchRequestBody buildBody(final Map bodyParam) { String batchId = MapUtils.getString(bodyParam, - BATCHID); + BATCHID); String size = StringUtils.isBlank(MapUtils.getString(bodyParam, - SIZE)) ? "1" : MapUtils.getString(bodyParam, - SIZE); + SIZE)) ? "1" : MapUtils.getString(bodyParam, + SIZE); String contents = MapUtils.getString(bodyParam, - CONTENTS, null); + CONTENTS, null); SendMessageBatchRequestBody body = new SendMessageBatchRequestBody(); body.setBatchId(batchId); if (StringUtils.isNotBlank(contents)) { body.setContents( - JsonUtils.deserialize(contents, new TypeReference>() { - })); + JsonUtils.deserialize(contents, new TypeReference>() { + })); } body.setSize(size); body.setProducerGroup(MapUtils.getString(bodyParam, PRODUCERGROUP)); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchResponseBody.java index bdf8004de0..f504473673 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchResponseBody.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.body.message; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.Map; + public class SendMessageBatchResponseBody extends Body { //return code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2RequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2RequestBody.java index b08dca7b0c..5abd7bc0cf 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2RequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2RequestBody.java @@ -17,11 +17,12 @@ package org.apache.eventmesh.common.protocol.http.body.message; -import java.util.HashMap; -import java.util.Map; +import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.commons.collections4.MapUtils; -import org.apache.eventmesh.common.protocol.http.body.Body; + +import java.util.HashMap; +import java.util.Map; public class SendMessageBatchV2RequestBody extends Body { diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2ResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2ResponseBody.java index a2f69fb84f..26cc08202c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2ResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageBatchV2ResponseBody.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.body.message; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.Map; + public class SendMessageBatchV2ResponseBody extends Body { //return code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageRequestBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageRequestBody.java index 25d35922a3..e14d230a56 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageRequestBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageRequestBody.java @@ -30,13 +30,13 @@ public class SendMessageRequestBody extends Body { - public static final String TOPIC = "topic"; - public static final String BIZSEQNO = "bizseqno"; - public static final String UNIQUEID = "uniqueid"; - public static final String CONTENT = "content"; - public static final String TTL = "ttl"; - public static final String TAG = "tag"; - public static final String EXTFIELDS = "extFields"; + public static final String TOPIC = "topic"; + public static final String BIZSEQNO = "bizseqno"; + public static final String UNIQUEID = "uniqueid"; + public static final String CONTENT = "content"; + public static final String TTL = "ttl"; + public static final String TAG = "tag"; + public static final String EXTFIELDS = "extFields"; public static final String PRODUCERGROUP = "producergroup"; private String topic; @@ -130,8 +130,8 @@ public static SendMessageRequestBody buildBody(Map bodyParam) { String extFields = MapUtils.getString(bodyParam, EXTFIELDS); if (StringUtils.isNotBlank(extFields)) { body.setExtFields( - JsonUtils.deserialize(extFields, new TypeReference>() { - })); + JsonUtils.deserialize(extFields, new TypeReference>() { + })); } body.setProducerGroup(MapUtils.getString(bodyParam, PRODUCERGROUP)); return body; @@ -155,14 +155,14 @@ public Map toMap() { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("sendMessageRequestBody={") - .append("topic=").append(topic).append(",") - .append("bizSeqNo=").append(bizSeqNo).append(",") - .append("uniqueId=").append(uniqueId).append(",") - .append("content=").append(content).append(",") - .append("ttl=").append(ttl).append(",") - .append("tag=").append(tag).append(",") - .append("producerGroup=").append(producerGroup).append(",") - .append("extFields=").append(extFields).append("}"); + .append("topic=").append(topic).append(",") + .append("bizSeqNo=").append(bizSeqNo).append(",") + .append("uniqueId=").append(uniqueId).append(",") + .append("content=").append(content).append(",") + .append("ttl=").append(ttl).append(",") + .append("tag=").append(tag).append(",") + .append("producerGroup=").append(producerGroup).append(",") + .append("extFields=").append(extFields).append("}"); return sb.toString(); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageResponseBody.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageResponseBody.java index 7a5f40dabd..e4e9eaa120 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageResponseBody.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/body/message/SendMessageResponseBody.java @@ -73,9 +73,9 @@ public static SendMessageResponseBody buildBody(Integer retCode, String retMsg) public String toString() { StringBuilder sb = new StringBuilder(); sb.append("sendMessageResponseBody={") - .append("retCode=").append(retCode).append(",") - .append("retMsg=").append(retMsg).append(",") - .append("resTime=").append(DateFormatUtils.format(resTime, Constants.DATE_FORMAT)).append("}"); + .append("retCode=").append(retCode).append(",") + .append("retMsg=").append(retMsg).append(",") + .append("resTime=").append(DateFormatUtils.format(resTime, Constants.DATE_FORMAT)).append("}"); return sb.toString(); } @@ -91,8 +91,8 @@ public Map toMap() { @Data @Builder public static class ReplyMessage { - public String topic; - public String body; + public String topic; + public String body; public Map properties; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/BaseRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/BaseRequestHeader.java index d58919e3c4..f34f915418 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/BaseRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/BaseRequestHeader.java @@ -17,11 +17,12 @@ package org.apache.eventmesh.common.protocol.http.header; -import java.util.HashMap; -import java.util.Map; +import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.commons.collections4.MapUtils; -import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; + +import java.util.HashMap; +import java.util.Map; public class BaseRequestHeader extends Header { private String code; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/BaseResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/BaseResponseHeader.java index cd7bbaf59b..2a2e2c7665 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/BaseResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/BaseResponseHeader.java @@ -18,11 +18,11 @@ package org.apache.eventmesh.common.protocol.http.header; +import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; + import java.util.HashMap; import java.util.Map; -import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; - public class BaseResponseHeader extends Header { private String code; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/Header.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/Header.java index f2e44108e5..9a432202a1 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/Header.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/Header.java @@ -18,8 +18,6 @@ package org.apache.eventmesh.common.protocol.http.header; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.protocol.http.header.client.HeartbeatRequestHeader; import org.apache.eventmesh.common.protocol.http.header.client.RegRequestHeader; @@ -32,6 +30,8 @@ import org.apache.eventmesh.common.protocol.http.header.message.SendMessageBatchV2RequestHeader; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader; +import java.util.Map; + public abstract class Header { public abstract Map toMap(); diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeader.java index 2713e8db29..85fceb6945 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeader.java @@ -17,16 +17,17 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.HashMap; +import java.util.Map; + public class HeartbeatRequestHeader extends Header { //request code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeader.java index e0d6e99a17..c1c35c47d1 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeader.java @@ -18,12 +18,12 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class HeartbeatResponseHeader extends Header { private int code; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java index 3b831a0f79..3d88dbf312 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeader.java @@ -17,13 +17,14 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + import java.util.HashMap; import java.util.Map; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegResponseHeader.java index 54ca794d57..b928b79fd0 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/RegResponseHeader.java @@ -18,12 +18,12 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class RegResponseHeader extends Header { //response code, as same as the request code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java index e6ba1b79fe..adef902d93 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeader.java @@ -17,13 +17,14 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + import java.util.HashMap; import java.util.Map; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeResponseHeader.java index f21fbceb89..d16fb4e6aa 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeResponseHeader.java @@ -17,12 +17,12 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class SubscribeResponseHeader extends Header { private int code; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeader.java index 7503c7c5ff..639d696476 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeader.java @@ -17,16 +17,17 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.HashMap; +import java.util.Map; + public class UnRegRequestHeader extends Header { //request code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegResponseHeader.java index 4338c0305f..550e796be7 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegResponseHeader.java @@ -18,12 +18,12 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class UnRegResponseHeader extends Header { private int code; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java index d58e8c8499..452e278846 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeader.java @@ -17,13 +17,14 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + import java.util.HashMap; import java.util.Map; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeResponseHeader.java index f2638234d2..bb90b4bf75 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeResponseHeader.java @@ -17,12 +17,12 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class UnSubscribeResponseHeader extends Header { private int code; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeader.java index 99a558796c..726c08a720 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeader.java @@ -18,15 +18,16 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - -import org.apache.commons.collections4.MapUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; + +import java.util.HashMap; +import java.util.Map; + public class PushMessageRequestHeader extends Header { //request code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java index 496b1906cc..ad4a8ec24e 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeader.java @@ -17,13 +17,14 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + import java.util.HashMap; import java.util.Map; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeader.java index f52428e4ef..20d6f107e9 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeader.java @@ -18,12 +18,12 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class ReplyMessageResponseHeader extends Header { //response code, as same as the request code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java index 85492cf2fc..9ee63f71b2 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchRequestHeader.java @@ -18,13 +18,14 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + import java.util.HashMap; import java.util.Map; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchResponseHeader.java index 8bee0b1158..4ddfde68b8 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchResponseHeader.java @@ -18,12 +18,12 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class SendMessageBatchResponseHeader extends Header { //response code, as same as the request code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java index 15ff19a623..369d2c5460 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2RequestHeader.java @@ -17,13 +17,14 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + import java.util.HashMap; import java.util.Map; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2ResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2ResponseHeader.java index ed4898fd02..a188c9713c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2ResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageBatchV2ResponseHeader.java @@ -17,12 +17,12 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class SendMessageBatchV2ResponseHeader extends Header { //response code, as same as the request code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java index f637563dc5..19774280a4 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageRequestHeader.java @@ -17,13 +17,14 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + import java.util.HashMap; import java.util.Map; diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageResponseHeader.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageResponseHeader.java index aa10c2a8c3..a9db7ff587 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageResponseHeader.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/http/header/message/SendMessageResponseHeader.java @@ -18,12 +18,12 @@ package org.apache.eventmesh.common.protocol.http.header.message; -import java.util.HashMap; -import java.util.Map; - import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; +import java.util.HashMap; +import java.util.Map; + public class SendMessageResponseHeader extends Header { //response code, as same as the request code diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/EventMeshClientInfo.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/EventMeshClientInfo.java index 93616b2b8e..bc97d97857 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/EventMeshClientInfo.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/EventMeshClientInfo.java @@ -29,7 +29,8 @@ // private long lastUpdateTimestamp; // private int protocolNumber; // -// public EventMeshClientInfo(String clientId, String consumerGroup, String endpoint, String language, long version, DataVersion dataVersion, long lastUpdateTimestamp, int protocolNumber) { +// public EventMeshClientInfo(String clientId, String consumerGroup, String endpoint, String language, long version, +// DataVersion dataVersion, long lastUpdateTimestamp, int protocolNumber) { // this.clientId = clientId; // this.endpoint = endpoint; // this.language = language; @@ -106,6 +107,8 @@ // // @Override // public String toString() { -// return "ClientId [clientId=" + clientId + ", consumerGroup=" + consumerGroup + ", endpoint=" + endpoint + ", language=" + language + ", version=" + version + ", dataVersion=" + dataVersion + ", lastUpdateTimestamp=" + lastUpdateTimestamp + "]"; +// return "ClientId [clientId=" + clientId + ", consumerGroup=" + consumerGroup + ", endpoint=" + endpoint +// + ", language=" + language + ", version=" + version + ", dataVersion=" + dataVersion +// + ", lastUpdateTimestamp=" + lastUpdateTimestamp + "]"; // } //} diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/EventMeshMessage.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/EventMeshMessage.java index a51f9e022a..945824074c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/EventMeshMessage.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/EventMeshMessage.java @@ -29,7 +29,7 @@ @AllArgsConstructor public class EventMeshMessage { - private String topic; + private String topic; private Map properties = new ConcurrentHashMap<>(); - private String body; + private String body; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Header.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Header.java index dc8e564382..9c9a2890bc 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Header.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Header.java @@ -25,10 +25,10 @@ @Data public class Header { - private Command cmd; - private int code; - private String desc; - private String seq; + private Command cmd; + private int code; + private String desc; + private String seq; private Map properties = new HashMap<>(); public Header() { @@ -72,4 +72,8 @@ public String getStringProperty(final String name) { return property.toString(); } + public Command getCommand() { + return this.cmd; + } + } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/HeartBeatInfo.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/HeartBeatInfo.java index c12d6917d2..9bd64ec877 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/HeartBeatInfo.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/HeartBeatInfo.java @@ -60,10 +60,12 @@ public void setTopicList(List topicList) { @Override public String toString() { - return "HeartBeatInfo{" + - "serviceId='" + serviceId + '\'' + - ", instanceId='" + instanceId + '\'' + - ", topicList=" + topicList + - '}'; + return "HeartBeatInfo{" + + "serviceId='" + serviceId + + '\'' + + ", instanceId='" + instanceId + + '\'' + + ", topicList=" + topicList + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Package.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Package.java index 1a2a223bf2..43c5d1a100 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Package.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Package.java @@ -17,12 +17,14 @@ package org.apache.eventmesh.common.protocol.tcp; + import org.apache.eventmesh.common.protocol.ProtocolTransportObject; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; + @Data @NoArgsConstructor @AllArgsConstructor diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/RedirectInfo.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/RedirectInfo.java index 81373f8485..8b552bfd20 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/RedirectInfo.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/RedirectInfo.java @@ -47,9 +47,10 @@ public void setPort(int port) { @Override public String toString() { - return "RedirectInfo{" + - "ip='" + ip + '\'' + - ", port=" + port + - '}'; + return "RedirectInfo{" + + "ip='" + ip + + '\'' + + ", port=" + port + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/RegisterInfo.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/RegisterInfo.java index 44303f2f58..750e29ed5f 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/RegisterInfo.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/RegisterInfo.java @@ -40,8 +40,8 @@ public void setTopicList(List topicList) { @Override public String toString() { - return "RegisterInfo{" + - "topicList=" + topicList + - '}'; + return "RegisterInfo{" + + "topicList=" + topicList + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Subscription.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Subscription.java index 3fb74b95b0..ad9f269417 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Subscription.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/Subscription.java @@ -43,8 +43,8 @@ public void setTopicList(List topicList) { @Override public String toString() { - return "Subscription{" + - "topicList=" + topicList + - '}'; + return "Subscription{" + + "topicList=" + topicList + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UnRegisterInfo.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UnRegisterInfo.java index 33961ad486..d4c8626a52 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UnRegisterInfo.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UnRegisterInfo.java @@ -60,10 +60,12 @@ public void setTopicList(List topicList) { @Override public String toString() { - return "UnRegisterInfo{" + - "serviceId='" + serviceId + '\'' + - ", instanceId='" + instanceId + '\'' + - ", topicList=" + topicList + - '}'; + return "UnRegisterInfo{" + + "serviceId='" + serviceId + + '\'' + + ", instanceId='" + instanceId + + '\'' + + ", topicList=" + topicList + + '}'; } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UserAgent.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UserAgent.java index 1d0c8d3fad..077ae9a37c 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UserAgent.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/UserAgent.java @@ -17,11 +17,11 @@ package org.apache.eventmesh.common.protocol.tcp; +import java.util.Objects; + import lombok.Builder; import lombok.Data; -import java.util.Objects; - @Data @Builder public class UserAgent { @@ -29,9 +29,9 @@ public class UserAgent { private String env; private String subsystem; private String path; - private int pid; + private int pid; private String host; - private int port; + private int port; private String version; private String username; private String password; @@ -40,7 +40,7 @@ public class UserAgent { private String consumerGroup; private String purpose; @Builder.Default - private int unack = 0; + private int unack = 0; public UserAgent() { } @@ -67,28 +67,67 @@ public UserAgent(String env, String subsystem, String path, int pid, String host @Override public String toString() { return String.format( - "UserAgent{env='%s', subsystem='%s', path='%s', pid=%d, host='%s', port=%d, version='%s', idc='%s', purpose='%s', unack='%d'}", - env, subsystem, path, pid, host, port, version, idc, purpose, unack); + "UserAgent{env='%s', subsystem='%s', path='%s', pid=%d, host='%s', port=%d, version='%s', idc='%s', purpose='%s', unack='%d'}", + env, subsystem, path, pid, host, port, version, idc, purpose, unack); } @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + + if (o == null || getClass() != o.getClass()) { + return false; + } UserAgent userAgent = (UserAgent) o; - if (pid != userAgent.pid) return false; - if (port != userAgent.port) return false; - if (unack != userAgent.unack) return false; - if (!Objects.equals(subsystem, userAgent.subsystem)) return false; - if (!Objects.equals(path, userAgent.path)) return false; - if (!Objects.equals(host, userAgent.host)) return false; - if (!Objects.equals(purpose, userAgent.purpose)) return false; - if (!Objects.equals(version, userAgent.version)) return false; - if (!Objects.equals(username, userAgent.username)) return false; - if (!Objects.equals(password, userAgent.password)) return false; - if (!Objects.equals(env, userAgent.env)) return false; + if (pid != userAgent.pid) { + return false; + } + + if (port != userAgent.port) { + return false; + } + + if (unack != userAgent.unack) { + return false; + } + + if (!Objects.equals(subsystem, userAgent.subsystem)) { + return false; + } + + + if (!Objects.equals(path, userAgent.path)) { + return false; + } + + if (!Objects.equals(host, userAgent.host)) { + return false; + } + + if (!Objects.equals(purpose, userAgent.purpose)) { + return false; + } + + if (!Objects.equals(version, userAgent.version)) { + return false; + } + + if (!Objects.equals(username, userAgent.username)) { + return false; + } + + if (!Objects.equals(password, userAgent.password)) { + return false; + } + + if (!Objects.equals(env, userAgent.env)) { + return false; + } + return Objects.equals(idc, userAgent.idc); } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/codec/Codec.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/codec/Codec.java index ab1d461207..b1593fe81e 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/codec/Codec.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/protocol/tcp/codec/Codec.java @@ -34,6 +34,11 @@ import java.util.List; import java.util.TimeZone; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import io.netty.handler.codec.ReplayingDecoder; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationFeature; @@ -41,24 +46,20 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.google.common.base.Preconditions; -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import io.netty.handler.codec.ReplayingDecoder; import lombok.extern.slf4j.Slf4j; @Slf4j public class Codec { - private static final int FRAME_MAX_LENGTH = 1024 * 1024 * 4; - private static final Charset DEFAULT_CHARSET = Charset.forName(Constants.DEFAULT_CHARSET); + private static final int FRAME_MAX_LENGTH = 1024 * 1024 * 4; + private static final Charset DEFAULT_CHARSET = Charset.forName(Constants.DEFAULT_CHARSET); private static final byte[] CONSTANT_MAGIC_FLAG = serializeBytes("EventMesh"); - private static final byte[] VERSION = serializeBytes("0000"); + private static final byte[] VERSION = serializeBytes("0000"); // todo: move to constants public static String CLOUD_EVENTS_PROTOCOL_NAME = "cloudevents"; - public static String EM_MESSAGE_PROTOCOL_NAME = "eventmeshmessage"; + public static String EM_MESSAGE_PROTOCOL_NAME = "eventmeshmessage"; public static String OPEN_MESSAGE_PROTOCOL_NAME = "openmessage"; // todo: use json util @@ -178,8 +179,8 @@ private Object parseBody(ByteBuf in, Header header, int bodyLength) throws JsonP private void validateFlag(byte[] flagBytes, byte[] versionBytes, ChannelHandlerContext ctx) { if (!Arrays.equals(flagBytes, CONSTANT_MAGIC_FLAG) || !Arrays.equals(versionBytes, VERSION)) { String errorMsg = String.format( - "invalid magic flag or version|flag=%s|version=%s|remoteAddress=%s", - deserializeBytes(flagBytes), deserializeBytes(versionBytes), ctx.channel().remoteAddress()); + "invalid magic flag or version|flag=%s|version=%s|remoteAddress=%s", + deserializeBytes(flagBytes), deserializeBytes(versionBytes), ctx.channel().remoteAddress()); throw new IllegalArgumentException(errorMsg); } } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/IPUtils.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/IPUtils.java index 434f5a580e..b96ed17dab 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/IPUtils.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/IPUtils.java @@ -36,8 +36,9 @@ public static String getLocalAddress() { // if the progress works under docker environment // return the host ip about this docker located from environment value String dockerHostIp = System.getenv("docker_host_ip"); - if (dockerHostIp != null && !"".equals(dockerHostIp)) + if (dockerHostIp != null && !"".equals(dockerHostIp)) { return dockerHostIp; + } //priority of networkInterface when generating client ip String priority = System.getProperty("networkInterface.priority", "eth0 preferList.indexOf(preferNetworkInterface.getName())) { preferNetworkInterface = networkInterface; } diff --git a/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/RandomStringUtils.java b/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/RandomStringUtils.java index aaeaec84a6..bc14554196 100644 --- a/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/RandomStringUtils.java +++ b/eventmesh-common/src/main/java/org/apache/eventmesh/common/utils/RandomStringUtils.java @@ -22,7 +22,7 @@ public class RandomStringUtils { private static final RandomStringGenerator RANDOM_NUM_GENERATOR = new RandomStringGenerator.Builder() - .withinRange('0', '9').build(); + .withinRange('0', '9').build(); public static String generateNum(int length) { return RANDOM_NUM_GENERATOR.generate(length); diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/EventMeshMessageTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/EventMeshMessageTest.java index 006a1d1cb3..b0df5405f3 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/EventMeshMessageTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/EventMeshMessageTest.java @@ -68,7 +68,7 @@ private EventMeshMessage createLiteMessage() { prop.put("key1", "value1"); prop.put("key2", "value2"); return EventMeshMessage.builder() - .prop(prop) - .build(); + .prop(prop) + .build(); } } diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelectorTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelectorTest.java index 4f7198f899..728244117d 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelectorTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/RandomLoadBalanceSelectorTest.java @@ -17,17 +17,17 @@ package org.apache.eventmesh.common.loadbalance; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class RandomLoadBalanceSelectorTest { private RandomLoadBalanceSelector randomLoadBalanceSelector; diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRandomLoadBalanceSelectorTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRandomLoadBalanceSelectorTest.java index 533163032a..beb5e659e1 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRandomLoadBalanceSelectorTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRandomLoadBalanceSelectorTest.java @@ -17,10 +17,8 @@ package org.apache.eventmesh.common.loadbalance; -import org.junit.Assert; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import static java.util.stream.Collectors.groupingBy; +import static java.util.stream.Collectors.summingInt; import java.lang.reflect.Field; import java.util.ArrayList; @@ -29,8 +27,10 @@ import java.util.function.Function; import java.util.stream.IntStream; -import static java.util.stream.Collectors.groupingBy; -import static java.util.stream.Collectors.summingInt; +import org.junit.Assert; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class WeightRandomLoadBalanceSelectorTest { diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelectorTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelectorTest.java index d37aed367b..cf43ee48ef 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelectorTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/loadbalance/WeightRoundRobinLoadBalanceSelectorTest.java @@ -17,17 +17,17 @@ package org.apache.eventmesh.common.loadbalance; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class WeightRoundRobinLoadBalanceSelectorTest { private Logger logger = LoggerFactory.getLogger(WeightRoundRobinLoadBalanceSelectorTest.class); diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/body/BaseResponseBodyTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/body/BaseResponseBodyTest.java index edba782483..4a8850ba09 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/body/BaseResponseBodyTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/body/BaseResponseBodyTest.java @@ -17,12 +17,13 @@ package org.apache.eventmesh.common.protocol.http.body; +import static org.hamcrest.CoreMatchers.is; + import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; + import org.junit.Assert; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; - public class BaseResponseBodyTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/BaseRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/BaseRequestHeaderTest.java index e511f192cb..4768963908 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/BaseRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/BaseRequestHeaderTest.java @@ -18,14 +18,15 @@ package org.apache.eventmesh.common.protocol.http.header; +import static org.hamcrest.CoreMatchers.is; + import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; -import org.junit.Assert; -import org.junit.Test; import java.util.HashMap; import java.util.Map; -import static org.hamcrest.CoreMatchers.is; +import org.junit.Assert; +import org.junit.Test; public class BaseRequestHeaderTest { diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/BaseResponseHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/BaseResponseHeaderTest.java index f963eea55e..23dc6540be 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/BaseResponseHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/BaseResponseHeaderTest.java @@ -17,12 +17,13 @@ package org.apache.eventmesh.common.protocol.http.header; +import static org.hamcrest.CoreMatchers.is; + import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; + import org.junit.Assert; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; - public class BaseResponseHeaderTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/AbstractRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/AbstractRequestHeaderTest.java index 115aa12eea..0726e6f07f 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/AbstractRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/AbstractRequestHeaderTest.java @@ -19,6 +19,7 @@ import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; + import org.junit.Assert; public class AbstractRequestHeaderTest { diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/AbstractResponseHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/AbstractResponseHeaderTest.java index 0b5b0bda92..54e1f0c35d 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/AbstractResponseHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/AbstractResponseHeaderTest.java @@ -17,11 +17,12 @@ package org.apache.eventmesh.common.protocol.http.header.client; +import static org.hamcrest.CoreMatchers.is; + import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.header.Header; -import org.junit.Assert; -import static org.hamcrest.CoreMatchers.is; +import org.junit.Assert; public class AbstractResponseHeaderTest { diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeaderTest.java index 7b1afaeea0..c09359e3f5 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatRequestHeaderTest.java @@ -18,10 +18,10 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import org.junit.Test; - import java.util.HashMap; +import org.junit.Test; + public class HeartbeatRequestHeaderTest extends AbstractRequestHeaderTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeaderTest.java index d27aeaf8d4..a437b8f707 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/HeartbeatResponseHeaderTest.java @@ -17,12 +17,8 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; -import org.junit.Assert; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; - public class HeartbeatResponseHeaderTest extends AbstractResponseHeaderTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeaderTest.java index dbeb33bf26..24f7eb3855 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/RegRequestHeaderTest.java @@ -17,10 +17,10 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import org.junit.Test; - import java.util.HashMap; +import org.junit.Test; + public class RegRequestHeaderTest extends AbstractRequestHeaderTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeaderTest.java index e883688903..af79ff03fe 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/SubscribeRequestHeaderTest.java @@ -17,10 +17,10 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import org.junit.Test; - import java.util.HashMap; +import org.junit.Test; + public class SubscribeRequestHeaderTest extends AbstractRequestHeaderTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeaderTest.java index 9e77a21711..50b8e8d6ea 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/UnRegRequestHeaderTest.java @@ -18,10 +18,10 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import org.junit.Test; - import java.util.HashMap; +import org.junit.Test; + public class UnRegRequestHeaderTest extends AbstractRequestHeaderTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeaderTest.java index 5ee7c9e509..562d92d83d 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/client/UnSubscribeRequestHeaderTest.java @@ -17,10 +17,10 @@ package org.apache.eventmesh.common.protocol.http.header.client; -import org.junit.Test; - import java.util.HashMap; +import org.junit.Test; + public class UnSubscribeRequestHeaderTest extends AbstractRequestHeaderTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeaderTest.java index 4f4d96efe4..d683789578 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageRequestHeaderTest.java @@ -17,17 +17,18 @@ package org.apache.eventmesh.common.protocol.http.header.message; +import static org.hamcrest.CoreMatchers.is; + import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; import java.util.HashMap; import java.util.Map; -import static org.hamcrest.CoreMatchers.is; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; public class PushMessageRequestHeaderTest { diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java index 174d57b881..3446ef0e2d 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/PushMessageResponseHeaderTest.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.common.protocol.http.header.message; +import static org.hamcrest.CoreMatchers.is; + import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; + import org.junit.Assert; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; - public class PushMessageResponseHeaderTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java index f8625c0e76..eec5d1854d 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageRequestHeaderTest.java @@ -17,17 +17,18 @@ package org.apache.eventmesh.common.protocol.http.header.message; +import static org.hamcrest.CoreMatchers.is; + import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; import java.util.HashMap; import java.util.Map; -import static org.hamcrest.CoreMatchers.is; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; public class ReplyMessageRequestHeaderTest { diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeaderTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeaderTest.java index a3b90da3ec..a6714a885b 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeaderTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/http/header/message/ReplyMessageResponseHeaderTest.java @@ -17,12 +17,13 @@ package org.apache.eventmesh.common.protocol.http.header.message; +import static org.hamcrest.CoreMatchers.is; + import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; + import org.junit.Assert; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; - public class ReplyMessageResponseHeaderTest { @Test diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/tcp/codec/CodecTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/tcp/codec/CodecTest.java index 365717e230..bb66e5c04b 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/tcp/codec/CodecTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/protocol/tcp/codec/CodecTest.java @@ -17,19 +17,26 @@ package org.apache.eventmesh.common.protocol.tcp.codec; -import io.netty.buffer.ByteBuf; -import io.netty.buffer.PooledByteBufAllocator; +import org.apache.eventmesh.common.protocol.tcp.Command; +import org.apache.eventmesh.common.protocol.tcp.Header; import org.apache.eventmesh.common.protocol.tcp.Package; + +import java.util.ArrayList; + import org.junit.Assert; import org.junit.Test; -import java.util.ArrayList; +import io.netty.buffer.ByteBuf; +import io.netty.buffer.PooledByteBufAllocator; public class CodecTest { @Test public void testCodec() throws Exception { - Package testP = new Package(); + Header header = new Header(); + header.setCmd(Command.HELLO_REQUEST); + Package testP = new Package(header); + testP.setBody(new Object()); Codec.Encoder ce = new Codec.Encoder(); ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(); ce.encode(null, testP, buf); @@ -37,7 +44,7 @@ public void testCodec() throws Exception { ArrayList result = new ArrayList<>(); cd.decode(null, buf, result); Assert.assertNotNull(result.get(0)); - Assert.assertEquals(result.get(0).toString(), testP.toString()); + Assert.assertEquals(testP.getHeader(), ((Package) result.get(0)).getHeader()); } } diff --git a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java index a9aeb0e38e..8aebf88334 100644 --- a/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java +++ b/eventmesh-common/src/test/java/org/apache/eventmesh/common/utils/ThreadUtilsTest.java @@ -49,7 +49,9 @@ public void run() { try { ThreadUtils.randomSleep(50); } catch (Exception ignore) { + //ignore } + sleepTime = System.currentTimeMillis() - startTime; } } diff --git a/eventmesh-common/src/test/resources/configuration.properties b/eventmesh-common/src/test/resources/configuration.properties index a5e0828ca3..d4a7542db1 100644 --- a/eventmesh-common/src/test/resources/configuration.properties +++ b/eventmesh-common/src/test/resources/configuration.properties @@ -14,7 +14,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # - eventMesh.server.env=value1 eventMesh.server.idc=value2 eventMesh.sysid=3 diff --git a/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/AbstractContext.java b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/AbstractContext.java index 559a082bfc..4fa7bd2ecf 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/AbstractContext.java +++ b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/AbstractContext.java @@ -17,5 +17,8 @@ package org.apache.eventmesh.api; +/** + * AbstractContext + */ public interface AbstractContext { } diff --git a/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/RequestReplyCallback.java b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/RequestReplyCallback.java index 3def887e07..9fdfa666bf 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/RequestReplyCallback.java +++ b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/RequestReplyCallback.java @@ -19,6 +19,9 @@ import io.cloudevents.CloudEvent; +/** + * RequestReplyCallback + */ public interface RequestReplyCallback { void onSuccess(CloudEvent event); diff --git a/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/ConnectorResourceService.java b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/ConnectorResourceService.java index d701639ae9..8b6cff71ca 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/ConnectorResourceService.java +++ b/eventmesh-connector-plugin/eventmesh-connector-api/src/main/java/org/apache/eventmesh/api/connector/ConnectorResourceService.java @@ -14,11 +14,15 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.api.connector; import org.apache.eventmesh.spi.EventMeshExtensionType; import org.apache.eventmesh.spi.EventMeshSPI; +/** + * ConnectorResourceService + */ @EventMeshSPI(isSingleton = true, eventMeshExtensionType = EventMeshExtensionType.CONNECTOR) public interface ConnectorResourceService { @@ -30,7 +34,7 @@ public interface ConnectorResourceService { void init() throws Exception; /** - *Resource release in connector,such as,some public threadpool if exist + * Resource release in connector,such as,some public threadpool if exist * * @throws Exception */ diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/admin/command/CreateTopicCommand.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/admin/command/CreateTopicCommand.java index 53f1822560..f1e325e552 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/admin/command/CreateTopicCommand.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/admin/command/CreateTopicCommand.java @@ -43,7 +43,7 @@ public void execute() throws Exception { init(); adminExt.start(); Set brokersAddr = CommandUtil.fetchMasterAddrByClusterName( - adminExt, clusterName); + adminExt, clusterName); for (String masterAddr : brokersAddr) { TopicConfig topicConfig = new TopicConfig(); topicConfig.setTopicName(topicName); diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/RocketMQMessageFactory.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/RocketMQMessageFactory.java index 966be12844..24699ef9fe 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/RocketMQMessageFactory.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/RocketMQMessageFactory.java @@ -17,6 +17,10 @@ package org.apache.eventmesh.connector.rocketmq.cloudevent; +import org.apache.eventmesh.connector.rocketmq.cloudevent.impl.RocketMQBinaryMessageReader; +import org.apache.eventmesh.connector.rocketmq.cloudevent.impl.RocketMQHeaders; +import org.apache.eventmesh.connector.rocketmq.cloudevent.impl.RocketMQMessageWriter; + import org.apache.rocketmq.common.message.Message; import java.util.Map; @@ -25,16 +29,11 @@ import io.cloudevents.core.message.MessageReader; import io.cloudevents.core.message.MessageWriter; -import io.cloudevents.core.message.impl.GenericStructuredMessageReader; import io.cloudevents.core.message.impl.MessageUtils; import io.cloudevents.lang.Nullable; import io.cloudevents.rw.CloudEventRWException; import io.cloudevents.rw.CloudEventWriter; -import org.apache.eventmesh.connector.rocketmq.cloudevent.impl.RocketMQBinaryMessageReader; -import org.apache.eventmesh.connector.rocketmq.cloudevent.impl.RocketMQHeaders; -import org.apache.eventmesh.connector.rocketmq.cloudevent.impl.RocketMQMessageWriter; - @ParametersAreNonnullByDefault public final class RocketMQMessageFactory { @@ -50,13 +49,13 @@ public static MessageReader createReader(final Message message) throws CloudEven public static MessageReader createReader(final Map props, @Nullable final byte[] body) - throws CloudEventRWException { + throws CloudEventRWException { return MessageUtils.parseStructuredOrBinaryMessage( - () -> null, - format -> null, - () -> props.get(RocketMQHeaders.SPEC_VERSION), - sv -> new RocketMQBinaryMessageReader(sv, props, body) + () -> null, + format -> null, + () -> props.get(RocketMQHeaders.SPEC_VERSION), + sv -> new RocketMQBinaryMessageReader(sv, props, body) ); } diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQBinaryMessageReader.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQBinaryMessageReader.java index 8b120380b5..fe95bfbfd8 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQBinaryMessageReader.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQBinaryMessageReader.java @@ -26,14 +26,14 @@ import io.cloudevents.core.message.impl.BaseGenericBinaryMessageReaderImpl; public class RocketMQBinaryMessageReader - extends BaseGenericBinaryMessageReaderImpl { + extends BaseGenericBinaryMessageReaderImpl { private final Map headers; public RocketMQBinaryMessageReader(SpecVersion version, Map headers, byte[] payload) { super(version, - payload != null && payload.length > 0 ? BytesCloudEventData.wrap(payload) : null); + payload != null && payload.length > 0 ? BytesCloudEventData.wrap(payload) : null); Objects.requireNonNull(headers); this.headers = headers; diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQHeaders.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQHeaders.java index 64600ae0a7..793092355d 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQHeaders.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQHeaders.java @@ -27,10 +27,10 @@ public class RocketMQHeaders { public static final String CE_PREFIX = "CE_"; protected static final Map ATTRIBUTES_TO_HEADERS = - MessageUtils.generateAttributesToHeadersMapping(v -> v); + MessageUtils.generateAttributesToHeadersMapping(v -> v); public static final String CONTENT_TYPE = - ATTRIBUTES_TO_HEADERS.get(CloudEventV1.DATACONTENTTYPE); + ATTRIBUTES_TO_HEADERS.get(CloudEventV1.DATACONTENTTYPE); public static final String SPEC_VERSION = ATTRIBUTES_TO_HEADERS.get(CloudEventV1.SPECVERSION); diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQMessageWriter.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQMessageWriter.java index 60f0609a36..e1f87869c3 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQMessageWriter.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/cloudevent/impl/RocketMQMessageWriter.java @@ -29,7 +29,7 @@ public final class RocketMQMessageWriter - implements MessageWriter, Message>, CloudEventWriter { + implements MessageWriter, Message>, CloudEventWriter { private Message message; @@ -66,7 +66,7 @@ public RocketMQMessageWriter(String topic, String keys, String tags) { @Override public CloudEventContextWriter withContextAttribute(String name, String value) - throws CloudEventRWException { + throws CloudEventRWException { //String propName = RocketMQHeaders.ATTRIBUTES_TO_HEADERS.get(name); //if (propName == null) { @@ -85,7 +85,7 @@ public RocketMQMessageWriter create(final SpecVersion version) { @Override public Message setEvent(final EventFormat format, final byte[] value) - throws CloudEventRWException { + throws CloudEventRWException { message.putUserProperty(RocketMQHeaders.CONTENT_TYPE, format.serializedContentType()); message.setBody(value); return message; diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/config/ClientConfiguration.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/config/ClientConfiguration.java index 20e6d87b61..f51576d3b6 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/config/ClientConfiguration.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/config/ClientConfiguration.java @@ -23,22 +23,22 @@ public class ClientConfiguration { - public String namesrvAddr = ""; - public String clientUserName = "username"; - public String clientPass = "password"; - public Integer consumeThreadMin = 2; - public Integer consumeThreadMax = 2; - public Integer consumeQueueSize = 10000; - public Integer pullBatchSize = 32; - public Integer ackWindow = 1000; - public Integer pubWindow = 100; - public long consumeTimeout = 0L; - public Integer pollNameServerInterval = 10 * 1000; + public String namesrvAddr = ""; + public String clientUserName = "username"; + public String clientPass = "password"; + public Integer consumeThreadMin = 2; + public Integer consumeThreadMax = 2; + public Integer consumeQueueSize = 10000; + public Integer pullBatchSize = 32; + public Integer ackWindow = 1000; + public Integer pubWindow = 100; + public long consumeTimeout = 0L; + public Integer pollNameServerInterval = 10 * 1000; public Integer heartbeatBrokerInterval = 30 * 1000; - public Integer rebalanceInterval = 20 * 1000; - public String clusterName = ""; - public String accessKey = ""; - public String secretKey = ""; + public Integer rebalanceInterval = 20 * 1000; + public String clusterName = ""; + public String accessKey = ""; + public String secretKey = ""; public void init() { @@ -54,86 +54,86 @@ public void init() { String namesrvAddrStr = ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_NAMESRV_ADDR); Preconditions.checkState(StringUtils.isNotEmpty(namesrvAddrStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_NAMESRV_ADDR)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_NAMESRV_ADDR)); namesrvAddr = StringUtils.trim(namesrvAddrStr); String consumeThreadPoolMinStr = - ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MIN); + ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MIN); if (StringUtils.isNotEmpty(consumeThreadPoolMinStr)) { Preconditions.checkState(StringUtils.isNumeric(consumeThreadPoolMinStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MIN)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MIN)); consumeThreadMin = Integer.valueOf(consumeThreadPoolMinStr); } String consumeThreadPoolMaxStr = - ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MAX); + ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MAX); if (StringUtils.isNotEmpty(consumeThreadPoolMaxStr)) { Preconditions.checkState(StringUtils.isNumeric(consumeThreadPoolMaxStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MAX)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MAX)); consumeThreadMax = Integer.valueOf(consumeThreadPoolMaxStr); } String consumerThreadPoolQueueSizeStr = - ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_QUEUESIZE); + ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_QUEUESIZE); if (StringUtils.isNotEmpty(consumerThreadPoolQueueSizeStr)) { Preconditions.checkState(StringUtils.isNumeric(consumerThreadPoolQueueSizeStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_QUEUESIZE)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_QUEUESIZE)); consumeQueueSize = Integer.valueOf(consumerThreadPoolQueueSizeStr); } String clientAckWindowStr = ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_ACK_WINDOW); if (StringUtils.isNotEmpty(clientAckWindowStr)) { Preconditions.checkState(StringUtils.isNumeric(clientAckWindowStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_ACK_WINDOW)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_ACK_WINDOW)); ackWindow = Integer.valueOf(clientAckWindowStr); } String clientPubWindowStr = ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_PUB_WINDOW); if (StringUtils.isNotEmpty(clientPubWindowStr)) { Preconditions.checkState(StringUtils.isNumeric(clientPubWindowStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_PUB_WINDOW)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_PUB_WINDOW)); pubWindow = Integer.valueOf(clientPubWindowStr); } String consumeTimeoutStr = - ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_CONSUME_TIMEOUT); + ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_CONSUME_TIMEOUT); if (StringUtils.isNotBlank(consumeTimeoutStr)) { Preconditions.checkState(StringUtils.isNumeric(consumeTimeoutStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_CONSUME_TIMEOUT)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_CONSUME_TIMEOUT)); consumeTimeout = Long.valueOf(consumeTimeoutStr); } String clientPullBatchSizeStr = - ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_PULL_BATCHSIZE); + ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_PULL_BATCHSIZE); if (StringUtils.isNotEmpty(clientPullBatchSizeStr)) { Preconditions.checkState(StringUtils.isNumeric(clientPullBatchSizeStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_PULL_BATCHSIZE)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_PULL_BATCHSIZE)); pullBatchSize = Integer.valueOf(clientPullBatchSizeStr); } String clientPollNamesrvIntervalStr = - ConfigurationWrapper.getProp( - ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_POLL_NAMESRV_INTERVAL); + ConfigurationWrapper.getProp( + ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_POLL_NAMESRV_INTERVAL); if (StringUtils.isNotEmpty(clientPollNamesrvIntervalStr)) { Preconditions.checkState(StringUtils.isNumeric(clientPollNamesrvIntervalStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_POLL_NAMESRV_INTERVAL)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_POLL_NAMESRV_INTERVAL)); pollNameServerInterval = Integer.valueOf(clientPollNamesrvIntervalStr); } String clientHeartbeatBrokerIntervalStr = - ConfigurationWrapper.getProp( - ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_HEARTBEAT_BROKER_INTERVAL); + ConfigurationWrapper.getProp( + ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_HEARTBEAT_BROKER_INTERVAL); if (StringUtils.isNotEmpty(clientHeartbeatBrokerIntervalStr)) { Preconditions.checkState(StringUtils.isNumeric(clientHeartbeatBrokerIntervalStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_HEARTBEAT_BROKER_INTERVAL)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_HEARTBEAT_BROKER_INTERVAL)); heartbeatBrokerInterval = Integer.valueOf(clientHeartbeatBrokerIntervalStr); } String clientRebalanceIntervalIntervalStr = - ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_REBALANCE_INTERVAL); + ConfigurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_REBALANCE_INTERVAL); if (StringUtils.isNotEmpty(clientRebalanceIntervalIntervalStr)) { Preconditions.checkState(StringUtils.isNumeric(clientRebalanceIntervalIntervalStr), - String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_REBALANCE_INTERVAL)); + String.format("%s error", ConfKeys.KEYS_EVENTMESH_ROCKETMQ_CLIENT_REBALANCE_INTERVAL)); rebalanceInterval = Integer.valueOf(clientRebalanceIntervalIntervalStr); } @@ -162,40 +162,40 @@ static class ConfKeys { public static String KEYS_EVENTMESH_ROCKETMQ_PASSWORD = "eventMesh.server.rocketmq.password"; public static String KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MIN = - "eventMesh.server.rocketmq.client.consumeThreadMin"; + "eventMesh.server.rocketmq.client.consumeThreadMin"; public static String KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_MAX = - "eventMesh.server.rocketmq.client.consumeThreadMax"; + "eventMesh.server.rocketmq.client.consumeThreadMax"; public static String KEYS_EVENTMESH_ROCKETMQ_CONSUME_THREADPOOL_QUEUESIZE = - "eventMesh.server.rocketmq.client.consumeThreadPoolQueueSize"; + "eventMesh.server.rocketmq.client.consumeThreadPoolQueueSize"; public static String KEYS_EVENTMESH_ROCKETMQ_CLIENT_ACK_WINDOW = "eventMesh.server.rocketmq.client.ackwindow"; public static String KEYS_EVENTMESH_ROCKETMQ_CLIENT_PUB_WINDOW = "eventMesh.server.rocketmq.client.pubwindow"; public static String KEYS_EVENTMESH_ROCKETMQ_CLIENT_CONSUME_TIMEOUT = - "eventMesh.server.rocketmq.client.comsumeTimeoutInMin"; + "eventMesh.server.rocketmq.client.comsumeTimeoutInMin"; public static String KEYS_EVENTMESH_ROCKETMQ_CLIENT_PULL_BATCHSIZE = - "eventMesh.server.rocketmq.client.pullBatchSize"; + "eventMesh.server.rocketmq.client.pullBatchSize"; public static String KEYS_EVENTMESH_ROCKETMQ_CLIENT_POLL_NAMESRV_INTERVAL = - "eventMesh.server.rocketmq.client.pollNameServerInterval"; + "eventMesh.server.rocketmq.client.pollNameServerInterval"; public static String KEYS_EVENTMESH_ROCKETMQ_CLIENT_HEARTBEAT_BROKER_INTERVAL = - "eventMesh.server.rocketmq.client.heartbeatBrokerInterval"; + "eventMesh.server.rocketmq.client.heartbeatBrokerInterval"; public static String KEYS_EVENTMESH_ROCKETMQ_CLIENT_REBALANCE_INTERVAL = - "eventMesh.server.rocketmq.client.rebalanceInterval"; + "eventMesh.server.rocketmq.client.rebalanceInterval"; public static String KEYS_EVENTMESH_ROCKETMQ_CLUSTER = "eventMesh.server.rocketmq.cluster"; public static String KEYS_EVENTMESH_ROCKETMQ_ACCESS_KEY = - "eventMesh.server.rocketmq.accessKey"; + "eventMesh.server.rocketmq.accessKey"; public static String KEYS_EVENTMESH_ROCKETMQ_SECRET_KEY = - "eventMesh.server.rocketmq.secretKey"; + "eventMesh.server.rocketmq.secretKey"; } } \ No newline at end of file diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/config/ConfigurationWrapper.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/config/ConfigurationWrapper.java index 9ff3861ad6..51303b2220 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/config/ConfigurationWrapper.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/config/ConfigurationWrapper.java @@ -44,7 +44,7 @@ public class ConfigurationWrapper { properties.load(new BufferedReader(new FileReader(configFile))); } catch (IOException e) { throw new IllegalArgumentException( - String.format("Cannot load RocketMQ configuration file from :%s", configFile)); + String.format("Cannot load RocketMQ configuration file from :%s", configFile)); } } diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/connector/ConnectorResourceServiceRocketmqImpl.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/connector/ConnectorResourceServiceRocketmqImpl.java index f802ec0773..f26747e9db 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/connector/ConnectorResourceServiceRocketmqImpl.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/connector/ConnectorResourceServiceRocketmqImpl.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.connector.rocketmq.connector; import org.apache.eventmesh.api.connector.ConnectorResourceService; diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/PushConsumerImpl.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/PushConsumerImpl.java index e7e5ae8e7e..348e4364b9 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/PushConsumerImpl.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/PushConsumerImpl.java @@ -32,15 +32,14 @@ import org.apache.eventmesh.connector.rocketmq.patch.EventMeshConsumeConcurrentlyStatus; import org.apache.eventmesh.connector.rocketmq.patch.EventMeshMessageListenerConcurrently; import org.apache.eventmesh.connector.rocketmq.utils.BeanUtils; -import org.apache.eventmesh.connector.rocketmq.utils.OMSUtil; import org.apache.eventmesh.connector.rocketmq.utils.CloudEventUtils; +import org.apache.eventmesh.connector.rocketmq.utils.OMSUtil; import org.apache.commons.lang3.StringUtils; import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.exception.MQClientException; import org.apache.rocketmq.client.impl.consumer.ConsumeMessageConcurrentlyService; import org.apache.rocketmq.client.impl.consumer.ConsumeMessageService; -import org.apache.rocketmq.client.utils.MessageUtil; import org.apache.rocketmq.common.message.MessageConst; import org.apache.rocketmq.common.message.MessageExt; import org.apache.rocketmq.common.protocol.heartbeat.MessageModel; @@ -76,7 +75,7 @@ public PushConsumerImpl(final Properties properties) { String consumerGroup = clientConfig.getConsumerId(); if (null == consumerGroup || consumerGroup.isEmpty()) { throw new ConnectorRuntimeException( - "Consumer Group is necessary for RocketMQ, please set it."); + "Consumer Group is necessary for RocketMQ, please set it."); } this.rocketmqPushConsumer.setConsumerGroup(consumerGroup); this.rocketmqPushConsumer.setMaxReconsumeTimes(clientConfig.getRmqMaxRedeliveryTimes()); @@ -84,7 +83,7 @@ public PushConsumerImpl(final Properties properties) { this.rocketmqPushConsumer.setConsumeThreadMax(clientConfig.getRmqMaxConsumeThreadNums()); this.rocketmqPushConsumer.setConsumeThreadMin(clientConfig.getRmqMinConsumeThreadNums()); this.rocketmqPushConsumer.setMessageModel( - MessageModel.valueOf(clientConfig.getMessageModel())); + MessageModel.valueOf(clientConfig.getMessageModel())); String consumerId = OMSUtil.buildInstanceName(); //this.rocketmqPushConsumer.setInstanceName(consumerId); @@ -157,14 +156,14 @@ public void unsubscribe(String topic) { public void updateOffset(List cloudEvents, AbstractContext context) { ConsumeMessageService consumeMessageService = rocketmqPushConsumer - .getDefaultMQPushConsumerImpl().getConsumeMessageService(); + .getDefaultMQPushConsumerImpl().getConsumeMessageService(); List msgExtList = new ArrayList<>(cloudEvents.size()); for (CloudEvent msg : cloudEvents) { msgExtList.add(CloudEventUtils.msgConvertExt( - RocketMQMessageFactory.createWriter(msg.getSubject()).writeBinary(msg))); + RocketMQMessageFactory.createWriter(msg.getSubject()).writeBinary(msg))); } ((ConsumeMessageConcurrentlyService) consumeMessageService) - .updateOffset(msgExtList, (EventMeshConsumeConcurrentlyContext) context); + .updateOffset(msgExtList, (EventMeshConsumeConcurrentlyContext) context); } @@ -178,13 +177,13 @@ public EventMeshConsumeConcurrentlyStatus handleMessage(MessageExt msg, } msg.putUserProperty(Constants.PROPERTY_MESSAGE_BORN_TIMESTAMP, - String.valueOf(msg.getBornTimestamp())); + String.valueOf(msg.getBornTimestamp())); msg.putUserProperty(Constants.PROPERTY_MESSAGE_STORE_TIMESTAMP, - String.valueOf(msg.getStoreTimestamp())); + String.valueOf(msg.getStoreTimestamp())); //for rr request/reply CloudEvent cloudEvent = - RocketMQMessageFactory.createReader(CloudEventUtils.msgConvert(msg)).toEvent(); + RocketMQMessageFactory.createReader(CloudEventUtils.msgConvert(msg)).toEvent(); CloudEventBuilder cloudEventBuilder = null; for (String sysPropKey : MessageConst.STRING_HASH_SET) { @@ -207,22 +206,22 @@ public EventMeshConsumeConcurrentlyStatus handleMessage(MessageExt msg, final Properties contextProperties = new Properties(); contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, - EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); + EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); AsyncConsumeContext asyncConsumeContext = new AsyncConsumeContext() { @Override public void commit(EventMeshAction action) { switch (action) { case CommitMessage: contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, - EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); break; case ReconsumeLater: contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, - EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); + EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); break; case ManualAck: contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, - EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); + EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); break; default: break; @@ -233,7 +232,7 @@ public void commit(EventMeshAction action) { listener.consume(cloudEvent, asyncConsumeContext); return EventMeshConsumeConcurrentlyStatus.valueOf( - contextProperties.getProperty(NonStandardKeys.MESSAGE_CONSUME_STATUS)); + contextProperties.getProperty(NonStandardKeys.MESSAGE_CONSUME_STATUS)); } @@ -249,12 +248,12 @@ public EventMeshConsumeConcurrentlyStatus handleMessage(MessageExt msg, } msg.putUserProperty(Constants.PROPERTY_MESSAGE_BORN_TIMESTAMP, - String.valueOf(msg.getBornTimestamp())); + String.valueOf(msg.getBornTimestamp())); msg.putUserProperty(EventMeshConstants.STORE_TIMESTAMP, - String.valueOf(msg.getStoreTimestamp())); + String.valueOf(msg.getStoreTimestamp())); CloudEvent cloudEvent = - RocketMQMessageFactory.createReader(CloudEventUtils.msgConvert(msg)).toEvent(); + RocketMQMessageFactory.createReader(CloudEventUtils.msgConvert(msg)).toEvent(); CloudEventBuilder cloudEventBuilder = null; @@ -279,7 +278,7 @@ public EventMeshConsumeConcurrentlyStatus handleMessage(MessageExt msg, final Properties contextProperties = new Properties(); contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, - EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); + EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = new EventMeshAsyncConsumeContext() { @Override @@ -287,15 +286,15 @@ public void commit(EventMeshAction action) { switch (action) { case CommitMessage: contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, - EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); break; case ReconsumeLater: contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, - EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); + EventMeshConsumeConcurrentlyStatus.RECONSUME_LATER.name()); break; case ManualAck: contextProperties.put(NonStandardKeys.MESSAGE_CONSUME_STATUS, - EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); + EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); break; default: break; @@ -308,7 +307,7 @@ public void commit(EventMeshAction action) { listener.consume(cloudEvent, eventMeshAsyncConsumeContext); return EventMeshConsumeConcurrentlyStatus.valueOf( - contextProperties.getProperty(NonStandardKeys.MESSAGE_CONSUME_STATUS)); + contextProperties.getProperty(NonStandardKeys.MESSAGE_CONSUME_STATUS)); } } diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/RocketMQConsumerImpl.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/RocketMQConsumerImpl.java index 5e4d4d3c95..12fc214475 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/RocketMQConsumerImpl.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/consumer/RocketMQConsumerImpl.java @@ -32,6 +32,7 @@ import org.slf4j.LoggerFactory; import io.cloudevents.CloudEvent; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -46,14 +47,14 @@ public synchronized void init(Properties keyValue) throws Exception { final ClientConfiguration clientConfiguration = new ClientConfiguration(); clientConfiguration.init(); boolean isBroadcast = Boolean.parseBoolean(keyValue.getProperty("isBroadcast")); - String consumerGroup = keyValue.getProperty("consumerGroup"); - String instanceName = keyValue.getProperty("instanceName"); + String consumerGroup = keyValue.getProperty("consumerGroup"); if (isBroadcast) { consumerGroup = Constants.BROADCAST_PREFIX + consumerGroup; } String namesrvAddr = clientConfiguration.namesrvAddr; + String instanceName = keyValue.getProperty("instanceName"); Properties properties = new Properties(); properties.put("ACCESS_POINTS", namesrvAddr); properties.put("REGION", "namespace"); diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/domain/NonStandardKeys.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/domain/NonStandardKeys.java index 5264d785e0..c36aaf8bbe 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/domain/NonStandardKeys.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/domain/NonStandardKeys.java @@ -17,6 +17,9 @@ package org.apache.eventmesh.connector.rocketmq.domain; +/** + * NonStandardKeys + */ public interface NonStandardKeys { String CONSUMER_GROUP = "rmq.consumer.group"; String PRODUCER_GROUP = "rmq.producer.group"; diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/domain/RocketMQConstants.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/domain/RocketMQConstants.java index 063f0f36fc..f387d3c7fb 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/domain/RocketMQConstants.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/domain/RocketMQConstants.java @@ -17,6 +17,9 @@ package org.apache.eventmesh.connector.rocketmq.domain; +/** + * RocketMQConstants + */ public interface RocketMQConstants { /** diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/patch/EventMeshConsumeConcurrentlyContext.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/patch/EventMeshConsumeConcurrentlyContext.java index 05442a6ab2..2dcfa95038 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/patch/EventMeshConsumeConcurrentlyContext.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/patch/EventMeshConsumeConcurrentlyContext.java @@ -18,6 +18,7 @@ package org.apache.eventmesh.connector.rocketmq.patch; import org.apache.eventmesh.api.AbstractContext; + import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.impl.consumer.ProcessQueue; import org.apache.rocketmq.common.message.MessageQueue; diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/patch/EventMeshMessageListenerConcurrently.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/patch/EventMeshMessageListenerConcurrently.java index 47e8ee11be..0d32ba27d3 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/patch/EventMeshMessageListenerConcurrently.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/patch/EventMeshMessageListenerConcurrently.java @@ -17,13 +17,14 @@ package org.apache.eventmesh.connector.rocketmq.patch; -import java.util.List; - import org.apache.commons.collections4.CollectionUtils; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently; import org.apache.rocketmq.common.message.MessageExt; + +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -53,6 +54,8 @@ public ConsumeConcurrentlyStatus consumeMessage(final List msgs, case CONSUME_FINISH: eventMeshConsumeConcurrentlyContext.setManualAck(true); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; + default: + return status; } } catch (Throwable e) { LOG.info("handleMessage fail", e); @@ -62,7 +65,7 @@ public ConsumeConcurrentlyStatus consumeMessage(final List msgs, LOG.info("handleMessage fail", e); return ConsumeConcurrentlyStatus.CONSUME_SUCCESS; } - return status; + //return status; } public abstract EventMeshConsumeConcurrentlyStatus handleMessage(MessageExt msg, EventMeshConsumeConcurrentlyContext context); diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/AbstractProducer.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/AbstractProducer.java index 3b0b7ce55d..e95a47f0b6 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/AbstractProducer.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/AbstractProducer.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.connector.rocketmq.producer; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicBoolean; - import org.apache.eventmesh.api.exception.ConnectorRuntimeException; import org.apache.eventmesh.connector.rocketmq.config.ClientConfig; import org.apache.eventmesh.connector.rocketmq.exception.RMQMessageFormatException; @@ -38,15 +35,18 @@ import org.apache.rocketmq.remoting.exception.RemotingTimeoutException; import org.apache.rocketmq.remoting.protocol.LanguageCode; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicBoolean; + public abstract class AbstractProducer { - final static InternalLogger log = ClientLogger.getLog(); + static final InternalLogger log = ClientLogger.getLog(); final Properties properties; final DefaultMQProducer rocketmqProducer; protected final AtomicBoolean started = new AtomicBoolean(false); // private boolean started = false; private final ClientConfig clientConfig; - private final String PRODUCER_ID = "PRODUCER_ID"; + private static final String PRODUCER_ID = "PRODUCER_ID"; AbstractProducer(final Properties properties) { this.properties = properties; @@ -101,39 +101,37 @@ ConnectorRuntimeException checkProducerException(String topic, String msgId, Thr if (e.getCause() != null) { if (e.getCause() instanceof RemotingTimeoutException) { return new RMQTimeoutException( - String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s", - this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e); - } else if (e.getCause() instanceof MQBrokerException || - e.getCause() instanceof RemotingConnectException) { + String.format("Send message to broker timeout, %dms, Topic=%s, msgId=%s", + this.rocketmqProducer.getSendMsgTimeout(), topic, msgId), e); + } else if (e.getCause() instanceof MQBrokerException + || e.getCause() instanceof RemotingConnectException) { if (e.getCause() instanceof MQBrokerException) { MQBrokerException brokerException = (MQBrokerException) e.getCause(); return new ConnectorRuntimeException( - String.format("Received a broker exception, Topic=%s, msgId=%s, %s", - topic, msgId, brokerException.getErrorMessage()), e); + String.format("Received a broker exception, Topic=%s, msgId=%s, %s", + topic, msgId, brokerException.getErrorMessage()), e); } if (e.getCause() instanceof RemotingConnectException) { RemotingConnectException connectException = - (RemotingConnectException) e.getCause(); + (RemotingConnectException) e.getCause(); return new ConnectorRuntimeException( - String.format( - "Network connection experiences failures. Topic=%s, msgId=%s, %s", - topic, msgId, connectException.getMessage()), - e); + String.format( + "Network connection experiences failures. Topic=%s, msgId=%s, %s", + topic, msgId, connectException.getMessage()), e); } } - } - // Exception thrown by local. - else { + } else { + // Exception thrown by local. MQClientException clientException = (MQClientException) e; if (-1 == clientException.getResponseCode()) { return new ConnectorRuntimeException( - String.format("Topic does not exist, Topic=%s, msgId=%s", - topic, msgId), e); + String.format("Topic does not exist, Topic=%s, msgId=%s", + topic, msgId), e); } else if (ResponseCode.MESSAGE_ILLEGAL == clientException.getResponseCode()) { return new RMQMessageFormatException( - String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s", - topic, msgId), e); + String.format("A illegal message for RocketMQ, Topic=%s, msgId=%s", + topic, msgId), e); } } } @@ -144,16 +142,16 @@ protected void checkProducerServiceState(DefaultMQProducerImpl producer) { switch (producer.getServiceState()) { case CREATE_JUST: throw new ConnectorRuntimeException( - String.format("You do not have start the producer, %s", - producer.getServiceState())); + String.format("You do not have start the producer, %s", + producer.getServiceState())); case SHUTDOWN_ALREADY: throw new ConnectorRuntimeException( - String.format("Your producer has been shut down, %s", - producer.getServiceState())); + String.format("Your producer has been shut down, %s", + producer.getServiceState())); case START_FAILED: throw new ConnectorRuntimeException( - String.format("When you start your service throws an exception, %s", - producer.getServiceState())); + String.format("When you start your service throws an exception, %s", + producer.getServiceState())); case RUNNING: default: } diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/ProducerImpl.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/ProducerImpl.java index 89c6b98b4f..fd4cecc710 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/ProducerImpl.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/ProducerImpl.java @@ -40,6 +40,7 @@ import java.util.Properties; import io.cloudevents.CloudEvent; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -62,7 +63,7 @@ public void setExtFields() { super.getRocketmqProducer().setPollNameServerInterval(60000); super.getRocketmqProducer().getDefaultMQProducerImpl().getmQClientFactory().getNettyClientConfig() - .setClientAsyncSemaphoreValue(eventMeshServerAsyncAccumulationThreshold); + .setClientAsyncSemaphoreValue(eventMeshServerAsyncAccumulationThreshold); super.getRocketmqProducer().setCompressMsgBodyOverHowmuch(10); } @@ -70,7 +71,7 @@ public void setExtFields() { public SendResult send(CloudEvent cloudEvent) { this.checkProducerServiceState(rocketmqProducer.getDefaultMQProducerImpl()); org.apache.rocketmq.common.message.Message msg = - RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); + RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); msg = supplySysProp(msg, cloudEvent); String messageId = null; try { @@ -90,7 +91,7 @@ public SendResult send(CloudEvent cloudEvent) { public void sendOneway(CloudEvent cloudEvent) { this.checkProducerServiceState(this.rocketmqProducer.getDefaultMQProducerImpl()); org.apache.rocketmq.common.message.Message msg = - RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); + RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); msg = supplySysProp(msg, cloudEvent); try { this.rocketmqProducer.sendOneway(msg); @@ -104,7 +105,7 @@ public void sendOneway(CloudEvent cloudEvent) { public void sendAsync(CloudEvent cloudEvent, SendCallback sendCallback) { this.checkProducerServiceState(this.rocketmqProducer.getDefaultMQProducerImpl()); org.apache.rocketmq.common.message.Message msg = - RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); + RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); msg = supplySysProp(msg, cloudEvent); try { this.rocketmqProducer.send(msg, this.sendCallbackConvert(msg, sendCallback)); @@ -115,11 +116,11 @@ public void sendAsync(CloudEvent cloudEvent, SendCallback sendCallback) { } public void request(CloudEvent cloudEvent, RequestReplyCallback rrCallback, long timeout) - throws InterruptedException, RemotingException, MQClientException, MQBrokerException { + throws InterruptedException, RemotingException, MQClientException, MQBrokerException { this.checkProducerServiceState(this.rocketmqProducer.getDefaultMQProducerImpl()); org.apache.rocketmq.common.message.Message msg = - RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); + RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); msg = supplySysProp(msg, cloudEvent); @@ -129,7 +130,7 @@ public void request(CloudEvent cloudEvent, RequestReplyCallback rrCallback, long public boolean reply(final CloudEvent cloudEvent, final SendCallback sendCallback) { this.checkProducerServiceState(this.rocketmqProducer.getDefaultMQProducerImpl()); org.apache.rocketmq.common.message.Message msg = - RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); + RocketMQMessageFactory.createWriter(cloudEvent.getSubject()).writeBinary(cloudEvent); MessageAccessor.putProperty(msg, MessageConst.PROPERTY_MESSAGE_TYPE, MixAll.REPLY_MESSAGE_FLAG); msg = supplySysProp(msg, cloudEvent); @@ -187,22 +188,22 @@ public void onException(Throwable e) { private org.apache.rocketmq.client.producer.SendCallback sendCallbackConvert(final Message message, final SendCallback sendCallback) { org.apache.rocketmq.client.producer.SendCallback rmqSendCallback = - new org.apache.rocketmq.client.producer.SendCallback() { - @Override - public void onSuccess(org.apache.rocketmq.client.producer.SendResult sendResult) { - sendCallback.onSuccess(CloudEventUtils.convertSendResult(sendResult)); - } + new org.apache.rocketmq.client.producer.SendCallback() { + @Override + public void onSuccess(org.apache.rocketmq.client.producer.SendResult sendResult) { + sendCallback.onSuccess(CloudEventUtils.convertSendResult(sendResult)); + } - @Override - public void onException(Throwable e) { - String topic = message.getTopic(); - ConnectorRuntimeException onsEx = ProducerImpl.this.checkProducerException(topic, null, e); - OnExceptionContext context = new OnExceptionContext(); - context.setTopic(topic); - context.setException(onsEx); - sendCallback.onException(context); - } - }; + @Override + public void onException(Throwable e) { + String topic = message.getTopic(); + ConnectorRuntimeException onsEx = ProducerImpl.this.checkProducerException(topic, null, e); + OnExceptionContext context = new OnExceptionContext(); + context.setTopic(topic); + context.setException(onsEx); + sendCallback.onException(context); + } + }; return rmqSendCallback; } diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/RocketMQProducerImpl.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/RocketMQProducerImpl.java index 47ed2b1d83..366f3b341a 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/RocketMQProducerImpl.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/producer/RocketMQProducerImpl.java @@ -31,6 +31,7 @@ import java.util.Properties; import io.cloudevents.CloudEvent; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -82,9 +83,14 @@ public void publish(CloudEvent message, SendCallback sendCallback) throws Except producer.sendAsync(message, sendCallback); } + @Override + public SendResult publish(CloudEvent message) { + return producer.send(message); + } + @Override public void request(CloudEvent message, RequestReplyCallback rrCallback, long timeout) - throws InterruptedException, RemotingException, MQClientException, MQBrokerException { + throws InterruptedException, RemotingException, MQClientException, MQBrokerException { producer.request(message, rrCallback, timeout); } @@ -97,7 +103,7 @@ public boolean reply(final CloudEvent message, final SendCallback sendCallback) @Override public void checkTopicExist(String topic) throws Exception { this.producer.getRocketmqProducer().getDefaultMQProducerImpl().getmQClientFactory().getMQClientAPIImpl() - .getDefaultTopicRouteInfoFromNameServer(topic, EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); + .getDefaultTopicRouteInfoFromNameServer(topic, EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); } @Override @@ -105,10 +111,6 @@ public void setExtFields() { producer.setExtFields(); } - @Override - public SendResult publish(CloudEvent message) { - return producer.send(message); - } @Override public void sendOneway(CloudEvent message) { diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/BeanUtils.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/BeanUtils.java index 0aae801dcf..1dfc77535a 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/BeanUtils.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/BeanUtils.java @@ -17,6 +17,10 @@ package org.apache.eventmesh.connector.rocketmq.utils; +import org.apache.commons.lang3.StringUtils; +import org.apache.rocketmq.client.log.ClientLogger; +import org.apache.rocketmq.logging.InternalLogger; + import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; @@ -24,12 +28,9 @@ import java.util.Properties; import java.util.Set; -import org.apache.commons.lang3.StringUtils; -import org.apache.rocketmq.client.log.ClientLogger; -import org.apache.rocketmq.logging.InternalLogger; - public final class BeanUtils { - final static InternalLogger log = ClientLogger.getLog(); + + private static final InternalLogger log = ClientLogger.getLog(); /** * Maps primitive {@code Class}es to their corresponding wrapper {@code Class}. @@ -95,16 +96,41 @@ public static T populate(final Properties properties, final Class clazz) return obj; } -// public static T populate(final KeyValue properties, final Class clazz) { -// T obj = null; -// try { -// obj = clazz.newInstance(); -// return populate(properties, obj); -// } catch (Throwable e) { -// log.warn("Error occurs !", e); -// } -// return obj; -// } + public static T populate(final Properties properties, final T obj) { + Class clazz = obj.getClass(); + try { + + Set> entries = properties.entrySet(); + for (Map.Entry entry : entries) { + String entryKey = entry.getKey().toString(); + String[] keyGroup = entryKey.split("[\\._]"); + for (int i = 0; i < keyGroup.length; i++) { + keyGroup[i] = keyGroup[i].toLowerCase(); + keyGroup[i] = StringUtils.capitalize(keyGroup[i]); + } + String beanFieldNameWithCapitalization = StringUtils.join(keyGroup); + try { + setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, entry.getValue()); + } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { + //ignored... + } + } + } catch (RuntimeException e) { + log.warn("Error occurs !", e); + } + return obj; + } + + //public static T populate(final KeyValue properties, final Class clazz) { + // T obj = null; + // try { + // obj = clazz.newInstance(); + // return populate(properties, obj); + // } catch (Throwable e) { + // log.warn("Error occurs !", e); + // } + // return obj; + //} public static Class getMethodClass(Class clazz, String methodName) { Method[] methods = clazz.getMethods(); @@ -135,53 +161,29 @@ public static void setProperties(Class clazz, Object obj, String methodName, } } - public static T populate(final Properties properties, final T obj) { - Class clazz = obj.getClass(); - try { - - Set> entries = properties.entrySet(); - for (Map.Entry entry : entries) { - String entryKey = entry.getKey().toString(); - String[] keyGroup = entryKey.split("[\\._]"); - for (int i = 0; i < keyGroup.length; i++) { - keyGroup[i] = keyGroup[i].toLowerCase(); - keyGroup[i] = StringUtils.capitalize(keyGroup[i]); - } - String beanFieldNameWithCapitalization = StringUtils.join(keyGroup); - try { - setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, entry.getValue()); - } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { - //ignored... - } - } - } catch (RuntimeException e) { - log.warn("Error occurs !", e); - } - return obj; - } -// public static T populate(final Properties properties, final T obj) { -// Class clazz = obj.getClass(); -// try { -// -// final Set keySet = properties.keySet(); -// for (Object key : keySet) { -// String[] keyGroup = key.toString().split("[\\._]"); -// for (int i = 0; i < keyGroup.length; i++) { -// keyGroup[i] = keyGroup[i].toLowerCase(); -// keyGroup[i] = StringUtils.capitalize(keyGroup[i]); -// } -// String beanFieldNameWithCapitalization = StringUtils.join(keyGroup); -// try { -// setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, properties.getProperty(key.toString())); -// } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { -// //ignored... -// } -// } -// } catch (RuntimeException e) { -// log.warn("Error occurs !", e); -// } -// return obj; -// } + //public static T populate(final Properties properties, final T obj) { + // Class clazz = obj.getClass(); + // try { + // + // final Set keySet = properties.keySet(); + // for (Object key : keySet) { + // String[] keyGroup = key.toString().split("[\\._]"); + // for (int i = 0; i < keyGroup.length; i++) { + // keyGroup[i] = keyGroup[i].toLowerCase(); + // keyGroup[i] = StringUtils.capitalize(keyGroup[i]); + // } + // String beanFieldNameWithCapitalization = StringUtils.join(keyGroup); + // try { + // setProperties(clazz, obj, "set" + beanFieldNameWithCapitalization, properties.getProperty(key.toString())); + // } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ignored) { + // //ignored... + // } + // } + // } catch (RuntimeException e) { + // log.warn("Error occurs !", e); + // } + // return obj; + //} } diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/CloudEventUtils.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/CloudEventUtils.java index 2073468895..b2dc90eaf5 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/CloudEventUtils.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/CloudEventUtils.java @@ -32,7 +32,7 @@ public class CloudEventUtils { public static SendResult convertSendResult( - org.apache.rocketmq.client.producer.SendResult rmqResult) { + org.apache.rocketmq.client.producer.SendResult rmqResult) { SendResult sendResult = new SendResult(); sendResult.setTopic(rmqResult.getMessageQueue().getTopic()); sendResult.setMessageId(rmqResult.getMsgId()); @@ -66,29 +66,29 @@ public static Message msgConvert(MessageExt rmqMsg) { if (rmqMsg.getMsgId() != null) { MessageAccessor.putProperty(message, buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_MESSAGE_ID), - rmqMsg.getMsgId()); + rmqMsg.getMsgId()); } if (rmqMsg.getTopic() != null) { MessageAccessor.putProperty(message, buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_DESTINATION), - rmqMsg.getTopic()); + rmqMsg.getTopic()); } // MessageAccessor.putProperty(message, buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_BORN_HOST), - String.valueOf(rmqMsg.getBornHost())); + String.valueOf(rmqMsg.getBornHost())); MessageAccessor.putProperty(message, buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_BORN_TIMESTAMP), - String.valueOf(rmqMsg.getBornTimestamp())); + String.valueOf(rmqMsg.getBornTimestamp())); MessageAccessor.putProperty(message, buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_STORE_HOST), - String.valueOf(rmqMsg.getStoreHost())); + String.valueOf(rmqMsg.getStoreHost())); MessageAccessor.putProperty(message, buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_STORE_TIMESTAMP), - String.valueOf(rmqMsg.getStoreTimestamp())); + String.valueOf(rmqMsg.getStoreTimestamp())); //use in manual ack MessageAccessor.putProperty(message, buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_QUEUE_ID), - String.valueOf(rmqMsg.getQueueId())); + String.valueOf(rmqMsg.getQueueId())); MessageAccessor.putProperty(message, buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_QUEUE_OFFSET), - String.valueOf(rmqMsg.getQueueOffset())); + String.valueOf(rmqMsg.getQueueOffset())); for (String sysPropKey : MessageConst.STRING_HASH_SET) { if (StringUtils.isNotEmpty(message.getProperty(sysPropKey))) { @@ -103,7 +103,6 @@ public static Message msgConvert(MessageExt rmqMsg) { } - private static String buildCloudEventPropertyKey(String propName) { //return RocketMQHeaders.CE_PREFIX + propName; return propName; @@ -112,7 +111,7 @@ private static String buildCloudEventPropertyKey(String propName) { public static org.apache.rocketmq.common.message.MessageExt msgConvertExt(Message message) { org.apache.rocketmq.common.message.MessageExt rmqMessageExt = - new org.apache.rocketmq.common.message.MessageExt(); + new org.apache.rocketmq.common.message.MessageExt(); try { if (message.getKeys() != null) { rmqMessageExt.setKeys(message.getKeys()); @@ -131,9 +130,9 @@ public static org.apache.rocketmq.common.message.MessageExt msgConvertExt(Messag rmqMessageExt.setTopic(message.getTopic()); int queueId = - Integer.parseInt(message.getProperty(buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_QUEUE_ID))); + Integer.parseInt(message.getProperty(buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_QUEUE_ID))); long queueOffset = Long.parseLong( - message.getProperty(buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_QUEUE_OFFSET))); + message.getProperty(buildCloudEventPropertyKey(Constants.PROPERTY_MESSAGE_QUEUE_OFFSET))); //use in manual ack rmqMessageExt.setQueueId(queueId); rmqMessageExt.setQueueOffset(queueOffset); diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/OMSUtil.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/OMSUtil.java index dd2a36bd8a..7d00e80620 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/OMSUtil.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/eventmesh/connector/rocketmq/utils/OMSUtil.java @@ -17,18 +17,7 @@ package org.apache.eventmesh.connector.rocketmq.utils; -import java.lang.reflect.Field; -import java.util.Iterator; -import java.util.Map; -import java.util.NoSuchElementException; -import java.util.Properties; -import java.util.Set; - - -import org.apache.eventmesh.common.Constants; import org.apache.rocketmq.common.UtilAll; -import org.apache.rocketmq.common.message.MessageAccessor; -import org.apache.rocketmq.common.message.MessageExt; public class OMSUtil { @@ -41,252 +30,252 @@ public static String buildInstanceName() { return Integer.toString(UtilAll.getPid()) + "%EventMesh" + "%" + System.nanoTime(); } -// public static org.apache.rocketmq.common.message.Message msgConvert(Message omsMessage) { -// org.apache.rocketmq.common.message.Message rmqMessage = new org.apache.rocketmq.common.message.Message(); -// if (omsMessage == null) { -// throw new OMSRuntimeException("'message' is null"); -// } else { -// if (omsMessage.getTopic() != null) { -// rmqMessage.setTopic(omsMessage.getTopic()); -// } -// if (omsMessage.getKey() != null) { -// rmqMessage.setKeys(omsMessage.getKey()); -// } -// if (omsMessage.getTag() != null) { -// rmqMessage.setTags(omsMessage.getTag()); -// } -// if (omsMessage.getStartDeliverTime() > 0L) { -// rmqMessage.putUserProperty("TIMER_DELIVER_MS", String.valueOf(omsMessage.getStartDeliverTime())); -// } -// -// if (omsMessage.getBody() != null) { -// rmqMessage.setBody(omsMessage.getBody()); -// } -// -// if (omsMessage.getShardingKey() != null && !omsMessage.getShardingKey().isEmpty()) { -// rmqMessage.putUserProperty("__SHARDINGKEY", omsMessage.getShardingKey()); -// } -// } -// Properties systemProperties = omsMessage.getSystemProperties(); -// Properties userProperties = omsMessage.getUserProperties(); -// -// //All destinations in RocketMQ use Topic -//// rmqMessage.setTopic(systemProperties.getProperty(BuiltinKeys.DESTINATION)); -// -//// if (sysHeaders.containsKey(BuiltinKeys.START_TIME)) { -//// long deliverTime = sysHeaders.getLong(BuiltinKeys.START_TIME, 0); -//// if (deliverTime > 0) { -//// rmqMessage.putUserProperty(RocketMQConstants.START_DELIVER_TIME, String.valueOf(deliverTime)); -//// } -//// } -// -// for (String key : userProperties.stringPropertyNames()) { -// MessageAccessor.putProperty(rmqMessage, key, userProperties.getProperty(key)); -// } -// -// //System headers has a high priority -// for (String key : systemProperties.stringPropertyNames()) { -// MessageAccessor.putProperty(rmqMessage, key, systemProperties.getProperty(key)); -// } -// -// return rmqMessage; -// } -// -// public static Message msgConvert(MessageExt rmqMsg) { -// Message message = new Message(); -// if (rmqMsg.getTopic() != null) { -// message.setTopic(rmqMsg.getTopic()); -// } -// -// if (rmqMsg.getKeys() != null) { -// message.setKey(rmqMsg.getKeys()); -// } -// -// if (rmqMsg.getTags() != null) { -// message.setTag(rmqMsg.getTags()); -// } -// -// if (rmqMsg.getBody() != null) { -// message.setBody(rmqMsg.getBody()); -// } -// -// if (rmqMsg.getUserProperty("TIMER_DELIVER_MS") != null) { -// long ms = Long.parseLong(rmqMsg.getUserProperty("TIMER_DELIVER_MS")); -// rmqMsg.getProperties().remove("TIMER_DELIVER_MS"); -// message.setStartDeliverTime(ms); -// } -// -// Properties systemProperties = new Properties(); -// Properties userProperties = new Properties(); -// -// -// final Set> entries = rmqMsg.getProperties().entrySet(); -// -// for (final Map.Entry entry : entries) { -// if (isOMSHeader(entry.getKey())) { -// //sysHeader -// systemProperties.put(entry.getKey(), entry.getValue()); -// } else { -// //userHeader -// userProperties.put(entry.getKey(), entry.getValue()); -// } -// } -// -// if (rmqMsg.getMsgId() != null){ -// systemProperties.put(Constants.PROPERTY_MESSAGE_MESSAGE_ID, rmqMsg.getMsgId()); -// } -// -// if (rmqMsg.getTopic() != null){ -// systemProperties.put(Constants.PROPERTY_MESSAGE_DESTINATION, rmqMsg.getTopic()); -// } -// -//// omsMsg.putSysHeaders(BuiltinKeys.SEARCH_KEYS, rmqMsg.getKeys()); -// systemProperties.put(Constants.PROPERTY_MESSAGE_BORN_HOST, String.valueOf(rmqMsg.getBornHost())); -// systemProperties.put(Constants.PROPERTY_MESSAGE_BORN_TIMESTAMP, rmqMsg.getBornTimestamp()); -// systemProperties.put(Constants.PROPERTY_MESSAGE_STORE_HOST, String.valueOf(rmqMsg.getStoreHost())); -// systemProperties.put("STORE_TIMESTAMP", rmqMsg.getStoreTimestamp()); -// -// //use in manual ack -// userProperties.put(Constants.PROPERTY_MESSAGE_QUEUE_ID, rmqMsg.getQueueId()); -// userProperties.put(Constants.PROPERTY_MESSAGE_QUEUE_OFFSET, rmqMsg.getQueueOffset()); -// -// message.setSystemProperties(systemProperties); -// message.setUserProperties(userProperties); -// -// return message; -// } -// -// public static org.apache.rocketmq.common.message.MessageExt msgConvertExt(Message omsMessage) { -// -// org.apache.rocketmq.common.message.MessageExt rmqMessageExt = new org.apache.rocketmq.common.message.MessageExt(); -// try { -// if (omsMessage.getKey() != null) { -// rmqMessageExt.setKeys(omsMessage.getKey()); -// } -// if (omsMessage.getTag() != null) { -// rmqMessageExt.setTags(omsMessage.getTag()); -// } -// if (omsMessage.getStartDeliverTime() > 0L) { -// rmqMessageExt.putUserProperty("TIMER_DELIVER_MS", String.valueOf(omsMessage.getStartDeliverTime())); -// } -// -// if (omsMessage.getBody() != null) { -// rmqMessageExt.setBody(omsMessage.getBody()); -// } -// -// if (omsMessage.getShardingKey() != null && !omsMessage.getShardingKey().isEmpty()) { -// rmqMessageExt.putUserProperty("__SHARDINGKEY", omsMessage.getShardingKey()); -// } -// -// Properties systemProperties = omsMessage.getSystemProperties(); -// Properties userProperties = omsMessage.getUserProperties(); -// -// //All destinations in RocketMQ use Topic -// rmqMessageExt.setTopic(omsMessage.getTopic()); -// -// int queueId = (int) userProperties.get(Constants.PROPERTY_MESSAGE_QUEUE_ID); -// long queueOffset = (long) userProperties.get(Constants.PROPERTY_MESSAGE_QUEUE_OFFSET); -// //use in manual ack -// rmqMessageExt.setQueueId(queueId); -// rmqMessageExt.setQueueOffset(queueOffset); -// -// for (String key : userProperties.stringPropertyNames()) { -// MessageAccessor.putProperty(rmqMessageExt, key, userProperties.getProperty(key)); -// } -// -// //System headers has a high priority -// for (String key : systemProperties.stringPropertyNames()) { -// MessageAccessor.putProperty(rmqMessageExt, key, systemProperties.getProperty(key)); -// } -// -// } catch (Exception e) { -// e.printStackTrace(); -// } -// return rmqMessageExt; -// -// } -// -// public static boolean isOMSHeader(String value) { -// for (Field field : OMSBuiltinKeys.class.getDeclaredFields()) { -// try { -// if (field.get(OMSBuiltinKeys.class).equals(value)) { -// return true; -// } -// } catch (IllegalAccessException e) { -// return false; -// } -// } -// return false; -// } -// -// /** -// * Convert a RocketMQ SEND_OK SendResult instance to a OMS SendResult. -// * -// * @param rmqResult RocketMQ result -// * @return send result -// */ -// public static SendResult sendResultConvert(org.apache.rocketmq.client.producer.SendResult rmqResult) { -// SendResult sendResult = new SendResult(); -// sendResult.setTopic(rmqResult.getMessageQueue().getTopic()); -// sendResult.setMessageId(rmqResult.getMsgId()); -// return sendResult; -// } -// -//// public static KeyValue buildKeyValue(KeyValue... keyValues) { -//// KeyValue keyValue = OMS.newKeyValue(); -//// for (KeyValue properties : keyValues) { -//// for (String key : properties.keySet()) { -//// keyValue.put(key, properties.getString(key)); -//// } -//// } -//// return keyValue; -//// } -// -// /** -// * Returns an iterator that cycles indefinitely over the elements of {@code Iterable}. -// * -// * @param Target type -// * @return Iterator -// */ -// public static Iterator cycle(final Iterable iterable) { -// return new Iterator() { -// Iterator iterator = new Iterator() { -// @Override -// public synchronized boolean hasNext() { -// return false; -// } -// -// @Override -// public synchronized T next() { -// throw new NoSuchElementException(); -// } -// -// @Override -// public synchronized void remove() { -// //Ignore -// } -// }; -// -// @Override -// public synchronized boolean hasNext() { -// return iterator.hasNext() || iterable.iterator().hasNext(); -// } -// -// @Override -// public synchronized T next() { -// if (!iterator.hasNext()) { -// iterator = iterable.iterator(); -// if (!iterator.hasNext()) { -// throw new NoSuchElementException(); -// } -// } -// return iterator.next(); -// } -// -// @Override -// public synchronized void remove() { -// iterator.remove(); -// } -// }; -// } + //public static org.apache.rocketmq.common.message.Message msgConvert(Message omsMessage) { + // org.apache.rocketmq.common.message.Message rmqMessage = new org.apache.rocketmq.common.message.Message(); + // if (omsMessage == null) { + // throw new OMSRuntimeException("'message' is null"); + // } else { + // if (omsMessage.getTopic() != null) { + // rmqMessage.setTopic(omsMessage.getTopic()); + // } + // if (omsMessage.getKey() != null) { + // rmqMessage.setKeys(omsMessage.getKey()); + // } + // if (omsMessage.getTag() != null) { + // rmqMessage.setTags(omsMessage.getTag()); + // } + // if (omsMessage.getStartDeliverTime() > 0L) { + // rmqMessage.putUserProperty("TIMER_DELIVER_MS", String.valueOf(omsMessage.getStartDeliverTime())); + // } + // + // if (omsMessage.getBody() != null) { + // rmqMessage.setBody(omsMessage.getBody()); + // } + // + // if (omsMessage.getShardingKey() != null && !omsMessage.getShardingKey().isEmpty()) { + // rmqMessage.putUserProperty("__SHARDINGKEY", omsMessage.getShardingKey()); + // } + // } + // Properties systemProperties = omsMessage.getSystemProperties(); + // Properties userProperties = omsMessage.getUserProperties(); + // + // //All destinations in RocketMQ use Topic + // //rmqMessage.setTopic(systemProperties.getProperty(BuiltinKeys.DESTINATION)); + // + // //if (sysHeaders.containsKey(BuiltinKeys.START_TIME)) { + // // long deliverTime = sysHeaders.getLong(BuiltinKeys.START_TIME, 0); + // // if (deliverTime > 0) { + // // rmqMessage.putUserProperty(RocketMQConstants.START_DELIVER_TIME, String.valueOf(deliverTime)); + // // } + // //} + // + // for (String key : userProperties.stringPropertyNames()) { + // MessageAccessor.putProperty(rmqMessage, key, userProperties.getProperty(key)); + // } + // + // //System headers has a high priority + // for (String key : systemProperties.stringPropertyNames()) { + // MessageAccessor.putProperty(rmqMessage, key, systemProperties.getProperty(key)); + // } + // + // return rmqMessage; + //} + // + //public static Message msgConvert(MessageExt rmqMsg) { + // Message message = new Message(); + // if (rmqMsg.getTopic() != null) { + // message.setTopic(rmqMsg.getTopic()); + // } + // + // if (rmqMsg.getKeys() != null) { + // message.setKey(rmqMsg.getKeys()); + // } + // + // if (rmqMsg.getTags() != null) { + // message.setTag(rmqMsg.getTags()); + // } + // + // if (rmqMsg.getBody() != null) { + // message.setBody(rmqMsg.getBody()); + // } + // + // if (rmqMsg.getUserProperty("TIMER_DELIVER_MS") != null) { + // long ms = Long.parseLong(rmqMsg.getUserProperty("TIMER_DELIVER_MS")); + // rmqMsg.getProperties().remove("TIMER_DELIVER_MS"); + // message.setStartDeliverTime(ms); + // } + // + // Properties systemProperties = new Properties(); + // Properties userProperties = new Properties(); + // + // + // final Set> entries = rmqMsg.getProperties().entrySet(); + // + // for (final Map.Entry entry : entries) { + // if (isOMSHeader(entry.getKey())) { + // //sysHeader + // systemProperties.put(entry.getKey(), entry.getValue()); + // } else { + // //userHeader + // userProperties.put(entry.getKey(), entry.getValue()); + // } + // } + // + // if (rmqMsg.getMsgId() != null){ + // systemProperties.put(Constants.PROPERTY_MESSAGE_MESSAGE_ID, rmqMsg.getMsgId()); + // } + // + // if (rmqMsg.getTopic() != null){ + // systemProperties.put(Constants.PROPERTY_MESSAGE_DESTINATION, rmqMsg.getTopic()); + // } + // + // //omsMsg.putSysHeaders(BuiltinKeys.SEARCH_KEYS, rmqMsg.getKeys()); + // systemProperties.put(Constants.PROPERTY_MESSAGE_BORN_HOST, String.valueOf(rmqMsg.getBornHost())); + // systemProperties.put(Constants.PROPERTY_MESSAGE_BORN_TIMESTAMP, rmqMsg.getBornTimestamp()); + // systemProperties.put(Constants.PROPERTY_MESSAGE_STORE_HOST, String.valueOf(rmqMsg.getStoreHost())); + // systemProperties.put("STORE_TIMESTAMP", rmqMsg.getStoreTimestamp()); + // + // //use in manual ack + // userProperties.put(Constants.PROPERTY_MESSAGE_QUEUE_ID, rmqMsg.getQueueId()); + // userProperties.put(Constants.PROPERTY_MESSAGE_QUEUE_OFFSET, rmqMsg.getQueueOffset()); + // + // message.setSystemProperties(systemProperties); + // message.setUserProperties(userProperties); + // + // return message; + //} + // + //public static org.apache.rocketmq.common.message.MessageExt msgConvertExt(Message omsMessage) { + // + // org.apache.rocketmq.common.message.MessageExt rmqMessageExt = new org.apache.rocketmq.common.message.MessageExt(); + // try { + // if (omsMessage.getKey() != null) { + // rmqMessageExt.setKeys(omsMessage.getKey()); + // } + // if (omsMessage.getTag() != null) { + // rmqMessageExt.setTags(omsMessage.getTag()); + // } + // if (omsMessage.getStartDeliverTime() > 0L) { + // rmqMessageExt.putUserProperty("TIMER_DELIVER_MS", String.valueOf(omsMessage.getStartDeliverTime())); + // } + // + // if (omsMessage.getBody() != null) { + // rmqMessageExt.setBody(omsMessage.getBody()); + // } + // + // if (omsMessage.getShardingKey() != null && !omsMessage.getShardingKey().isEmpty()) { + // rmqMessageExt.putUserProperty("__SHARDINGKEY", omsMessage.getShardingKey()); + // } + // + // Properties systemProperties = omsMessage.getSystemProperties(); + // Properties userProperties = omsMessage.getUserProperties(); + // + // //All destinations in RocketMQ use Topic + // rmqMessageExt.setTopic(omsMessage.getTopic()); + // + // int queueId = (int) userProperties.get(Constants.PROPERTY_MESSAGE_QUEUE_ID); + // long queueOffset = (long) userProperties.get(Constants.PROPERTY_MESSAGE_QUEUE_OFFSET); + // //use in manual ack + // rmqMessageExt.setQueueId(queueId); + // rmqMessageExt.setQueueOffset(queueOffset); + // + // for (String key : userProperties.stringPropertyNames()) { + // MessageAccessor.putProperty(rmqMessageExt, key, userProperties.getProperty(key)); + // } + // + // //System headers has a high priority + // for (String key : systemProperties.stringPropertyNames()) { + // MessageAccessor.putProperty(rmqMessageExt, key, systemProperties.getProperty(key)); + // } + // + // } catch (Exception e) { + // e.printStackTrace(); + // } + // return rmqMessageExt; + // + //} + // + //public static boolean isOMSHeader(String value) { + // for (Field field : OMSBuiltinKeys.class.getDeclaredFields()) { + // try { + // if (field.get(OMSBuiltinKeys.class).equals(value)) { + // return true; + // } + // } catch (IllegalAccessException e) { + // return false; + // } + // } + // return false; + //} + // + ///** + // * Convert a RocketMQ SEND_OK SendResult instance to a OMS SendResult. + // * + // * @param rmqResult RocketMQ result + // * @return send result + // */ + //public static SendResult sendResultConvert(org.apache.rocketmq.client.producer.SendResult rmqResult) { + // SendResult sendResult = new SendResult(); + // sendResult.setTopic(rmqResult.getMessageQueue().getTopic()); + // sendResult.setMessageId(rmqResult.getMsgId()); + // return sendResult; + //} + // + ////public static KeyValue buildKeyValue(KeyValue... keyValues) { + //// KeyValue keyValue = OMS.newKeyValue(); + //// for (KeyValue properties : keyValues) { + //// for (String key : properties.keySet()) { + //// keyValue.put(key, properties.getString(key)); + //// } + //// } + //// return keyValue; + ////} + // + ///** + // * Returns an iterator that cycles indefinitely over the elements of {@code Iterable}. + // * + // * @param Target type + // * @return Iterator + // */ + //public static Iterator cycle(final Iterable iterable) { + // return new Iterator() { + // Iterator iterator = new Iterator() { + // @Override + // public synchronized boolean hasNext() { + // return false; + // } + // + // @Override + // public synchronized T next() { + // throw new NoSuchElementException(); + // } + // + // @Override + // public synchronized void remove() { + // //Ignore + // } + // }; + // + // @Override + // public synchronized boolean hasNext() { + // return iterator.hasNext() || iterable.iterator().hasNext(); + // } + // + // @Override + // public synchronized T next() { + // if (!iterator.hasNext()) { + // iterator = iterable.iterator(); + // if (!iterator.hasNext()) { + // throw new NoSuchElementException(); + // } + // } + // return iterator.next(); + // } + // + // @Override + // public synchronized void remove() { + // iterator.remove(); + // } + // }; + //} } diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java index 16ef1fde6d..9471224f70 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/main/java/org/apache/rocketmq/client/impl/consumer/ConsumeMessageConcurrentlyService.java @@ -18,6 +18,7 @@ package org.apache.rocketmq.client.impl.consumer; import org.apache.eventmesh.connector.rocketmq.patch.EventMeshConsumeConcurrentlyContext; + import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext; import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus; @@ -37,8 +38,19 @@ import org.apache.rocketmq.logging.InternalLogger; import org.apache.rocketmq.remoting.common.RemotingHelper; -import java.util.*; -import java.util.concurrent.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Executors; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.RejectedExecutionException; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ThreadPoolExecutor; +import java.util.concurrent.TimeUnit; public class ConsumeMessageConcurrentlyService implements ConsumeMessageService { private static final InternalLogger log = ClientLogger.getLog(); @@ -101,12 +113,12 @@ public void shutdown(long awaitTerminateMillis) { } -// @Override -// public void shutdown(long awaitTerminateMillis) { -// this.scheduledExecutorService.shutdown(); -// this.consumeExecutor.shutdown(); -// this.cleanExpireMsgExecutors.shutdown(); -// } + //@Override + //public void shutdown(long awaitTerminateMillis) { + // this.scheduledExecutorService.shutdown(); + // this.consumeExecutor.shutdown(); + // this.cleanExpireMsgExecutors.shutdown(); + //} public void shutdown() { this.scheduledExecutorService.shutdown(); @@ -171,7 +183,7 @@ public ConsumeMessageDirectlyResult consumeMessageDirectly(MessageExt msg, Strin List msgs = new ArrayList(); msgs.add(msg); MessageQueue mq = new MessageQueue(); -// mq.setBrokerName(brokerName); + //mq.setBrokerName(brokerName); mq.setTopic(msg.getTopic()); mq.setQueueId(msg.getQueueId()); @@ -280,12 +292,12 @@ private void cleanExpireMsg() { public void processConsumeResult( final ConsumeConcurrentlyStatus status, final EventMeshConsumeConcurrentlyContext context, - final ConsumeRequest consumeRequest - ) { + final ConsumeRequest consumeRequest) { int ackIndex = context.getAckIndex(); - if (consumeRequest.getMsgs().isEmpty()) + if (consumeRequest.getMsgs().isEmpty()) { return; + } switch (status) { case CONSUME_SUCCESS: @@ -386,7 +398,8 @@ public void run() { private void submitConsumeRequestLater(final ConsumeRequest consumeRequest) { final int times = defaultMQPushConsumerImpl.getDefaultMQPushConsumer().getMaxReconsumeTimes(); - log.warn("rejected by thread pool, try resubmit {} times, consumerGroup:{}", times, defaultMQPushConsumerImpl.getDefaultMQPushConsumer().getConsumerGroup()); + log.warn("rejected by thread pool, try resubmit {} times, consumerGroup:{}", times, + defaultMQPushConsumerImpl.getDefaultMQPushConsumer().getConsumerGroup()); this.scheduledExecutorService.schedule(new Runnable() { @Override @@ -397,12 +410,13 @@ public void run() { try { Thread.sleep(1000); } catch (InterruptedException e) { + //ignore } ConsumeMessageConcurrentlyService.this.consumeExecutor.submit(consumeRequest); success = true; break; } catch (RejectedExecutionException e) { - + //ignore } } if (!success) { @@ -437,7 +451,8 @@ public ProcessQueue getProcessQueue() { @Override public void run() { if (this.processQueue.isDropped()) { - log.info("the message queue not be able to consume, because it's dropped. group={} {}", ConsumeMessageConcurrentlyService.this.consumerGroup, this.messageQueue); + log.info("the message queue not be able to consume, because it's dropped. group={} {}", + ConsumeMessageConcurrentlyService.this.consumerGroup, this.messageQueue); return; } diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/eventmesh/producer/DefaultProducerImplTest.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/eventmesh/producer/DefaultProducerImplTest.java index 16ff257b79..3114c54f0e 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/eventmesh/producer/DefaultProducerImplTest.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/eventmesh/producer/DefaultProducerImplTest.java @@ -18,21 +18,14 @@ package org.apache.eventmesh.producer; -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.eventmesh.api.producer.MeshMQProducer; -import org.apache.eventmesh.connector.rocketmq.producer.RocketMQProducerImpl; - import org.junit.After; import org.junit.Before; -import org.junit.Test; - -import io.openmessaging.api.exception.OMSRuntimeException; public class DefaultProducerImplTest { @Before - public void before() {} + public void before() { + } @After @@ -40,24 +33,24 @@ public void after() { //TBD:Remove topic } - @Test - public void testCreate_EmptyTopic() { - MeshMQProducer meshPub = new RocketMQProducerImpl(); - try { - meshPub.createTopic(" "); - } catch (OMSRuntimeException e) { - assertThat(e.getMessage()).isEqualToIgnoringWhitespace("RocketMQ can not create topic"); - } - } - - @Test - public void testCreate_NullTopic() { - MeshMQProducer meshPub = new RocketMQProducerImpl(); - try { - meshPub.createTopic(null); - } catch (OMSRuntimeException e) { - String errorMessage = e.getMessage(); - assertThat(errorMessage).isEqualTo("RocketMQ can not create topic null"); - } - } + //@Test + //public void testCreate_EmptyTopic() { + // MeshMQProducer meshPub = new RocketMQProducerImpl(); + // try { + // meshPub.createTopic(" "); + // } catch (OMSRuntimeException e) { + // assertThat(e.getMessage()).isEqualToIgnoringWhitespace("RocketMQ can not create topic"); + // } + //} + // + //@Test + //public void testCreate_NullTopic() { + // MeshMQProducer meshPub = new RocketMQProducerImpl(); + // try { + // meshPub.createTopic(null); + // } catch (OMSRuntimeException e) { + // String errorMessage = e.getMessage(); + // assertThat(errorMessage).isEqualTo("RocketMQ can not create topic null"); + // } + //} } \ No newline at end of file diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/consumer/PushConsumerImplTest.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/consumer/PushConsumerImplTest.java index 4f67de7573..31bcd5f8e1 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/consumer/PushConsumerImplTest.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/consumer/PushConsumerImplTest.java @@ -52,10 +52,11 @@ public class PushConsumerImplTest { @Before public void before() throws Exception { Properties consumerProp = new Properties(); -// consumerProp.setProperty(OMSBuiltinKeys.DRIVER_IMPL, -// "org.apache.eventmesh.connector.rocketmq.MessagingAccessPointImpl"); + //consumerProp.setProperty(OMSBuiltinKeys.DRIVER_IMPL, + // "org.apache.eventmesh.connector.rocketmq.MessagingAccessPointImpl"); consumerProp.setProperty("access_points", "IP1:9876,IP2:9876"); - //final MessagingAccessPoint messagingAccessPoint = OMS.builder().build(consumerProp);//.endpoint("oms:rocketmq://IP1:9876,IP2:9876/namespace").build(config); + //final MessagingAccessPoint messagingAccessPoint = OMS.builder().build(consumerProp); + // .endpoint("oms:rocketmq://IP1:9876,IP2:9876/namespace").build(config); consumerProp.setProperty("message.model", "CLUSTERING"); @@ -81,7 +82,7 @@ public void after() throws Exception { @Test public void testConsumeMessage() { - final byte[] testBody = new byte[] {'a', 'b'}; + final byte[] testBody = new byte[]{'a', 'b'}; MessageExt consumedMsg = new MessageExt(); consumedMsg.setMsgId("NewMsgId"); @@ -98,7 +99,7 @@ public void consume(CloudEvent cloudEvent, org.apache.eventmesh.api.AsyncConsume } }); ((MessageListenerConcurrently) rocketmqPushConsumer - .getMessageListener()).consumeMessage(Collections.singletonList(consumedMsg), null); + .getMessageListener()).consumeMessage(Collections.singletonList(consumedMsg), null); } diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/producer/ProducerImplTest.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/producer/ProducerImplTest.java index 27e0c69f29..d144bd2c4c 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/producer/ProducerImplTest.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/producer/ProducerImplTest.java @@ -94,12 +94,12 @@ public void testSend_OK() throws InterruptedException, RemotingException, MQClie CloudEvent cloudEvent = CloudEventBuilder.v1() - .withId("id1") - .withSource(URI.create("https://github.com/cloudevents/*****")) - .withType("producer.example") - .withSubject("HELLO_TOPIC") - .withData("hello world".getBytes()) - .build(); + .withId("id1") + .withSource(URI.create("https://github.com/cloudevents/*****")) + .withType("producer.example") + .withSubject("HELLO_TOPIC") + .withData("hello world".getBytes()) + .build(); org.apache.eventmesh.api.SendResult result = producer.send(cloudEvent); @@ -120,12 +120,12 @@ public void testSend_WithException() throws InterruptedException, RemotingExcept try { CloudEvent cloudEvent = CloudEventBuilder.v1() - .withId("id1") - .withSource(URI.create("https://github.com/cloudevents/*****")) - .withType("producer.example") - .withSubject("HELLO_TOPIC") - .withData(new byte[]{'a'}) - .build(); + .withId("id1") + .withSource(URI.create("https://github.com/cloudevents/*****")) + .withType("producer.example") + .withSubject("HELLO_TOPIC") + .withData(new byte[]{'a'}) + .build(); producer.send(cloudEvent); failBecauseExceptionWasNotThrown(ConnectorRuntimeException.class); } catch (Exception e) { diff --git a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/utils/BeanUtilsTest.java b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/utils/BeanUtilsTest.java index 7f545f3c0b..1a7f52c0e5 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/utils/BeanUtilsTest.java +++ b/eventmesh-connector-plugin/eventmesh-connector-rocketmq/src/test/java/org/apache/rocketmq/utils/BeanUtilsTest.java @@ -17,11 +17,12 @@ package org.apache.rocketmq.utils; -import java.util.Properties; - import org.apache.eventmesh.connector.rocketmq.config.ClientConfig; import org.apache.eventmesh.connector.rocketmq.domain.NonStandardKeys; import org.apache.eventmesh.connector.rocketmq.utils.BeanUtils; + +import java.util.Properties; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -30,13 +31,13 @@ public class BeanUtilsTest { private Properties properties = new Properties(); public static class CustomizedConfig extends ClientConfig { - final static String STRING_TEST = "string.test"; + static final String STRING_TEST = "string.test"; String stringTest = "foobar"; - final static String DOUBLE_TEST = "double.test"; + static final String DOUBLE_TEST = "double.test"; double doubleTest = 123.0; - final static String LONG_TEST = "long.test"; + static final String LONG_TEST = "long.test"; long longTest = 123L; String getStringTest() { diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/MessageQueue.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/MessageQueue.java index 6936a1b6d3..ddac489d4d 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/MessageQueue.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/MessageQueue.java @@ -17,12 +17,13 @@ package org.apache.eventmesh.connector.standalone.broker; -import com.google.common.base.Preconditions; import org.apache.eventmesh.connector.standalone.broker.model.MessageEntity; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.ReentrantLock; +import com.google.common.base.Preconditions; + /** * This is a block queue, can get entity by offset. * The queue is a FIFO data structure. diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/StandaloneBroker.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/StandaloneBroker.java index 822d1c09ef..2e715e35b5 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/StandaloneBroker.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/StandaloneBroker.java @@ -17,15 +17,17 @@ package org.apache.eventmesh.connector.standalone.broker; -import io.cloudevents.CloudEvent; -import org.apache.commons.lang3.tuple.Pair; import org.apache.eventmesh.connector.standalone.broker.model.MessageEntity; import org.apache.eventmesh.connector.standalone.broker.model.TopicMetadata; import org.apache.eventmesh.connector.standalone.broker.task.HistoryMessageClearTask; +import org.apache.commons.lang3.tuple.Pair; + import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import io.cloudevents.CloudEvent; + /** * This broker used to store event, it just support standalone mode, you shouldn't use this module in production environment */ diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/model/MessageEntity.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/model/MessageEntity.java index dd7468f03b..0225874b7c 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/model/MessageEntity.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/model/MessageEntity.java @@ -17,10 +17,10 @@ package org.apache.eventmesh.connector.standalone.broker.model; -import io.cloudevents.CloudEvent; - import java.io.Serializable; +import io.cloudevents.CloudEvent; + public class MessageEntity implements Serializable { private TopicMetadata topicMetadata; diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/model/TopicMetadata.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/model/TopicMetadata.java index d098e56605..9b6c673e3a 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/model/TopicMetadata.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/model/TopicMetadata.java @@ -51,8 +51,10 @@ public int hashCode() { @Override public String toString() { - return "TopicMetadata{" + - "topic='" + topicName + '\'' + + return "TopicMetadata{" + + + "topic='" + topicName + '\'' + + '}'; } } diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/task/HistoryMessageClearTask.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/task/HistoryMessageClearTask.java index a8fa87a1ad..5499f331f2 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/task/HistoryMessageClearTask.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/task/HistoryMessageClearTask.java @@ -20,12 +20,13 @@ import org.apache.eventmesh.connector.standalone.broker.MessageQueue; import org.apache.eventmesh.connector.standalone.broker.model.MessageEntity; import org.apache.eventmesh.connector.standalone.broker.model.TopicMetadata; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * This task used to clear the history message, the element in message queue can only be cleaned by this task. */ @@ -39,7 +40,7 @@ public class HistoryMessageClearTask implements Runnable { /** * If the currentTimeMills - messageCreateTimeMills >= MESSAGE_STORE_WINDOW, then the message will be clear */ - private final long MESSAGE_STORE_WINDOW = 60 * 60 * 1000; + private static final long MESSAGE_STORE_WINDOW = 60 * 60 * 1000; public HistoryMessageClearTask(ConcurrentHashMap messageContainer) { this.messageContainer = messageContainer; diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/task/SubScribeTask.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/task/SubScribeTask.java index f5058c111c..81f1e2bfc7 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/task/SubScribeTask.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/broker/task/SubScribeTask.java @@ -31,10 +31,10 @@ public class SubScribeTask implements Runnable { - private String topicName; - private StandaloneBroker standaloneBroker; - private EventListener listener; - private volatile boolean isRunning; + private String topicName; + private StandaloneBroker standaloneBroker; + private EventListener listener; + private volatile boolean isRunning; private AtomicInteger offset; @@ -75,7 +75,7 @@ public void commit(EventMeshAction action) { case CommitMessage: // update offset logger.info("message commit, topic: {}, current offset:{}", topicName, - offset.get()); + offset.get()); break; case ReconsumeLater: // don't update offset @@ -84,7 +84,7 @@ public void commit(EventMeshAction action) { // update offset offset.incrementAndGet(); logger - .info("message ack, topic: {}, current offset:{}", topicName, offset.get()); + .info("message ack, topic: {}, current offset:{}", topicName, offset.get()); break; default: @@ -97,13 +97,13 @@ public void commit(EventMeshAction action) { } catch (Exception ex) { logger.error("consumer error, topic: {}, offset: {}", topicName, offset == null ? null : offset.get(), - ex); + ex); } try { Thread.sleep(1000); } catch (InterruptedException e) { logger.error("Thread is interrupted, topic: {}, offset: {} thread name: {}", - topicName, offset == null ? null : offset.get(), Thread.currentThread().getName(), e); + topicName, offset == null ? null : offset.get(), Thread.currentThread().getName(), e); Thread.currentThread().interrupt(); } } diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/consumer/StandaloneConsumer.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/consumer/StandaloneConsumer.java index 5a1837964b..225b208309 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/consumer/StandaloneConsumer.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/consumer/StandaloneConsumer.java @@ -48,9 +48,9 @@ public StandaloneConsumer(Properties properties) { this.subscribeTaskTable = new ConcurrentHashMap<>(16); this.isStarted = new AtomicBoolean(false); this.consumeExecutorService = ThreadPoolFactory.createThreadPoolExecutor( - Runtime.getRuntime().availableProcessors() * 2, - Runtime.getRuntime().availableProcessors() * 2, - "StandaloneConsumerThread" + Runtime.getRuntime().availableProcessors() * 2, + Runtime.getRuntime().availableProcessors() * 2, + "StandaloneConsumerThread" ); } @@ -84,7 +84,7 @@ public void init(Properties keyValue) throws Exception { @Override public void updateOffset(List cloudEvents, AbstractContext context) { cloudEvents.forEach(cloudEvent -> standaloneBroker.updateOffset( - new TopicMetadata(cloudEvent.getSubject()), (Long) cloudEvent.getExtension("offset")) + new TopicMetadata(cloudEvent.getSubject()), (Long) cloudEvent.getExtension("offset")) ); } diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/consumer/StandaloneConsumerAdaptor.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/consumer/StandaloneConsumerAdaptor.java index 716b4a21d3..c09d422ffc 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/consumer/StandaloneConsumerAdaptor.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/consumer/StandaloneConsumerAdaptor.java @@ -78,95 +78,95 @@ public void unsubscribe(String topic) { consumer.unsubscribe(topic); } -// @Override -// public void init(Properties keyValue) throws Exception { -// String producerGroup = keyValue.getProperty("producerGroup"); -// -// MessagingAccessPointImpl messagingAccessPoint = new MessagingAccessPointImpl(keyValue); -// consumer = (StandaloneConsumer) messagingAccessPoint.createConsumer(keyValue); -// -// } -// -// @Override -// public void updateOffset(List msgs, AbstractContext context) { -// for(Message message : msgs) { -// consumer.updateOffset(message); -// } -// } -// -// @Override -// public void subscribe(String topic, AsyncMessageListener listener) throws Exception { -// // todo: support subExpression -// consumer.subscribe(topic, "*", listener); -// } -// -// @Override -// public void unsubscribe(String topic) { -// consumer.unsubscribe(topic); -// } -// -// @Override -// public void subscribe(String topic, String subExpression, MessageListener listener) { -// throw new UnsupportedOperationException("not supported yet"); -// } -// -// @Override -// public void subscribe(String topic, MessageSelector selector, MessageListener listener) { -// throw new UnsupportedOperationException("not supported yet"); -// } -// -// @Override -// public void subscribe(String topic, String subExpression, GenericMessageListener listener) { -// throw new UnsupportedOperationException("not supported yet"); -// } -// -// @Override -// public void subscribe(String topic, MessageSelector selector, GenericMessageListener listener) { -// throw new UnsupportedOperationException("not supported yet"); -// } -// -// @Override -// public void subscribe(String topic, String subExpression, AsyncMessageListener listener) { -// throw new UnsupportedOperationException("not supported yet"); -// } -// -// @Override -// public void subscribe(String topic, MessageSelector selector, AsyncMessageListener listener) { -// throw new UnsupportedOperationException("not supported yet"); -// } -// -// @Override -// public void subscribe(String topic, String subExpression, AsyncGenericMessageListener listener) { -// throw new UnsupportedOperationException("not supported yet"); -// } -// -// @Override -// public void subscribe(String topic, MessageSelector selector, AsyncGenericMessageListener listener) { -// throw new UnsupportedOperationException("not supported yet"); -// } -// -// @Override -// public void updateCredential(Properties credentialProperties) { -// -// } -// -// @Override -// public boolean isStarted() { -// return consumer.isStarted(); -// } -// -// @Override -// public boolean isClosed() { -// return consumer.isClosed(); -// } -// -// @Override -// public void start() { -// consumer.start(); -// } -// -// @Override -// public void shutdown() { -// consumer.shutdown(); -// } + //@Override + //public void init(Properties keyValue) throws Exception { + // String producerGroup = keyValue.getProperty("producerGroup"); + // + // MessagingAccessPointImpl messagingAccessPoint = new MessagingAccessPointImpl(keyValue); + // consumer = (StandaloneConsumer) messagingAccessPoint.createConsumer(keyValue); + // + //} + // + //@Override + //public void updateOffset(List msgs, AbstractContext context) { + // for(Message message : msgs) { + // consumer.updateOffset(message); + // } + //} + // + //@Override + //public void subscribe(String topic, AsyncMessageListener listener) throws Exception { + // // todo: support subExpression + // consumer.subscribe(topic, "*", listener); + //} + // + //@Override + //public void unsubscribe(String topic) { + // consumer.unsubscribe(topic); + //} + // + //@Override + //public void subscribe(String topic, String subExpression, MessageListener listener) { + // throw new UnsupportedOperationException("not supported yet"); + //} + // + //@Override + //public void subscribe(String topic, MessageSelector selector, MessageListener listener) { + // throw new UnsupportedOperationException("not supported yet"); + //} + // + //@Override + //public void subscribe(String topic, String subExpression, GenericMessageListener listener) { + // throw new UnsupportedOperationException("not supported yet"); + //} + // + //@Override + //public void subscribe(String topic, MessageSelector selector, GenericMessageListener listener) { + // throw new UnsupportedOperationException("not supported yet"); + //} + // + //@Override + //public void subscribe(String topic, String subExpression, AsyncMessageListener listener) { + // throw new UnsupportedOperationException("not supported yet"); + //} + // + //@Override + //public void subscribe(String topic, MessageSelector selector, AsyncMessageListener listener) { + // throw new UnsupportedOperationException("not supported yet"); + //} + // + //@Override + //public void subscribe(String topic, String subExpression, AsyncGenericMessageListener listener) { + // throw new UnsupportedOperationException("not supported yet"); + //} + // + //@Override + //public void subscribe(String topic, MessageSelector selector, AsyncGenericMessageListener listener) { + // throw new UnsupportedOperationException("not supported yet"); + //} + // + //@Override + //public void updateCredential(Properties credentialProperties) { + // + //} + // + //@Override + //public boolean isStarted() { + // return consumer.isStarted(); + //} + // + //@Override + //public boolean isClosed() { + // return consumer.isClosed(); + //} + // + //@Override + //public void start() { + // consumer.start(); + //} + // + //@Override + //public void shutdown() { + // consumer.shutdown(); + //} } diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/producer/StandaloneProducer.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/producer/StandaloneProducer.java index e6dce1a9bb..c6aaf43a32 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/producer/StandaloneProducer.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/producer/StandaloneProducer.java @@ -31,10 +31,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; - import io.cloudevents.CloudEvent; +import com.google.common.base.Preconditions; + public class StandaloneProducer { private Logger logger = LoggerFactory.getLogger(StandaloneProducer.class); @@ -79,7 +79,7 @@ public SendResult publish(CloudEvent cloudEvent) { } catch (Exception e) { logger.error("send message error, topic: {}", cloudEvent.getSubject(), e); throw new ConnectorRuntimeException( - String.format("Send message error, topic: %s", cloudEvent.getSubject())); + String.format("Send message error, topic: %s", cloudEvent.getSubject())); } } @@ -92,10 +92,10 @@ public void publish(CloudEvent cloudEvent, SendCallback sendCallback) throws Exc sendCallback.onSuccess(sendResult); } catch (Exception ex) { OnExceptionContext onExceptionContext = OnExceptionContext.builder() - .messageId(cloudEvent.getId()) - .topic(cloudEvent.getSubject()) - .exception(new ConnectorRuntimeException(ex)) - .build(); + .messageId(cloudEvent.getId()) + .topic(cloudEvent.getSubject()) + .exception(new ConnectorRuntimeException(ex)) + .build(); sendCallback.onException(onExceptionContext); } } @@ -113,10 +113,10 @@ public void sendAsync(CloudEvent cloudEvent, SendCallback sendCallback) { sendCallback.onSuccess(sendResult); } catch (Exception ex) { OnExceptionContext onExceptionContext = OnExceptionContext.builder() - .messageId(cloudEvent.getId()) - .topic(cloudEvent.getSubject()) - .exception(new ConnectorRuntimeException(ex)) - .build(); + .messageId(cloudEvent.getId()) + .topic(cloudEvent.getSubject()) + .exception(new ConnectorRuntimeException(ex)) + .build(); sendCallback.onException(onExceptionContext); } } diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/producer/StandaloneProducerAdaptor.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/producer/StandaloneProducerAdaptor.java index 8cff7e4f82..cab52f2439 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/producer/StandaloneProducerAdaptor.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/main/java/org/apache/eventmesh/connector/standalone/producer/StandaloneProducerAdaptor.java @@ -83,10 +83,10 @@ public void sendAsync(CloudEvent cloudEvent, SendCallback sendCallback) { standaloneProducer.sendAsync(cloudEvent, sendCallback); } -// @Override -// public void request(CloudEvent cloudEvent, RRCallback rrCallback, long timeout) throws Exception { -// standaloneProducer.request(cloudEvent, rrCallback, timeout); -// } + //@Override + //public void request(CloudEvent cloudEvent, RRCallback rrCallback, long timeout) throws Exception { + // standaloneProducer.request(cloudEvent, rrCallback, timeout); + //} @Override public void request(CloudEvent cloudEvent, RequestReplyCallback rrCallback, long timeout) throws Exception { diff --git a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/test/java/org/apache/eventmesh/connector/standalone/broker/StandaloneBrokerTest.java b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/test/java/org/apache/eventmesh/connector/standalone/broker/StandaloneBrokerTest.java index 92e4eb7dc9..1e66b0fffd 100644 --- a/eventmesh-connector-plugin/eventmesh-connector-standalone/src/test/java/org/apache/eventmesh/connector/standalone/broker/StandaloneBrokerTest.java +++ b/eventmesh-connector-plugin/eventmesh-connector-standalone/src/test/java/org/apache/eventmesh/connector/standalone/broker/StandaloneBrokerTest.java @@ -19,6 +19,8 @@ import org.apache.eventmesh.connector.standalone.broker.model.MessageEntity; +import java.net.URI; + import org.junit.Assert; import org.junit.Test; @@ -35,14 +37,24 @@ public void getInstance() { @Test public void putMessage() throws InterruptedException { StandaloneBroker instance = StandaloneBroker.getInstance(); - MessageEntity messageEntity = instance.putMessage("test-topic", CloudEventBuilder.v1().build()); + CloudEvent cloudEvent = CloudEventBuilder.v1() + .withId("test") + .withSource(URI.create("testsource")) + .withType("testType") + .build(); + MessageEntity messageEntity = instance.putMessage("test-topic", cloudEvent); Assert.assertNotNull(messageEntity); } @Test public void takeMessage() throws InterruptedException { StandaloneBroker instance = StandaloneBroker.getInstance(); - instance.putMessage("test-topic", CloudEventBuilder.v1().build()); + CloudEvent cloudEvent = CloudEventBuilder.v1() + .withId("test") + .withSource(URI.create("testsource")) + .withType("testType") + .build(); + instance.putMessage("test-topic", cloudEvent); CloudEvent message = instance.takeMessage("test-topic"); Assert.assertNotNull(message); } diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/cloudevents/AsyncPublishInstance.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/cloudevents/AsyncPublishInstance.java index 0f98ac2fa3..c205f5514b 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/cloudevents/AsyncPublishInstance.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/cloudevents/AsyncPublishInstance.java @@ -21,10 +21,8 @@ import org.apache.eventmesh.client.http.producer.EventMeshHttpProducer; import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.EventMeshMessage; import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.utils.JsonUtils; -import org.apache.eventmesh.common.utils.RandomStringUtils; import org.apache.eventmesh.common.utils.ThreadUtils; import org.apache.eventmesh.util.Utils; @@ -39,8 +37,8 @@ import io.cloudevents.CloudEvent; import io.cloudevents.core.builder.CloudEventBuilder; + import lombok.extern.slf4j.Slf4j; -import static org.apache.eventmesh.tcp.common.EventMeshTestCaseTopicSet.TOPIC_PRX_WQ2ClientUniCast; @Slf4j public class AsyncPublishInstance { @@ -64,16 +62,16 @@ public static void main(String[] args) throws Exception { final String topic = "TEST-TOPIC-HTTP-ASYNC"; EventMeshHttpClientConfig eventMeshClientConfig = EventMeshHttpClientConfig.builder() - .liteEventMeshAddr(eventMeshIPPort) - .producerGroup("EventMeshTest-producerGroup") - .env("env") - .idc("idc") - .ip(IPUtils.getLocalAddress()) - .sys("1234") - .pid(String.valueOf(ThreadUtils.getPID())) - .userName("eventmesh") - .password("pass") - .build(); + .liteEventMeshAddr(eventMeshIPPort) + .producerGroup("EventMeshTest-producerGroup") + .env("env") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())) + .userName("eventmesh") + .password("pass") + .build(); try (EventMeshHttpProducer eventMeshHttpProducer = new EventMeshHttpProducer(eventMeshClientConfig)) { for (int i = 0; i < messageSize; i++) { @@ -81,14 +79,14 @@ public static void main(String[] args) throws Exception { content.put("content", "testAsyncMessage"); CloudEvent event = CloudEventBuilder.v1() - .withId(UUID.randomUUID().toString()) - .withSubject(topic) - .withSource(URI.create("/")) - .withDataContentType("application/cloudevents+json") - .withType(EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME) - .withData(JsonUtils.serialize(content).getBytes(StandardCharsets.UTF_8)) - .withExtension(Constants.EVENTMESH_MESSAGE_CONST_TTL, String.valueOf(4 * 1000)) - .build(); + .withId(UUID.randomUUID().toString()) + .withSubject(topic) + .withSource(URI.create("/")) + .withDataContentType("application/cloudevents+json") + .withType(EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME) + .withData(JsonUtils.serialize(content).getBytes(StandardCharsets.UTF_8)) + .withExtension(Constants.EVENTMESH_MESSAGE_CONST_TTL, String.valueOf(4 * 1000)) + .build(); eventMeshHttpProducer.publish(event); } Thread.sleep(30000); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/AsyncPublishInstance.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/AsyncPublishInstance.java index 751cb2cf97..80a0092978 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/AsyncPublishInstance.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/AsyncPublishInstance.java @@ -17,8 +17,6 @@ package org.apache.eventmesh.http.demo.pub.eventmeshmessage; -import lombok.extern.slf4j.Slf4j; - import org.apache.eventmesh.client.http.conf.EventMeshHttpClientConfig; import org.apache.eventmesh.client.http.producer.EventMeshHttpProducer; import org.apache.eventmesh.common.Constants; @@ -35,6 +33,8 @@ import java.util.Map; import java.util.Properties; +import lombok.extern.slf4j.Slf4j; + @Slf4j public class AsyncPublishInstance { @@ -57,16 +57,16 @@ public static void main(String[] args) throws Exception { final String topic = "TEST-TOPIC-HTTP-ASYNC"; EventMeshHttpClientConfig eventMeshClientConfig = EventMeshHttpClientConfig.builder() - .liteEventMeshAddr(eventMeshIPPort) - .producerGroup("EventMeshTest-producerGroup") - .env("env") - .idc("idc") - .ip(IPUtils.getLocalAddress()) - .sys("1234") - .pid(String.valueOf(ThreadUtils.getPID())) - .userName("eventmesh") - .password("pass") - .build(); + .liteEventMeshAddr(eventMeshIPPort) + .producerGroup("EventMeshTest-producerGroup") + .env("env") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())) + .userName("eventmesh") + .password("pass") + .build(); try (EventMeshHttpProducer eventMeshHttpProducer = new EventMeshHttpProducer(eventMeshClientConfig);) { for (int i = 0; i < messageSize; i++) { @@ -74,12 +74,12 @@ public static void main(String[] args) throws Exception { content.put("content", "testPublishMessage"); EventMeshMessage eventMeshMessage = EventMeshMessage.builder() - .bizSeqNo(RandomStringUtils.generateNum(30)) - .content(JsonUtils.serialize(content)) - .topic(topic) - .uniqueId(RandomStringUtils.generateNum(30)) - .build() - .addProp(Constants.EVENTMESH_MESSAGE_CONST_TTL, String.valueOf(4 * 1000)); + .bizSeqNo(RandomStringUtils.generateNum(30)) + .content(JsonUtils.serialize(content)) + .topic(topic) + .uniqueId(RandomStringUtils.generateNum(30)) + .build() + .addProp(Constants.EVENTMESH_MESSAGE_CONST_TTL, String.valueOf(4 * 1000)); eventMeshHttpProducer.publish(eventMeshMessage); } Thread.sleep(30000); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/AsyncSyncRequestInstance.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/AsyncSyncRequestInstance.java index 428472634a..ea359d25dc 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/AsyncSyncRequestInstance.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/AsyncSyncRequestInstance.java @@ -54,28 +54,28 @@ public static void main(String[] args) throws Exception { } EventMeshHttpClientConfig eventMeshClientConfig = EventMeshHttpClientConfig.builder() - .liteEventMeshAddr(eventMeshIPPort) - .producerGroup("EventMeshTest-producerGroup") - .env("env") - .idc("idc") - .ip(IPUtils.getLocalAddress()) - .sys("1234") - .pid(String.valueOf(ThreadUtils.getPID())).build(); + .liteEventMeshAddr(eventMeshIPPort) + .producerGroup("EventMeshTest-producerGroup") + .env("env") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())).build(); eventMeshHttpProducer = new EventMeshHttpProducer(eventMeshClientConfig); final long startTime = System.currentTimeMillis(); final EventMeshMessage eventMeshMessage = EventMeshMessage.builder() - .bizSeqNo(RandomStringUtils.generateNum(30)) - .content("testAsyncMessage") - .topic(topic) - .uniqueId(RandomStringUtils.generateNum(30)).build(); + .bizSeqNo(RandomStringUtils.generateNum(30)) + .content("testAsyncMessage") + .topic(topic) + .uniqueId(RandomStringUtils.generateNum(30)).build(); eventMeshHttpProducer.request(eventMeshMessage, new RRCallback() { @Override public void onSuccess(EventMeshMessage o) { log.debug("sendmsg : {}, return : {}, cost:{}ms", eventMeshMessage.getContent(), o.getContent(), - System.currentTimeMillis() - startTime); + System.currentTimeMillis() - startTime); } @Override diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/SyncRequestInstance.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/SyncRequestInstance.java index 4d7e1d2642..e61307ccad 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/SyncRequestInstance.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/pub/eventmeshmessage/SyncRequestInstance.java @@ -52,27 +52,27 @@ public static void main(String[] args) throws Exception { } EventMeshHttpClientConfig eventMeshClientConfig = EventMeshHttpClientConfig.builder() - .liteEventMeshAddr(eventMeshIPPort) - .producerGroup("EventMeshTest-producerGroup") - .env("env") - .idc("idc") - .ip(IPUtils.getLocalAddress()) - .sys("1234") - .pid(String.valueOf(ThreadUtils.getPID())).build(); + .liteEventMeshAddr(eventMeshIPPort) + .producerGroup("EventMeshTest-producerGroup") + .env("env") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())).build(); eventMeshHttpProducer = new EventMeshHttpProducer(eventMeshClientConfig); long startTime = System.currentTimeMillis(); EventMeshMessage eventMeshMessage = EventMeshMessage.builder() - .bizSeqNo(RandomStringUtils.generateNum(30)) - .content("contentStr with special protocal") - .topic(topic) - .uniqueId(RandomStringUtils.generateNum(30)).build(); + .bizSeqNo(RandomStringUtils.generateNum(30)) + .content("contentStr with special protocal") + .topic(topic) + .uniqueId(RandomStringUtils.generateNum(30)).build(); EventMeshMessage rsp = eventMeshHttpProducer.request(eventMeshMessage, 10000); if (logger.isDebugEnabled()) { logger.debug("sendmsg : {}, return : {}, cost:{}ms", eventMeshMessage.getContent(), rsp.getContent(), - System.currentTimeMillis() - startTime); + System.currentTimeMillis() - startTime); } } catch (Exception e) { logger.warn("send msg failed", e); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/controller/SubController.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/controller/SubController.java index c82864b4be..58b5b632da 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/controller/SubController.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/http/demo/sub/controller/SubController.java @@ -17,11 +17,6 @@ package org.apache.eventmesh.http.demo.sub.controller; -import io.cloudevents.CloudEvent; -import io.cloudevents.core.provider.EventFormatProvider; -import io.cloudevents.jackson.JsonFormat; -import lombok.extern.slf4j.Slf4j; - import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.utils.JsonUtils; @@ -40,6 +35,12 @@ import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; +import io.cloudevents.CloudEvent; +import io.cloudevents.core.provider.EventFormatProvider; +import io.cloudevents.jackson.JsonFormat; + +import lombok.extern.slf4j.Slf4j; + @Slf4j @RestController @@ -55,8 +56,9 @@ public String subTest(HttpServletRequest request) { log.info("=======receive message======= {}", content); Map contentMap = JsonUtils.deserialize(content, HashMap.class); if (StringUtils.equals(EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME, contentMap.get(ProtocolKey.PROTOCOL_TYPE))) { - CloudEvent event = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE) - .deserialize(content.getBytes(StandardCharsets.UTF_8)); + CloudEvent event = EventFormatProvider.getInstance() + .resolveFormat(JsonFormat.CONTENT_TYPE) + .deserialize(content.getBytes(StandardCharsets.UTF_8)); String data = new String(event.getData().toBytes(), StandardCharsets.UTF_8); log.info("=======receive data======= {}", data); } 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 0c0f2c1928..816ed25893 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 @@ -52,17 +52,17 @@ public class SubService implements InitializingBean { final Properties properties = Utils.readPropertiesFile("application.properties"); - final List topicList = Lists.newArrayList( - new SubscriptionItem("TEST-TOPIC-HTTP-ASYNC", SubscriptionMode.CLUSTERING, SubscriptionType.ASYNC) + final List topicList = Lists.newArrayList( + new SubscriptionItem("TEST-TOPIC-HTTP-ASYNC", SubscriptionMode.CLUSTERING, SubscriptionType.ASYNC) ); - final String localIp = IPUtils.getLocalAddress(); - final String localPort = properties.getProperty("server.port"); - final String eventMeshIp = properties.getProperty("eventmesh.ip"); - final String eventMeshHttpPort = properties.getProperty("eventmesh.http.port"); - final String url = "http://" + localIp + ":" + localPort + "/sub/test"; - final String env = "P"; - final String idc = "FT"; - final String subsys = "1234"; + final String localIp = IPUtils.getLocalAddress(); + final String localPort = properties.getProperty("server.port"); + final String eventMeshIp = properties.getProperty("eventmesh.ip"); + final String eventMeshHttpPort = properties.getProperty("eventmesh.http.port"); + final String url = "http://" + localIp + ":" + localPort + "/sub/test"; + final String env = "P"; + final String idc = "FT"; + final String subsys = "1234"; // CountDownLatch size is the same as messageSize in AsyncPublishInstance.java (Publisher) private CountDownLatch countDownLatch = new CountDownLatch(AsyncPublishInstance.messageSize); @@ -72,13 +72,13 @@ public void afterPropertiesSet() throws Exception { final String eventMeshIPPort = eventMeshIp + ":" + eventMeshHttpPort; EventMeshHttpClientConfig eventMeshClientConfig = EventMeshHttpClientConfig.builder() - .liteEventMeshAddr(eventMeshIPPort) - .consumerGroup("EventMeshTest-consumerGroup") - .env(env) - .idc(idc) - .ip(IPUtils.getLocalAddress()) - .sys(subsys) - .pid(String.valueOf(ThreadUtils.getPID())).build(); + .liteEventMeshAddr(eventMeshIPPort) + .consumerGroup("EventMeshTest-consumerGroup") + .env(env) + .idc(idc) + .ip(IPUtils.getLocalAddress()) + .sys(subsys) + .pid(String.valueOf(ThreadUtils.getPID())).build(); eventMeshHttpConsumer = new EventMeshHttpConsumer(eventMeshClientConfig); eventMeshHttpConsumer.heartBeat(topicList, url); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java index dad5e65d24..78a2f1031f 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/common/EventMeshTestUtils.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.tcp.common; -import io.cloudevents.CloudEvent; -import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.core.v1.CloudEventV1; import static org.apache.eventmesh.common.protocol.tcp.Command.RESPONSE_TO_SERVER; import static org.apache.eventmesh.tcp.common.EventMeshTestCaseTopicSet.TOPIC_PRX_SyncSubscribeTest; import static org.apache.eventmesh.tcp.common.EventMeshTestCaseTopicSet.TOPIC_PRX_WQ2ClientBroadCast; @@ -41,44 +38,47 @@ import java.util.UUID; import java.util.concurrent.ThreadLocalRandom; +import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; + public class EventMeshTestUtils { private static final int seqLength = 10; // generate pub-client public static UserAgent generateClient1() { UserAgent agent = UserAgent.builder() - .env("test") - .host("127.0.0.1") - .password(generateRandomString(8)) - .username("PU4283") - .producerGroup("EventmeshTest-ProducerGroup") - .consumerGroup("EventmeshTest-ConsumerGroup") - .path("/data/app/umg_proxy") - .port(8362) - .subsystem("5023") - .pid(32893) - .version("2.0.11") - .idc("FT") - .build(); + .env("test") + .host("127.0.0.1") + .password(generateRandomString(8)) + .username("PU4283") + .producerGroup("EventmeshTest-ProducerGroup") + .consumerGroup("EventmeshTest-ConsumerGroup") + .path("/data/app/umg_proxy") + .port(8362) + .subsystem("5023") + .pid(32893) + .version("2.0.11") + .idc("FT") + .build(); return MessageUtils.generatePubClient(agent); } // generate sub-client public static UserAgent generateClient2() { UserAgent agent = UserAgent.builder() - .env("test") - .host("127.0.0.1") - .password(generateRandomString(8)) - .username("PU4283") - .producerGroup("EventmeshTest-ProducerGroup") - .consumerGroup("EventmeshTest-ConsumerGroup") - .path("/data/app/umg_proxy") - .port(9362) - .subsystem("5017") - .pid(42893) - .version("2.0.11") - .idc("FT") - .build(); + .env("test") + .host("127.0.0.1") + .password(generateRandomString(8)) + .username("PU4283") + .producerGroup("EventmeshTest-ProducerGroup") + .consumerGroup("EventmeshTest-ConsumerGroup") + .path("/data/app/umg_proxy") + .port(9362) + .subsystem("5017") + .pid(42893) + .version("2.0.11") + .idc("FT") + .build(); return MessageUtils.generateSubClient(agent); } @@ -171,14 +171,14 @@ public static CloudEvent generateCloudEventV1Async() { content.put("content", "testAsyncMessage"); CloudEvent event = CloudEventBuilder.v1() - .withId(UUID.randomUUID().toString()) - .withSubject(TOPIC_PRX_WQ2ClientUniCast) - .withSource(URI.create("/")) - .withDataContentType("application/cloudevents+json") - .withType(EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME) - .withData(JsonUtils.serialize(content).getBytes(StandardCharsets.UTF_8)) - .withExtension("ttl", "30000") - .build(); + .withId(UUID.randomUUID().toString()) + .withSubject(TOPIC_PRX_WQ2ClientUniCast) + .withSource(URI.create("/")) + .withDataContentType("application/cloudevents+json") + .withType(EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME) + .withData(JsonUtils.serialize(content).getBytes(StandardCharsets.UTF_8)) + .withExtension("ttl", "30000") + .build(); return event; } @@ -187,16 +187,16 @@ public static CloudEvent generateCloudEventV1SyncRR() { content.put("content", "testSyncRR"); CloudEvent event = CloudEventBuilder.v1() - .withId(UUID.randomUUID().toString()) - .withSubject(TOPIC_PRX_SyncSubscribeTest) - .withSource(URI.create("/")) - .withDataContentType("application/cloudevents+json") - .withType(EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME) - .withData(JsonUtils.serialize(content).getBytes(StandardCharsets.UTF_8)) - .withExtension("ttl", "30000") - .withExtension("msgtype", "persistent") - .withExtension("keys", generateRandomString(16)) - .build(); + .withId(UUID.randomUUID().toString()) + .withSubject(TOPIC_PRX_SyncSubscribeTest) + .withSource(URI.create("/")) + .withDataContentType("application/cloudevents+json") + .withType(EventMeshCommon.CLOUD_EVENTS_PROTOCOL_NAME) + .withData(JsonUtils.serialize(content).getBytes(StandardCharsets.UTF_8)) + .withExtension("ttl", "30000") + .withExtension("msgtype", "persistent") + .withExtension("keys", generateRandomString(16)) + .build(); return event; } } diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/AsyncPublish.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/AsyncPublish.java index f7321d4b76..7b1fc3b3ba 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/AsyncPublish.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/AsyncPublish.java @@ -17,12 +17,10 @@ package org.apache.eventmesh.tcp.demo.pub.cloudevents; -import io.cloudevents.CloudEvent; - import org.apache.eventmesh.client.tcp.EventMeshTCPClient; +import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; -import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.tcp.common.EventMeshTestUtils; import org.apache.eventmesh.util.Utils; @@ -32,6 +30,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; + public class AsyncPublish { public static Logger logger = LoggerFactory.getLogger(AsyncPublish.class); @@ -47,12 +47,12 @@ public static void main(String[] agrs) throws Exception { try { UserAgent userAgent = EventMeshTestUtils.generateClient1(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host(eventMeshIp) - .port(eventMeshTcpPort) - .userAgent(userAgent) - .build(); + .host(eventMeshIp) + .port(eventMeshTcpPort) + .userAgent(userAgent) + .build(); client = - EventMeshTCPClientFactory.createEventMeshTCPClient(eventMeshTcpClientConfig, CloudEvent.class); + EventMeshTCPClientFactory.createEventMeshTCPClient(eventMeshTcpClientConfig, CloudEvent.class); client.init(); for (int i = 0; i < 5; i++) { diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/SyncRequest.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/SyncRequest.java index c04d2a7a6a..5d5b666383 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/SyncRequest.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/cloudevents/SyncRequest.java @@ -21,19 +21,19 @@ import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; -import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.tcp.common.EventMeshTestUtils; import org.apache.eventmesh.util.Utils; +import java.nio.charset.StandardCharsets; +import java.util.Properties; + import io.cloudevents.CloudEvent; import io.cloudevents.core.provider.EventFormatProvider; import io.cloudevents.jackson.JsonFormat; -import lombok.extern.slf4j.Slf4j; -import java.nio.charset.StandardCharsets; -import java.util.Properties; +import lombok.extern.slf4j.Slf4j; @Slf4j public class SyncRequest { @@ -46,20 +46,20 @@ public static void main(String[] agrs) throws Exception { final int eventMeshTcpPort = Integer.parseInt(properties.getProperty("eventmesh.tcp.port")); UserAgent userAgent = EventMeshTestUtils.generateClient1(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host(eventMeshIp) - .port(eventMeshTcpPort) - .userAgent(userAgent) - .build(); + .host(eventMeshIp) + .port(eventMeshTcpPort) + .userAgent(userAgent) + .build(); try { client = EventMeshTCPClientFactory.createEventMeshTCPClient( - eventMeshTcpClientConfig, CloudEvent.class); + eventMeshTcpClientConfig, CloudEvent.class); client.init(); CloudEvent event = EventMeshTestUtils.generateCloudEventV1SyncRR(); log.info("begin send rr msg=================={}", event); Package response = client.rr(event, EventMeshCommon.DEFAULT_TIME_OUT_MILLS); CloudEvent replyEvent = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE) - .deserialize(response.getBody().toString().getBytes(StandardCharsets.UTF_8)); + .deserialize(response.getBody().toString().getBytes(StandardCharsets.UTF_8)); String content = new String(replyEvent.getData().toBytes(), StandardCharsets.UTF_8); log.info("receive rr reply==================={}|{}", response, content); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublish.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublish.java index a1687ce62e..876164b6f5 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublish.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublish.java @@ -18,9 +18,9 @@ package org.apache.eventmesh.tcp.demo.pub.eventmeshmessage; import org.apache.eventmesh.client.tcp.EventMeshTCPClient; +import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; -import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.tcp.common.EventMeshTestUtils; @@ -46,12 +46,12 @@ public static void main(String[] agrs) throws Exception { try { UserAgent userAgent = EventMeshTestUtils.generateClient1(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host(eventMeshIp) - .port(eventMeshTcpPort) - .userAgent(userAgent) - .build(); + .host(eventMeshIp) + .port(eventMeshTcpPort) + .userAgent(userAgent) + .build(); client = - EventMeshTCPClientFactory.createEventMeshTCPClient(eventMeshTcpClientConfig, EventMeshMessage.class); + EventMeshTCPClientFactory.createEventMeshTCPClient(eventMeshTcpClientConfig, EventMeshMessage.class); client.init(); for (int i = 0; i < 5; i++) { diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublishBroadcast.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublishBroadcast.java index e2d2634172..bc94f31e9e 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublishBroadcast.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/AsyncPublishBroadcast.java @@ -18,9 +18,9 @@ package org.apache.eventmesh.tcp.demo.pub.eventmeshmessage; import org.apache.eventmesh.client.tcp.EventMeshTCPClient; +import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; -import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.tcp.common.EventMeshTestUtils; @@ -41,12 +41,12 @@ public static void main(String[] agrs) throws Exception { final int eventMeshTcpPort = Integer.parseInt(properties.getProperty("eventmesh.tcp.port")); UserAgent userAgent = EventMeshTestUtils.generateClient1(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host(eventMeshIp) - .port(eventMeshTcpPort) - .userAgent(userAgent) - .build(); + .host(eventMeshIp) + .port(eventMeshTcpPort) + .userAgent(userAgent) + .build(); try (final EventMeshTCPClient client = - EventMeshTCPClientFactory.createEventMeshTCPClient(eventMeshTcpClientConfig, EventMeshMessage.class)) { + EventMeshTCPClientFactory.createEventMeshTCPClient(eventMeshTcpClientConfig, EventMeshMessage.class)) { client.init(); EventMeshMessage eventMeshMessage = EventMeshTestUtils.generateBroadcastMqMsg(); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/SyncRequest.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/SyncRequest.java index f0ded1fd93..0b4ade9a5b 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/SyncRequest.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/pub/eventmeshmessage/SyncRequest.java @@ -18,9 +18,9 @@ package org.apache.eventmesh.tcp.demo.pub.eventmeshmessage; import org.apache.eventmesh.client.tcp.EventMeshTCPClient; +import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.client.tcp.common.EventMeshCommon; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; -import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.common.protocol.tcp.UserAgent; @@ -36,13 +36,13 @@ public class SyncRequest { public static void main(String[] agrs) throws Exception { UserAgent userAgent = EventMeshTestUtils.generateClient1(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host("127.0.0.1") - .port(10002) - .userAgent(userAgent) - .build(); + .host("127.0.0.1") + .port(10002) + .userAgent(userAgent) + .build(); try { client = EventMeshTCPClientFactory.createEventMeshTCPClient( - eventMeshTcpClientConfig, EventMeshMessage.class); + eventMeshTcpClientConfig, EventMeshMessage.class); client.init(); EventMeshMessage eventMeshMessage = EventMeshTestUtils.generateSyncRRMqMsg(); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/cloudevents/AsyncSubscribe.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/cloudevents/AsyncSubscribe.java index 91f4eda6c8..91719d757d 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/cloudevents/AsyncSubscribe.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/cloudevents/AsyncSubscribe.java @@ -18,9 +18,9 @@ package org.apache.eventmesh.tcp.demo.sub.cloudevents; import org.apache.eventmesh.client.tcp.EventMeshTCPClient; +import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; -import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.UserAgent; @@ -33,7 +33,7 @@ import java.util.Properties; import io.cloudevents.CloudEvent; -import io.netty.channel.ChannelHandlerContext; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -49,10 +49,10 @@ public static void main(String[] agrs) throws Exception { final int eventMeshTcpPort = Integer.parseInt(properties.getProperty("eventmesh.tcp.port")); UserAgent userAgent = EventMeshTestUtils.generateClient2(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host(eventMeshIp) - .port(eventMeshTcpPort) - .userAgent(userAgent) - .build(); + .host(eventMeshIp) + .port(eventMeshTcpPort) + .userAgent(userAgent) + .build(); try { client = EventMeshTCPClientFactory.createEventMeshTCPClient(eventMeshTcpClientConfig, CloudEvent.class); client.init(); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/cloudevents/SyncResponse.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/cloudevents/SyncResponse.java index d1753233f2..76292e1b5f 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/cloudevents/SyncResponse.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/cloudevents/SyncResponse.java @@ -19,26 +19,22 @@ import org.apache.eventmesh.client.tcp.EventMeshTCPClient; import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; -import org.apache.eventmesh.client.tcp.common.MessageUtils; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; -import org.apache.eventmesh.common.protocol.tcp.Command; -import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; -import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.tcp.common.EventMeshTestUtils; import org.apache.eventmesh.util.Utils; -import io.cloudevents.CloudEvent; -import io.netty.channel.ChannelHandlerContext; -import lombok.extern.slf4j.Slf4j; - import java.nio.charset.StandardCharsets; import java.util.Optional; import java.util.Properties; +import io.cloudevents.CloudEvent; + +import lombok.extern.slf4j.Slf4j; + @Slf4j public class SyncResponse implements ReceiveMsgHook { @@ -52,13 +48,13 @@ public static void main(String[] agrs) throws Exception { final int eventMeshTcpPort = Integer.parseInt(properties.getProperty("eventmesh.tcp.port")); UserAgent userAgent = EventMeshTestUtils.generateClient2(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host(eventMeshIp) - .port(eventMeshTcpPort) - .userAgent(userAgent) - .build(); + .host(eventMeshIp) + .port(eventMeshTcpPort) + .userAgent(userAgent) + .build(); try { client = EventMeshTCPClientFactory - .createEventMeshTCPClient(eventMeshTcpClientConfig, CloudEvent.class); + .createEventMeshTCPClient(eventMeshTcpClientConfig, CloudEvent.class); client.init(); client.subscribe("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/AsyncSubscribe.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/AsyncSubscribe.java index bb99cfc7f5..780316340b 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/AsyncSubscribe.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/AsyncSubscribe.java @@ -18,9 +18,9 @@ package org.apache.eventmesh.tcp.demo.sub.eventmeshmessage; import org.apache.eventmesh.client.tcp.EventMeshTCPClient; +import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; -import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; @@ -32,7 +32,6 @@ import java.util.Optional; import java.util.Properties; -import io.netty.channel.ChannelHandlerContext; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -48,17 +47,17 @@ public static void main(String[] agrs) throws Exception { final int eventMeshTcpPort = Integer.parseInt(properties.getProperty("eventmesh.tcp.port")); UserAgent userAgent = EventMeshTestUtils.generateClient2(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host(eventMeshIp) - .port(eventMeshTcpPort) - .userAgent(userAgent) - .build(); + .host(eventMeshIp) + .port(eventMeshTcpPort) + .userAgent(userAgent) + .build(); try { client = - EventMeshTCPClientFactory.createEventMeshTCPClient(eventMeshTcpClientConfig, EventMeshMessage.class); + EventMeshTCPClientFactory.createEventMeshTCPClient(eventMeshTcpClientConfig, EventMeshMessage.class); client.init(); client.subscribe(EventMeshTestCaseTopicSet.TOPIC_PRX_WQ2ClientUniCast, SubscriptionMode.CLUSTERING, - SubscriptionType.ASYNC); + SubscriptionType.ASYNC); client.registerSubBusiHandler(handler); client.listen(); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/AsyncSubscribeBroadcast.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/AsyncSubscribeBroadcast.java index dfc58a5a62..93d09539fa 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/AsyncSubscribeBroadcast.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/AsyncSubscribeBroadcast.java @@ -18,9 +18,9 @@ package org.apache.eventmesh.tcp.demo.sub.eventmeshmessage; import org.apache.eventmesh.client.tcp.EventMeshTCPClient; +import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; -import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; @@ -31,7 +31,6 @@ import java.util.Optional; import java.util.Properties; -import io.netty.channel.ChannelHandlerContext; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -45,12 +44,12 @@ public static void main(String[] agrs) throws Exception { final int eventMeshTcpPort = Integer.parseInt(properties.getProperty("eventmesh.tcp.port")); UserAgent userAgent = EventMeshTestUtils.generateClient2(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host(eventMeshIp) - .port(eventMeshTcpPort) - .userAgent(userAgent) - .build(); + .host(eventMeshIp) + .port(eventMeshTcpPort) + .userAgent(userAgent) + .build(); try (EventMeshTCPClient client = EventMeshTCPClientFactory.createEventMeshTCPClient( - eventMeshTcpClientConfig, EventMeshMessage.class)) { + eventMeshTcpClientConfig, EventMeshMessage.class)) { client.init(); client.subscribe("TEST-TOPIC-TCP-BROADCAST", SubscriptionMode.BROADCASTING, SubscriptionType.ASYNC); diff --git a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/SyncResponse.java b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/SyncResponse.java index e9606fa6ce..9c7d37dd32 100644 --- a/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/SyncResponse.java +++ b/eventmesh-examples/src/main/java/org/apache/eventmesh/tcp/demo/sub/eventmeshmessage/SyncResponse.java @@ -18,24 +18,19 @@ package org.apache.eventmesh.tcp.demo.sub.eventmeshmessage; import org.apache.eventmesh.client.tcp.EventMeshTCPClient; -import org.apache.eventmesh.client.tcp.common.MessageUtils; +import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.client.tcp.common.ReceiveMsgHook; import org.apache.eventmesh.client.tcp.conf.EventMeshTCPClientConfig; -import org.apache.eventmesh.client.tcp.EventMeshTCPClientFactory; import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; -import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; -import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.tcp.common.EventMeshTestUtils; -import io.netty.channel.ChannelHandlerContext; -import lombok.extern.slf4j.Slf4j; -import static org.apache.eventmesh.common.protocol.tcp.Command.RESPONSE_TO_SERVER; - import java.util.Optional; +import lombok.extern.slf4j.Slf4j; + @Slf4j public class SyncResponse implements ReceiveMsgHook { @@ -46,13 +41,13 @@ public class SyncResponse implements ReceiveMsgHook { public static void main(String[] agrs) throws Exception { UserAgent userAgent = EventMeshTestUtils.generateClient2(); EventMeshTCPClientConfig eventMeshTcpClientConfig = EventMeshTCPClientConfig.builder() - .host("127.0.0.1") - .port(10002) - .userAgent(userAgent) - .build(); + .host("127.0.0.1") + .port(10002) + .userAgent(userAgent) + .build(); try { client = EventMeshTCPClientFactory - .createEventMeshTCPClient(eventMeshTcpClientConfig, EventMeshMessage.class); + .createEventMeshTCPClient(eventMeshTcpClientConfig, EventMeshMessage.class); client.init(); client.subscribe("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC); 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 63a93ba759..b872c3af8d 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 @@ -70,7 +70,7 @@ private static String getLinuxLocalIp() throws SocketException { if (!inetAddress.isLoopbackAddress()) { String ipaddress = inetAddress.getHostAddress().toString(); if (!ipaddress.contains("::") && !ipaddress.contains("0:0:") - && !ipaddress.contains("fe80")) { + && !ipaddress.contains("fe80")) { ip = ipaddress; } } diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolAdaptor.java b/eventmesh-protocol-plugin/eventmesh-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolAdaptor.java index 43ba72401b..b6d5c83a47 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolAdaptor.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolAdaptor.java @@ -22,10 +22,10 @@ import org.apache.eventmesh.spi.EventMeshExtensionType; import org.apache.eventmesh.spi.EventMeshSPI; -import io.cloudevents.CloudEvent; - import java.util.List; +import io.cloudevents.CloudEvent; + /** * Protocol transformer SPI interface, all protocol plugin should implementation. * diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolPluginFactory.java b/eventmesh-protocol-plugin/eventmesh-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolPluginFactory.java index 2d6f7bd559..1d2cd40426 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolPluginFactory.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-api/src/main/java/org/apache/eventmesh/protocol/api/ProtocolPluginFactory.java @@ -34,7 +34,7 @@ public class ProtocolPluginFactory { private static final Map> PROTOCOL_ADAPTOR_MAP = - new ConcurrentHashMap<>(16); + new ConcurrentHashMap<>(16); /** * Get protocol adaptor by name. @@ -46,12 +46,12 @@ public class ProtocolPluginFactory { @SuppressWarnings("unchecked") public static ProtocolAdaptor getProtocolAdaptor(String protocolType) { ProtocolAdaptor protocolAdaptor = PROTOCOL_ADAPTOR_MAP.computeIfAbsent( - protocolType, - (type) -> EventMeshExtensionFactory.getExtension(ProtocolAdaptor.class, type) + protocolType, + (type) -> EventMeshExtensionFactory.getExtension(ProtocolAdaptor.class, type) ); if (protocolAdaptor == null) { throw new IllegalArgumentException( - String.format("Cannot find the Protocol adaptor: %s", protocolType) + String.format("Cannot find the Protocol adaptor: %s", protocolType) ); } return protocolAdaptor; 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 10939ee679..c54a88e7fa 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 @@ -38,20 +38,20 @@ import java.util.List; import java.util.Map; -import com.google.common.base.Preconditions; - import io.cloudevents.CloudEvent; import io.cloudevents.core.format.EventFormat; import io.cloudevents.core.provider.EventFormatProvider; import io.cloudevents.jackson.JsonFormat; +import com.google.common.base.Preconditions; + /** * CloudEvents protocol adaptor, used to transform CloudEvents message to CloudEvents message. * * @since 1.3.0 */ public class CloudEventsProtocolAdaptor - implements ProtocolAdaptor { + implements ProtocolAdaptor { @Override public CloudEvent toCloudEvent(ProtocolTransportObject cloudEvent) throws ProtocolHandleException { @@ -98,7 +98,7 @@ private CloudEvent deserializeHttpProtocol(String requestCode, @Override public List toBatchCloudEvent(ProtocolTransportObject protocol) - throws ProtocolHandleException { + throws ProtocolHandleException { return null; } @@ -113,7 +113,7 @@ public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws Prot @Override public Map toMap() { byte[] eventByte = - EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE).serialize(cloudEvent); + EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE).serialize(cloudEvent); map.put("content", new String(eventByte, StandardCharsets.UTF_8)); return map; } @@ -127,7 +127,7 @@ public Map toMap() { Preconditions.checkNotNull(dataContentType, "DateContentType cannot be null"); EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(dataContentType); Preconditions.checkNotNull(eventFormat, - String.format("DateContentType:%s is not supported", dataContentType)); + String.format("DateContentType:%s is not supported", dataContentType)); pkg.setBody(eventFormat.serialize(cloudEvent)); return pkg; } else { diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageBatchProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageBatchProtocolResolver.java index 2b4f180038..d27fdcdb1c 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageBatchProtocolResolver.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageBatchProtocolResolver.java @@ -17,10 +17,11 @@ package org.apache.eventmesh.protocol.cloudevents.resolver.http; -import io.cloudevents.CloudEvent; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.header.Header; +import io.cloudevents.CloudEvent; + public class SendMessageBatchProtocolResolver { public static CloudEvent buildEvent(Header header, Body body) { return null; diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageBatchV2ProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageBatchV2ProtocolResolver.java index a90484b060..095095f3fe 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageBatchV2ProtocolResolver.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageBatchV2ProtocolResolver.java @@ -17,28 +17,24 @@ package org.apache.eventmesh.protocol.cloudevents.resolver.http; -import io.cloudevents.CloudEvent; -import io.cloudevents.SpecVersion; -import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.core.provider.EventFormatProvider; -import io.cloudevents.core.v03.CloudEventV03; -import io.cloudevents.core.v1.CloudEventV1; -import io.cloudevents.jackson.JsonFormat; - -import org.apache.commons.lang3.StringUtils; - import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageBatchV2RequestBody; -import org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageBatchV2RequestHeader; -import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException; +import org.apache.commons.lang3.StringUtils; + import java.nio.charset.StandardCharsets; +import io.cloudevents.CloudEvent; +import io.cloudevents.SpecVersion; +import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.core.provider.EventFormatProvider; +import io.cloudevents.jackson.JsonFormat; + public class SendMessageBatchV2ProtocolResolver { public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHandleException { try { @@ -66,42 +62,42 @@ public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHan CloudEvent event = null; if (StringUtils.equals(SpecVersion.V1.toString(), protocolVersion)) { event = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE) - .deserialize(content.getBytes(StandardCharsets.UTF_8)); + .deserialize(content.getBytes(StandardCharsets.UTF_8)); event = CloudEventBuilder.from(event) - .withExtension(ProtocolKey.REQUEST_CODE, code) - .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) - .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc) - .withExtension(ProtocolKey.ClientInstanceKey.IP, ip) - .withExtension(ProtocolKey.ClientInstanceKey.PID, pid) - .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys) - .withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username) - .withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd) - .withExtension(ProtocolKey.VERSION, version.getVersion()) - .withExtension(ProtocolKey.LANGUAGE, language) - .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType) - .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc) - .withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion) - .withExtension(SendMessageBatchV2RequestBody.PRODUCERGROUP, producerGroup) - .build(); + .withExtension(ProtocolKey.REQUEST_CODE, code) + .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) + .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc) + .withExtension(ProtocolKey.ClientInstanceKey.IP, ip) + .withExtension(ProtocolKey.ClientInstanceKey.PID, pid) + .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys) + .withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username) + .withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd) + .withExtension(ProtocolKey.VERSION, version.getVersion()) + .withExtension(ProtocolKey.LANGUAGE, language) + .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType) + .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc) + .withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion) + .withExtension(SendMessageBatchV2RequestBody.PRODUCERGROUP, producerGroup) + .build(); } else if (StringUtils.equals(SpecVersion.V03.toString(), protocolVersion)) { event = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE) - .deserialize(content.getBytes(StandardCharsets.UTF_8)); + .deserialize(content.getBytes(StandardCharsets.UTF_8)); event = CloudEventBuilder.from(event) - .withExtension(ProtocolKey.REQUEST_CODE, code) - .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) - .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc) - .withExtension(ProtocolKey.ClientInstanceKey.IP, ip) - .withExtension(ProtocolKey.ClientInstanceKey.PID, pid) - .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys) - .withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username) - .withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd) - .withExtension(ProtocolKey.VERSION, version.getVersion()) - .withExtension(ProtocolKey.LANGUAGE, language) - .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType) - .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc) - .withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion) - .withExtension(SendMessageBatchV2RequestBody.PRODUCERGROUP, producerGroup) - .build(); + .withExtension(ProtocolKey.REQUEST_CODE, code) + .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) + .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc) + .withExtension(ProtocolKey.ClientInstanceKey.IP, ip) + .withExtension(ProtocolKey.ClientInstanceKey.PID, pid) + .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys) + .withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username) + .withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd) + .withExtension(ProtocolKey.VERSION, version.getVersion()) + .withExtension(ProtocolKey.LANGUAGE, language) + .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType) + .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc) + .withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion) + .withExtension(SendMessageBatchV2RequestBody.PRODUCERGROUP, producerGroup) + .build(); } return event; } catch (Exception e) { diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageRequestProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageRequestProtocolResolver.java index f8e0791e6d..8bfde60d32 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageRequestProtocolResolver.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/http/SendMessageRequestProtocolResolver.java @@ -17,26 +17,24 @@ package org.apache.eventmesh.protocol.cloudevents.resolver.http; -import io.cloudevents.CloudEvent; -import io.cloudevents.SpecVersion; -import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.core.provider.EventFormatProvider; -import io.cloudevents.core.v03.CloudEventV03; -import io.cloudevents.core.v1.CloudEventV1; -import io.cloudevents.jackson.JsonFormat; - -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.header.Header; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader; -import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException; +import org.apache.commons.lang3.StringUtils; + import java.nio.charset.StandardCharsets; +import io.cloudevents.CloudEvent; +import io.cloudevents.SpecVersion; +import io.cloudevents.core.builder.CloudEventBuilder; +import io.cloudevents.core.provider.EventFormatProvider; +import io.cloudevents.jackson.JsonFormat; + public class SendMessageRequestProtocolResolver { public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHandleException { @@ -65,7 +63,7 @@ public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHan CloudEvent event = null; if (StringUtils.equals(SpecVersion.V1.toString(), protocolVersion)) { event = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE) - .deserialize(content.getBytes(StandardCharsets.UTF_8)); + .deserialize(content.getBytes(StandardCharsets.UTF_8)); event = CloudEventBuilder.v1(event) .withExtension(ProtocolKey.REQUEST_CODE, code) .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) @@ -84,7 +82,7 @@ public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHan .build(); } else if (StringUtils.equals(SpecVersion.V03.toString(), protocolVersion)) { event = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE) - .deserialize(content.getBytes(StandardCharsets.UTF_8)); + .deserialize(content.getBytes(StandardCharsets.UTF_8)); event = CloudEventBuilder.v03(event) .withExtension(ProtocolKey.REQUEST_CODE, code) .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/tcp/TcpMessageProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/tcp/TcpMessageProtocolResolver.java index 8903786296..82b338882d 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/tcp/TcpMessageProtocolResolver.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/main/java/org/apache/eventmesh/protocol/cloudevents/resolver/tcp/TcpMessageProtocolResolver.java @@ -26,8 +26,6 @@ import java.nio.charset.StandardCharsets; -import com.google.common.base.Preconditions; - import io.cloudevents.CloudEvent; import io.cloudevents.SpecVersion; import io.cloudevents.core.builder.CloudEventBuilder; @@ -35,10 +33,12 @@ import io.cloudevents.core.provider.EventFormatProvider; import io.cloudevents.jackson.JsonFormat; +import com.google.common.base.Preconditions; + public class TcpMessageProtocolResolver { public static CloudEvent buildEvent(Header header, String cloudEventJson) - throws ProtocolHandleException { + throws ProtocolHandleException { CloudEventBuilder cloudEventBuilder; String protocolType = header.getProperty(Constants.PROTOCOL_TYPE).toString(); @@ -46,11 +46,11 @@ public static CloudEvent buildEvent(Header header, String cloudEventJson) String protocolDesc = header.getProperty(Constants.PROTOCOL_DESC).toString(); if (StringUtils.isBlank(protocolType) - || StringUtils.isBlank(protocolVersion) - || StringUtils.isBlank(protocolDesc)) { + || StringUtils.isBlank(protocolVersion) + || StringUtils.isBlank(protocolDesc)) { throw new ProtocolHandleException( - String.format("invalid protocol params protocolType %s|protocolVersion %s|protocolDesc %s", - protocolType, protocolVersion, protocolDesc)); + String.format("invalid protocol params protocolType %s|protocolVersion %s|protocolDesc %s", + protocolType, protocolVersion, protocolDesc)); } if (!StringUtils.equals(CloudEventsProtocolConstant.PROTOCOL_NAME, protocolType)) { @@ -61,7 +61,7 @@ public static CloudEvent buildEvent(Header header, String cloudEventJson) // todo:resolve different format EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE); Preconditions - .checkNotNull(eventFormat, String.format("EventFormat: %s is not supported", JsonFormat.CONTENT_TYPE)); + .checkNotNull(eventFormat, String.format("EventFormat: %s is not supported", JsonFormat.CONTENT_TYPE)); CloudEvent event = eventFormat.deserialize(cloudEventJson.getBytes(StandardCharsets.UTF_8)); cloudEventBuilder = CloudEventBuilder.v1(event); for (String propKey : header.getProperties().keySet()) { @@ -73,7 +73,7 @@ public static CloudEvent buildEvent(Header header, String cloudEventJson) } else if (StringUtils.equals(SpecVersion.V03.toString(), protocolVersion)) { // todo:resolve different format CloudEvent event = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE) - .deserialize(cloudEventJson.getBytes(StandardCharsets.UTF_8)); + .deserialize(cloudEventJson.getBytes(StandardCharsets.UTF_8)); cloudEventBuilder = CloudEventBuilder.v03(event); for (String propKey : header.getProperties().keySet()) { diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/test/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptorTest.java b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/test/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptorTest.java index 5155cf6e84..e4c684a208 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/test/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptorTest.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-cloudevents/src/test/java/org/apache/eventmesh/protocol/cloudevents/CloudEventsProtocolAdaptorTest.java @@ -29,11 +29,11 @@ public class CloudEventsProtocolAdaptorTest { @Test public void loadPlugin() { ProtocolAdaptor protocolAdaptor = - ProtocolPluginFactory.getProtocolAdaptor(CloudEventsProtocolConstant.PROTOCOL_NAME); + ProtocolPluginFactory.getProtocolAdaptor(CloudEventsProtocolConstant.PROTOCOL_NAME); Assert.assertNotNull(protocolAdaptor); Assert.assertEquals( - CloudEventsProtocolConstant.PROTOCOL_NAME, protocolAdaptor.getProtocolType()); + CloudEventsProtocolConstant.PROTOCOL_NAME, protocolAdaptor.getProtocolType()); Assert.assertEquals(CloudEventsProtocolAdaptor.class, protocolAdaptor.getClass()); } } \ No newline at end of file diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java index 75a99fd51c..f1be1af82e 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptor.java @@ -99,9 +99,10 @@ public ProtocolTransportObject fromCloudEvent(CloudEvent cloudEvent) throws Prot HttpCommand httpCommand = new HttpCommand(); Body body = new Body() { final Map map = new HashMap<>(); + @Override public Map toMap() { - map.put("content", new String(cloudEvent.getData().toBytes(), StandardCharsets.UTF_8)); + map.put("content", new String(cloudEvent.getData().toBytes(), StandardCharsets.UTF_8)); return map; } }; diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageBatchProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageBatchProtocolResolver.java index cd8f8179e7..e5762dc354 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageBatchProtocolResolver.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageBatchProtocolResolver.java @@ -17,10 +17,11 @@ package org.apache.eventmesh.protocol.meshmessage.resolver.http; -import io.cloudevents.CloudEvent; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.header.Header; +import io.cloudevents.CloudEvent; + public class SendMessageBatchProtocolResolver { public static CloudEvent buildEvent(Header header, Body body) { return null; diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageBatchV2ProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageBatchV2ProtocolResolver.java index 0f3678fae7..eefe660a37 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageBatchV2ProtocolResolver.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageBatchV2ProtocolResolver.java @@ -17,10 +17,6 @@ package org.apache.eventmesh.protocol.meshmessage.resolver.http; -import io.cloudevents.CloudEvent; -import io.cloudevents.SpecVersion; -import io.cloudevents.core.builder.CloudEventBuilder; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.protocol.http.body.Body; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageBatchV2RequestBody; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody; @@ -30,9 +26,15 @@ import org.apache.eventmesh.common.protocol.http.header.message.SendMessageBatchV2RequestHeader; import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException; +import org.apache.commons.lang3.StringUtils; + import java.net.URI; import java.nio.charset.StandardCharsets; +import io.cloudevents.CloudEvent; +import io.cloudevents.SpecVersion; +import io.cloudevents.core.builder.CloudEventBuilder; + public class SendMessageBatchV2ProtocolResolver { public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHandleException { try { diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageRequestProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageRequestProtocolResolver.java index ace5bfeadd..b53245ffa1 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageRequestProtocolResolver.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/http/SendMessageRequestProtocolResolver.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.protocol.meshmessage.resolver.http; import org.apache.eventmesh.common.protocol.http.body.Body; -import org.apache.eventmesh.common.protocol.http.body.message.SendMessageBatchV2RequestBody; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; @@ -65,28 +64,28 @@ public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHan cloudEventBuilder = CloudEventBuilder.v1(); cloudEventBuilder = cloudEventBuilder.withId(sendMessageRequestBody.getBizSeqNo()) - .withSubject(sendMessageRequestBody.getTopic()) - .withType("eventmeshmessage") - .withSource(URI.create("/")) - .withData(content.getBytes(StandardCharsets.UTF_8)) - .withExtension(ProtocolKey.REQUEST_CODE, code) - .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) - .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc) - .withExtension(ProtocolKey.ClientInstanceKey.IP, ip) - .withExtension(ProtocolKey.ClientInstanceKey.PID, pid) - .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys) - .withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username) - .withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd) - .withExtension(ProtocolKey.VERSION, version.getVersion()) - .withExtension(ProtocolKey.LANGUAGE, language) - .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType) - .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc) - .withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion) - .withExtension(SendMessageRequestBody.BIZSEQNO, sendMessageRequestBody.getBizSeqNo()) - .withExtension(SendMessageRequestBody.UNIQUEID, sendMessageRequestBody.getUniqueId()) - .withExtension(SendMessageRequestBody.PRODUCERGROUP, - sendMessageRequestBody.getProducerGroup()) - .withExtension(SendMessageRequestBody.TTL, sendMessageRequestBody.getTtl()); + .withSubject(sendMessageRequestBody.getTopic()) + .withType("eventmeshmessage") + .withSource(URI.create("/")) + .withData(content.getBytes(StandardCharsets.UTF_8)) + .withExtension(ProtocolKey.REQUEST_CODE, code) + .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) + .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc) + .withExtension(ProtocolKey.ClientInstanceKey.IP, ip) + .withExtension(ProtocolKey.ClientInstanceKey.PID, pid) + .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys) + .withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username) + .withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd) + .withExtension(ProtocolKey.VERSION, version.getVersion()) + .withExtension(ProtocolKey.LANGUAGE, language) + .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType) + .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc) + .withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion) + .withExtension(SendMessageRequestBody.BIZSEQNO, sendMessageRequestBody.getBizSeqNo()) + .withExtension(SendMessageRequestBody.UNIQUEID, sendMessageRequestBody.getUniqueId()) + .withExtension(SendMessageRequestBody.PRODUCERGROUP, + sendMessageRequestBody.getProducerGroup()) + .withExtension(SendMessageRequestBody.TTL, sendMessageRequestBody.getTtl()); if (StringUtils.isNotEmpty(sendMessageRequestBody.getTag())) { cloudEventBuilder = cloudEventBuilder.withExtension(SendMessageRequestBody.TAG, sendMessageRequestBody.getTag()); } @@ -94,28 +93,28 @@ public static CloudEvent buildEvent(Header header, Body body) throws ProtocolHan } else if (StringUtils.equals(SpecVersion.V03.toString(), protocolVersion)) { cloudEventBuilder = CloudEventBuilder.v03(); cloudEventBuilder = cloudEventBuilder.withId(sendMessageRequestBody.getBizSeqNo()) - .withSubject(sendMessageRequestBody.getTopic()) - .withType("eventmeshmessage") - .withSource(URI.create("/")) - .withData(content.getBytes(StandardCharsets.UTF_8)) - .withExtension(ProtocolKey.REQUEST_CODE, code) - .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) - .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc) - .withExtension(ProtocolKey.ClientInstanceKey.IP, ip) - .withExtension(ProtocolKey.ClientInstanceKey.PID, pid) - .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys) - .withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username) - .withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd) - .withExtension(ProtocolKey.VERSION, version.getVersion()) - .withExtension(ProtocolKey.LANGUAGE, language) - .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType) - .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc) - .withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion) - .withExtension(SendMessageRequestBody.BIZSEQNO, sendMessageRequestBody.getBizSeqNo()) - .withExtension(SendMessageRequestBody.UNIQUEID, sendMessageRequestBody.getUniqueId()) - .withExtension(SendMessageRequestBody.PRODUCERGROUP, - sendMessageRequestBody.getProducerGroup()) - .withExtension(SendMessageRequestBody.TTL, sendMessageRequestBody.getTtl()); + .withSubject(sendMessageRequestBody.getTopic()) + .withType("eventmeshmessage") + .withSource(URI.create("/")) + .withData(content.getBytes(StandardCharsets.UTF_8)) + .withExtension(ProtocolKey.REQUEST_CODE, code) + .withExtension(ProtocolKey.ClientInstanceKey.ENV, env) + .withExtension(ProtocolKey.ClientInstanceKey.IDC, idc) + .withExtension(ProtocolKey.ClientInstanceKey.IP, ip) + .withExtension(ProtocolKey.ClientInstanceKey.PID, pid) + .withExtension(ProtocolKey.ClientInstanceKey.SYS, sys) + .withExtension(ProtocolKey.ClientInstanceKey.USERNAME, username) + .withExtension(ProtocolKey.ClientInstanceKey.PASSWD, passwd) + .withExtension(ProtocolKey.VERSION, version.getVersion()) + .withExtension(ProtocolKey.LANGUAGE, language) + .withExtension(ProtocolKey.PROTOCOL_TYPE, protocolType) + .withExtension(ProtocolKey.PROTOCOL_DESC, protocolDesc) + .withExtension(ProtocolKey.PROTOCOL_VERSION, protocolVersion) + .withExtension(SendMessageRequestBody.BIZSEQNO, sendMessageRequestBody.getBizSeqNo()) + .withExtension(SendMessageRequestBody.UNIQUEID, sendMessageRequestBody.getUniqueId()) + .withExtension(SendMessageRequestBody.PRODUCERGROUP, + sendMessageRequestBody.getProducerGroup()) + .withExtension(SendMessageRequestBody.TTL, sendMessageRequestBody.getTtl()); if (StringUtils.isNotEmpty(sendMessageRequestBody.getTag())) { cloudEventBuilder = cloudEventBuilder.withExtension(SendMessageRequestBody.TAG, sendMessageRequestBody.getTag()); } diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/tcp/TcpMessageProtocolResolver.java b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/tcp/TcpMessageProtocolResolver.java index e0d2f4e789..1ee7051dff 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/tcp/TcpMessageProtocolResolver.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/main/java/org/apache/eventmesh/protocol/meshmessage/resolver/tcp/TcpMessageProtocolResolver.java @@ -17,10 +17,6 @@ package org.apache.eventmesh.protocol.meshmessage.resolver.tcp; -import io.cloudevents.CloudEvent; -import io.cloudevents.SpecVersion; -import io.cloudevents.core.builder.CloudEventBuilder; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Header; @@ -28,11 +24,17 @@ import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException; import org.apache.eventmesh.protocol.meshmessage.MeshMessageProtocolConstant; +import org.apache.commons.lang3.StringUtils; + import java.net.URI; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; +import io.cloudevents.CloudEvent; +import io.cloudevents.SpecVersion; +import io.cloudevents.core.builder.CloudEventBuilder; + public class TcpMessageProtocolResolver { diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/test/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptorTest.java b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/test/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptorTest.java index 54108bf79f..d67c58071a 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/test/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptorTest.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-meshmessage/src/test/java/org/apache/eventmesh/protocol/meshmessage/MeshMessageProtocolAdaptorTest.java @@ -29,11 +29,11 @@ public class MeshMessageProtocolAdaptorTest { @Test public void loadPlugin() { ProtocolAdaptor protocolAdaptor = - ProtocolPluginFactory.getProtocolAdaptor(MeshMessageProtocolConstant.PROTOCOL_NAME); + ProtocolPluginFactory.getProtocolAdaptor(MeshMessageProtocolConstant.PROTOCOL_NAME); Assert.assertNotNull(protocolAdaptor); Assert.assertEquals( - MeshMessageProtocolConstant.PROTOCOL_NAME, protocolAdaptor.getProtocolType() + MeshMessageProtocolConstant.PROTOCOL_NAME, protocolAdaptor.getProtocolType() ); } diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-openmessage/src/main/java/org/apache/eventmesh/protocol/openmessage/OpenMessageProtocolAdaptor.java b/eventmesh-protocol-plugin/eventmesh-protocol-openmessage/src/main/java/org/apache/eventmesh/protocol/openmessage/OpenMessageProtocolAdaptor.java index 00a48b19a8..0e2d525049 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-openmessage/src/main/java/org/apache/eventmesh/protocol/openmessage/OpenMessageProtocolAdaptor.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-openmessage/src/main/java/org/apache/eventmesh/protocol/openmessage/OpenMessageProtocolAdaptor.java @@ -19,13 +19,13 @@ import org.apache.eventmesh.common.protocol.ProtocolTransportObject; import org.apache.eventmesh.protocol.api.ProtocolAdaptor; - -import io.cloudevents.CloudEvent; -import io.openmessaging.api.Message; import org.apache.eventmesh.protocol.api.exception.ProtocolHandleException; import java.util.List; +import io.cloudevents.CloudEvent; +import io.openmessaging.api.Message; + /** * OpenMessage protocol adaptor, used to transform protocol between * {@link CloudEvent} with {@link Message}. diff --git a/eventmesh-protocol-plugin/eventmesh-protocol-openmessage/src/test/java/org/apache/eventmesh/protocol/openmessage/OpenMessageProtocolAdaptorTest.java b/eventmesh-protocol-plugin/eventmesh-protocol-openmessage/src/test/java/org/apache/eventmesh/protocol/openmessage/OpenMessageProtocolAdaptorTest.java index 5d833ec580..b0c49707fa 100644 --- a/eventmesh-protocol-plugin/eventmesh-protocol-openmessage/src/test/java/org/apache/eventmesh/protocol/openmessage/OpenMessageProtocolAdaptorTest.java +++ b/eventmesh-protocol-plugin/eventmesh-protocol-openmessage/src/test/java/org/apache/eventmesh/protocol/openmessage/OpenMessageProtocolAdaptorTest.java @@ -29,11 +29,11 @@ public class OpenMessageProtocolAdaptorTest { @Test public void loadPlugin() { ProtocolAdaptor protocolAdaptor = - ProtocolPluginFactory.getProtocolAdaptor(OpenMessageProtocolConstant.PROTOCOL_NAME); + ProtocolPluginFactory.getProtocolAdaptor(OpenMessageProtocolConstant.PROTOCOL_NAME); Assert.assertNotNull(protocolAdaptor); Assert.assertEquals( - OpenMessageProtocolConstant.PROTOCOL_NAME, protocolAdaptor.getProtocolType() + OpenMessageProtocolConstant.PROTOCOL_NAME, protocolAdaptor.getProtocolType() ); Assert.assertEquals(OpenMessageProtocolAdaptor.class, protocolAdaptor.getClass()); } diff --git a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/exception/RegistryException.java b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/exception/RegistryException.java index 31453efb3b..893f8ff25c 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/exception/RegistryException.java +++ b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/exception/RegistryException.java @@ -14,8 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.api.exception; +/** + * RegistryException + */ public class RegistryException extends RuntimeException { public RegistryException(String message) { diff --git a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/RegistryService.java b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/RegistryService.java index 5363b2d8b0..f9520176ae 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/RegistryService.java +++ b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/RegistryService.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.api.registry; import org.apache.eventmesh.api.exception.RegistryException; @@ -26,6 +27,9 @@ import java.util.List; import java.util.Map; +/** + * RegistryService + */ @EventMeshSPI(isSingleton = true, eventMeshExtensionType = EventMeshExtensionType.REGISTRY) public interface RegistryService { void init() throws RegistryException; @@ -36,7 +40,8 @@ public interface RegistryService { List findEventMeshInfoByCluster(String clusterName) throws RegistryException; - Map> findEventMeshClientDistributionData(String clusterName, String group, String purpose) throws RegistryException; + Map> findEventMeshClientDistributionData( + String clusterName, String group, String purpose) throws RegistryException; boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws RegistryException; diff --git a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshDataInfo.java b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshDataInfo.java index 389d1e4949..228053a09e 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshDataInfo.java +++ b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshDataInfo.java @@ -14,8 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.api.registry.dto; +/** + * EventMeshDataInfo + */ public class EventMeshDataInfo { private String eventMeshClusterName; private String eventMeshName; diff --git a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshRegisterInfo.java b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshRegisterInfo.java index 98eaf5d495..5560d19919 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshRegisterInfo.java +++ b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshRegisterInfo.java @@ -14,10 +14,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.api.registry.dto; import java.util.Map; +/** + * EventMeshRegisterInfo + */ public class EventMeshRegisterInfo { private String eventMeshClusterName; private String eventMeshName; diff --git a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshUnRegisterInfo.java b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshUnRegisterInfo.java index 06e54a01db..2216454348 100644 --- a/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshUnRegisterInfo.java +++ b/eventmesh-registry-plugin/eventmesh-registry-api/src/main/java/org/apache/eventmesh/api/registry/dto/EventMeshUnRegisterInfo.java @@ -14,8 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.api.registry.dto; +/** + * EventMeshUnRegisterInfo + */ public class EventMeshUnRegisterInfo { private String eventMeshClusterName; private String eventMeshName; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/acl/Acl.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/acl/Acl.java index bf762ebd92..7d07aafb42 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/acl/Acl.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/acl/Acl.java @@ -14,27 +14,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.acl; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.api.acl.AclPropertyKeys; import org.apache.eventmesh.api.acl.AclService; import org.apache.eventmesh.api.exception.AclException; -//import org.apache.eventmesh.api.producer.MeshMQProducer; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.spi.EventMeshExtensionFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.util.Properties; import java.util.ServiceLoader; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class Acl { private static final Logger logger = LoggerFactory.getLogger(Acl.class); private static AclService aclService; - public void init(String aclPluginType) throws AclException{ -// aclService = getSpiAclService(); + public void init(String aclPluginType) throws AclException { + //aclService = getSpiAclService(); aclService = EventMeshExtensionFactory.getExtension(AclService.class, aclPluginType); if (aclService == null) { logger.error("can't load the aclService plugin, please check."); @@ -43,63 +45,67 @@ public void init(String aclPluginType) throws AclException{ aclService.init(); } - public void start() throws AclException{ + public void start() throws AclException { aclService.start(); } - public void shutdown() throws AclException{ + public void shutdown() throws AclException { aclService.shutdown(); } - public static void doAclCheckInTcpConnect(String remoteAddr, UserAgent userAgent, int requestCode) throws AclException{ + public static void doAclCheckInTcpConnect(String remoteAddr, UserAgent userAgent, int requestCode) throws AclException { aclService.doAclCheckInConnect(buildTcpAclProperties(remoteAddr, userAgent, null, requestCode)); } - public static void doAclCheckInTcpHeartbeat(String remoteAddr, UserAgent userAgent, int requestCode) throws AclException{ + public static void doAclCheckInTcpHeartbeat(String remoteAddr, UserAgent userAgent, int requestCode) throws AclException { aclService.doAclCheckInHeartbeat(buildTcpAclProperties(remoteAddr, userAgent, null, requestCode)); } - public static void doAclCheckInTcpSend(String remoteAddr, UserAgent userAgent, String topic, int requestCode) throws AclException{ + public static void doAclCheckInTcpSend(String remoteAddr, UserAgent userAgent, String topic, int requestCode) throws AclException { aclService.doAclCheckInSend(buildTcpAclProperties(remoteAddr, userAgent, topic, requestCode)); } - public static void doAclCheckInTcpReceive(String remoteAddr, UserAgent userAgent, String topic, int requestCode) throws AclException{ + public static void doAclCheckInTcpReceive(String remoteAddr, UserAgent userAgent, String topic, int requestCode) throws AclException { aclService.doAclCheckInReceive(buildTcpAclProperties(remoteAddr, userAgent, topic, requestCode)); } - private static Properties buildTcpAclProperties(String remoteAddr, UserAgent userAgent, String topic, int requestCode){ + private static Properties buildTcpAclProperties(String remoteAddr, UserAgent userAgent, String topic, int requestCode) { Properties aclProperties = new Properties(); aclProperties.put(AclPropertyKeys.CLIENT_IP, remoteAddr); aclProperties.put(AclPropertyKeys.USER, userAgent.getUsername()); aclProperties.put(AclPropertyKeys.PASSWORD, userAgent.getPassword()); aclProperties.put(AclPropertyKeys.SUBSYSTEM, userAgent.getSubsystem()); aclProperties.put(AclPropertyKeys.REQUEST_CODE, requestCode); - if(StringUtils.isNotBlank(topic)) { + if (StringUtils.isNotBlank(topic)) { aclProperties.put(AclPropertyKeys.TOPIC, topic); } return aclProperties; } - public static void doAclCheckInHttpSend(String remoteAddr, String user, String pass,String subsystem, String topic, int requestCode) throws AclException{ + public static void doAclCheckInHttpSend(String remoteAddr, String user, String pass, String subsystem, String topic, + int requestCode) throws AclException { aclService.doAclCheckInSend(buildHttpAclProperties(remoteAddr, user, pass, subsystem, topic, requestCode)); } - public static void doAclCheckInHttpReceive(String remoteAddr, String user, String pass,String subsystem, String topic, int requestCode) throws AclException{ + public static void doAclCheckInHttpReceive(String remoteAddr, String user, String pass, String subsystem, String topic, + int requestCode) throws AclException { aclService.doAclCheckInReceive(buildHttpAclProperties(remoteAddr, user, pass, subsystem, topic, requestCode)); } - public static void doAclCheckInHttpHeartbeat(String remoteAddr, String user, String pass,String subsystem, String topic, int requestCode) throws AclException{ + public static void doAclCheckInHttpHeartbeat(String remoteAddr, String user, String pass, String subsystem, String topic, + int requestCode) throws AclException { aclService.doAclCheckInHeartbeat(buildHttpAclProperties(remoteAddr, user, pass, subsystem, topic, requestCode)); } - private static Properties buildHttpAclProperties(String remoteAddr, String user, String pass,String subsystem, String topic, int requestCode){ + private static Properties buildHttpAclProperties(String remoteAddr, String user, String pass, String subsystem, + String topic, int requestCode) { Properties aclProperties = new Properties(); aclProperties.put(AclPropertyKeys.CLIENT_IP, remoteAddr); aclProperties.put(AclPropertyKeys.USER, user); aclProperties.put(AclPropertyKeys.PASSWORD, pass); aclProperties.put(AclPropertyKeys.SUBSYSTEM, subsystem); aclProperties.put(AclPropertyKeys.REQUEST_CODE, requestCode); - if(StringUtils.isNotBlank(topic)) { + if (StringUtils.isNotBlank(topic)) { aclProperties.put(AclPropertyKeys.TOPIC, topic); } return aclProperties; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/controller/ClientManageController.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/controller/ClientManageController.java index 3fc2e8e2b8..1c95127619 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/controller/ClientManageController.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/controller/ClientManageController.java @@ -43,7 +43,7 @@ public class ClientManageController { private static final Logger logger = LoggerFactory.getLogger(ClientManageController.class); private EventMeshTCPServer eventMeshTCPServer; - + private AdminController adminController; public ClientManageController(EventMeshTCPServer eventMeshTCPServer) { @@ -63,10 +63,10 @@ public void start() throws IOException { server.createContext("/clientManage/redirectClientByIpPort", new RedirectClientByIpPortHandler(eventMeshTCPServer)); server.createContext("/clientManage/showListenClientByTopic", new ShowListenClientByTopicHandler(eventMeshTCPServer)); server.createContext("/eventMesh/recommend", new QueryRecommendEventMeshHandler(eventMeshTCPServer)); - + adminController = new AdminController(); adminController.run(server); - + server.start(); logger.info("ClientManageController start success, port:{}", port); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java index 41af41ac03..51ebf9e68c 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/QueryRecommendEventMeshHandler.java @@ -17,26 +17,23 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import org.apache.commons.lang3.StringUtils; -import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendImpl; import org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendStrategy; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.NetUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.io.OutputStream; import java.util.Map; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; /** * query recommend eventmesh @@ -55,12 +52,12 @@ public QueryRecommendEventMeshHandler(EventMeshTCPServer eventMeshTCPServer) { public void handle(HttpExchange httpExchange) throws IOException { String result = ""; OutputStream out = httpExchange.getResponseBody(); - try{ - if(!eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerRegistryEnable) { + try { + if (!eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerRegistryEnable) { throw new Exception("registry enable config is false, not support"); } - String queryString = httpExchange.getRequestURI().getQuery(); - Map queryStringInfo = NetUtils.formData2Dic(queryString); + String queryString = httpExchange.getRequestURI().getQuery(); + Map queryStringInfo = NetUtils.formData2Dic(queryString); String group = queryStringInfo.get(EventMeshConstants.MANAGE_GROUP); String purpose = queryStringInfo.get(EventMeshConstants.MANAGE_PURPOSE); if (StringUtils.isBlank(group) || StringUtils.isBlank(purpose)) { @@ -73,16 +70,16 @@ public void handle(HttpExchange httpExchange) throws IOException { EventMeshRecommendStrategy eventMeshRecommendStrategy = new EventMeshRecommendImpl(eventMeshTCPServer); String recommendEventMeshResult = eventMeshRecommendStrategy.calculateRecommendEventMesh(group, purpose); result = (recommendEventMeshResult == null) ? "null" : recommendEventMeshResult; - logger.info("recommend eventmesh:{},group:{},purpose:{}",result, group, purpose); + logger.info("recommend eventmesh:{},group:{},purpose:{}", result, group, purpose); httpExchange.sendResponseHeaders(200, 0); out.write(result.getBytes()); - }catch (Exception e){ + } catch (Exception e) { logger.error("QueryRecommendEventMeshHandler fail...", e); - }finally { - if(out != null){ + } finally { + if (out != null) { try { out.close(); - }catch (IOException e){ + } catch (IOException e) { logger.warn("out close failed...", e); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java index 79ba4bd98f..2039c227f2 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandler.java @@ -17,17 +17,14 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.NetUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.io.OutputStream; @@ -35,6 +32,12 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + public class RedirectClientByIpPortHandler implements HttpHandler { private static final Logger logger = LoggerFactory.getLogger(RedirectClientByIpPortHandler.class); @@ -65,24 +68,29 @@ public void handle(HttpExchange httpExchange) throws IOException { out.write(result.getBytes()); return; } - logger.info("redirectClientByIpPort in admin,ip:{},port:{},destIp:{},destPort:{}====================", ip, port, destEventMeshIp, destEventMeshPort); + logger.info("redirectClientByIpPort in admin,ip:{},port:{},destIp:{},destPort:{}====================", ip, + port, destEventMeshIp, destEventMeshPort); ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); String redirectResult = ""; try { if (!sessionMap.isEmpty()) { for (Session session : sessionMap.values()) { - if (session.getClient().getHost().equals(ip) && String.valueOf(session.getClient().getPort()).equals(port)) { + if (session.getClient().getHost().equals(ip) && String.valueOf( + session.getClient().getPort()).equals(port)) { redirectResult += "|"; - redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, destEventMeshIp, Integer.parseInt(destEventMeshPort), + redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, + destEventMeshIp, Integer.parseInt(destEventMeshPort), session, clientSessionGroupMapping); } } } } catch (Exception e) { - logger.error("clientManage|redirectClientByIpPort|fail|ip={}|port={}|destEventMeshIp" + + logger.error("clientManage|redirectClientByIpPort|fail|ip={}|port={}|destEventMeshIp" + + "={}|destEventMeshPort={},errMsg={}", ip, port, destEventMeshIp, destEventMeshPort, e); - result = String.format("redirectClientByIpPort fail! sessionMap size {%d}, {clientIp=%s clientPort=%s " + + result = String.format("redirectClientByIpPort fail! sessionMap size {%d}, {clientIp=%s clientPort=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", sessionMap.size(), ip, port, destEventMeshIp, destEventMeshPort, redirectResult, e .getMessage()); @@ -90,7 +98,8 @@ public void handle(HttpExchange httpExchange) throws IOException { out.write(result.getBytes()); return; } - result = String.format("redirectClientByIpPort success! sessionMap size {%d}, {ip=%s port=%s " + + result = String.format("redirectClientByIpPort success! sessionMap size {%d}, {ip=%s port=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", sessionMap.size(), ip, port, destEventMeshIp, destEventMeshPort, redirectResult); httpExchange.sendResponseHeaders(200, 0); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java index b605a1cc64..b5f83ac890 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByPathHandler.java @@ -17,17 +17,14 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.NetUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.io.OutputStream; @@ -35,6 +32,12 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + /** * redirect subsystem for path */ @@ -59,14 +62,16 @@ public void handle(HttpExchange httpExchange) throws IOException { String destEventMeshIp = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_IP); String destEventMeshPort = queryStringInfo.get(EventMeshConstants.MANAGE_DEST_PORT); - if (StringUtils.isBlank(path) || StringUtils.isBlank(destEventMeshIp) || StringUtils.isBlank(destEventMeshPort) || - !StringUtils.isNumeric(destEventMeshPort)) { + if (StringUtils.isBlank(path) || StringUtils.isBlank(destEventMeshIp) + || StringUtils.isBlank(destEventMeshPort) + || !StringUtils.isNumeric(destEventMeshPort)) { httpExchange.sendResponseHeaders(200, 0); result = "params illegal!"; out.write(result.getBytes()); return; } - logger.info("redirectClientByPath in admin,path:{},destIp:{},destPort:{}====================", path, destEventMeshIp, destEventMeshPort); + logger.info("redirectClientByPath in admin,path:{},destIp:{},destPort:{}====================", path, + destEventMeshIp, destEventMeshPort); ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); String redirectResult = ""; @@ -75,15 +80,18 @@ public void handle(HttpExchange httpExchange) throws IOException { for (Session session : sessionMap.values()) { if (session.getClient().getPath().contains(path)) { redirectResult += "|"; - redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, destEventMeshIp, Integer.parseInt(destEventMeshPort), + redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, + destEventMeshIp, Integer.parseInt(destEventMeshPort), session, clientSessionGroupMapping); } } } } catch (Exception e) { - logger.error("clientManage|redirectClientByPath|fail|path={}|destEventMeshIp" + + logger.error("clientManage|redirectClientByPath|fail|path={}|destEventMeshIp" + + "={}|destEventMeshPort={},errMsg={}", path, destEventMeshIp, destEventMeshPort, e); - result = String.format("redirectClientByPath fail! sessionMap size {%d}, {path=%s " + + result = String.format("redirectClientByPath fail! sessionMap size {%d}, {path=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", sessionMap.size(), path, destEventMeshIp, destEventMeshPort, redirectResult, e .getMessage()); @@ -91,7 +99,8 @@ public void handle(HttpExchange httpExchange) throws IOException { out.write(result.getBytes()); return; } - result = String.format("redirectClientByPath success! sessionMap size {%d}, {path=%s " + + result = String.format("redirectClientByPath success! sessionMap size {%d}, {path=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", sessionMap.size(), path, destEventMeshIp, destEventMeshPort, redirectResult); httpExchange.sendResponseHeaders(200, 0); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java index 400c8c0e8e..6fae83c30f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientBySubSystemHandler.java @@ -17,17 +17,14 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.NetUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.io.OutputStream; @@ -35,6 +32,12 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + /** * redirect subsystem for subsys and dcn */ @@ -67,7 +70,8 @@ public void handle(HttpExchange httpExchange) throws IOException { out.write(result.getBytes()); return; } - logger.info("redirectClientBySubSystem in admin,subsys:{},destIp:{},destPort:{}====================", subSystem, destEventMeshIp, destEventMeshPort); + logger.info("redirectClientBySubSystem in admin,subsys:{},destIp:{},destPort:{}====================", + subSystem, destEventMeshIp, destEventMeshPort); ClientSessionGroupMapping clientSessionGroupMapping = eventMeshTCPServer.getClientSessionGroupMapping(); ConcurrentHashMap sessionMap = clientSessionGroupMapping.getSessionMap(); String redirectResult = ""; @@ -76,15 +80,18 @@ public void handle(HttpExchange httpExchange) throws IOException { for (Session session : sessionMap.values()) { if (session.getClient().getSubsystem().equals(subSystem)) { redirectResult += "|"; - redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, destEventMeshIp, Integer.parseInt(destEventMeshPort), + redirectResult += EventMeshTcp2Client.redirectClient2NewEventMesh(eventMeshTCPServer, + destEventMeshIp, Integer.parseInt(destEventMeshPort), session, clientSessionGroupMapping); } } } } catch (Exception e) { - logger.error("clientManage|redirectClientBySubSystem|fail|subSystem={}|destEventMeshIp" + + logger.error("clientManage|redirectClientBySubSystem|fail|subSystem={}|destEventMeshIp" + + "={}|destEventMeshPort={},errMsg={}", subSystem, destEventMeshIp, destEventMeshPort, e); - result = String.format("redirectClientBySubSystem fail! sessionMap size {%d}, {subSystem=%s " + + result = String.format("redirectClientBySubSystem fail! sessionMap size {%d}, {subSystem=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s}, errorMsg : %s", sessionMap.size(), subSystem, destEventMeshIp, destEventMeshPort, redirectResult, e .getMessage()); @@ -92,7 +99,8 @@ public void handle(HttpExchange httpExchange) throws IOException { out.write(result.getBytes()); return; } - result = String.format("redirectClientBySubSystem success! sessionMap size {%d}, {subSystem=%s " + + result = String.format("redirectClientBySubSystem success! sessionMap size {%d}, {subSystem=%s " + + "destEventMeshIp=%s destEventMeshPort=%s}, result {%s} ", sessionMap.size(), subSystem, destEventMeshIp, destEventMeshPort, redirectResult); httpExchange.sendResponseHeaders(200, 0); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java index 7a6f598576..ca445a3b44 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectAllClientHandler.java @@ -66,7 +66,7 @@ public void handle(HttpExchange httpExchange) throws IOException { if (!sessionMap.isEmpty()) { for (Map.Entry entry : sessionMap.entrySet()) { InetSocketAddress addr = EventMeshTcp2Client.serverGoodby2Client( - eventMeshTCPServer, entry.getValue(), clientSessionGroupMapping); + eventMeshTCPServer, entry.getValue(), clientSessionGroupMapping); if (addr != null) { successRemoteAddrs.add(addr); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java index 3ddd45e492..00533f59d5 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientByIpPortHandler.java @@ -17,17 +17,14 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.NetUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.io.OutputStream; @@ -37,6 +34,12 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + public class RejectClientByIpPortHandler implements HttpHandler { private static final Logger logger = LoggerFactory.getLogger(RejectClientByIpPortHandler.class); @@ -71,7 +74,8 @@ public void handle(HttpExchange httpExchange) throws IOException { if (!sessionMap.isEmpty()) { for (Map.Entry entry : sessionMap.entrySet()) { if (entry.getKey().getHostString().equals(ip) && String.valueOf(entry.getKey().getPort()).equals(port)) { - InetSocketAddress addr = EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer, entry.getValue(), clientSessionGroupMapping); + InetSocketAddress addr = EventMeshTcp2Client.serverGoodby2Client(eventMeshTCPServer, + entry.getValue(), clientSessionGroupMapping); if (addr != null) { successRemoteAddrs.add(addr); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java index e5208c665c..90cca19104 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/RejectClientBySubSystemHandler.java @@ -17,17 +17,14 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcp2Client; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.NetUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.io.IOException; import java.io.OutputStream; @@ -37,6 +34,12 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + public class RejectClientBySubSystemHandler implements HttpHandler { private static final Logger logger = LoggerFactory.getLogger(RejectClientBySubSystemHandler.class); @@ -60,6 +63,7 @@ private String printClients(List clients) { /** * remove c client by dcn and susysId + * * @param httpExchange * @throws IOException */ @@ -96,13 +100,15 @@ public void handle(HttpExchange httpExchange) throws IOException { } } catch (Exception e) { logger.error("clientManage|rejectClientBySubSystem|fail|subSystemId={},errMsg={}", subSystem, e); - result = String.format("rejectClientBySubSystem fail! sessionMap size {%d}, had reject {%d} , {" + + result = String.format("rejectClientBySubSystem fail! sessionMap size {%d}, had reject {%d} , {" + + "subSystemId=%s}, errorMsg : %s", sessionMap.size(), printClients(successRemoteAddrs), subSystem, e.getMessage()); httpExchange.sendResponseHeaders(200, 0); out.write(result.getBytes()); return; } - result = String.format("rejectClientBySubSystem success! sessionMap size {%d}, had reject {%s} , {" + + result = String.format("rejectClientBySubSystem success! sessionMap size {%d}, had reject {%s} , {" + + "subSystemId=%s}", sessionMap.size(), printClients(successRemoteAddrs), subSystem); httpExchange.sendResponseHeaders(200, 0); out.write(result.getBytes()); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java index 07cbbb20c8..29d4cd58bd 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientBySystemHandler.java @@ -17,16 +17,12 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.NetUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.OutputStream; @@ -34,6 +30,12 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + public class ShowClientBySystemHandler implements HttpHandler { private static final Logger logger = LoggerFactory.getLogger(ShowClientBySystemHandler.class); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java index 64d5c5df04..9c28f53166 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowClientHandler.java @@ -17,22 +17,23 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.OutputStream; import java.net.InetSocketAddress; -import java.util.*; +import java.util.HashMap; +import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + /** * This handler used to print the total client info */ @@ -69,7 +70,8 @@ public void handle(HttpExchange httpExchange) throws IOException { } for (Map.Entry entry : statMap.entrySet()) { - result += String.format("System=%s | ClientNum=%d", entry.getKey(), entry.getValue().intValue()) + + result += String.format("System=%s | ClientNum=%d", entry.getKey(), entry.getValue().intValue()) + + newLine; } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java index 6d8cbe4bcc..95b3272add 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/admin/handler/ShowListenClientByTopicHandler.java @@ -17,8 +17,6 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; -import com.sun.net.httpserver.HttpHandler; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -26,8 +24,6 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientSessionGroupMapping; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.NetUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.OutputStream; @@ -35,6 +31,12 @@ import java.util.Set; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + /** * query client subscription by topic */ diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractHTTPServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractHTTPServer.java index 097ed1416c..4a3f01f667 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractHTTPServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractHTTPServer.java @@ -53,8 +53,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.common.base.Preconditions; - import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelFuture; @@ -97,6 +95,8 @@ import io.opentelemetry.context.propagation.TextMapPropagator; import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import com.google.common.base.Preconditions; + public abstract class AbstractHTTPServer extends AbstractRemotingServer { public Logger httpServerLogger = LoggerFactory.getLogger(this.getClass()); @@ -120,14 +120,14 @@ public abstract class AbstractHTTPServer extends AbstractRemotingServer { public Tracer tracer; public ThreadPoolExecutor asyncContextCompleteHandler = - ThreadPoolFactory.createThreadPoolExecutor(10, 10, "EventMesh-http-asyncContext-"); + ThreadPoolFactory.createThreadPoolExecutor(10, 10, "EventMesh-http-asyncContext-"); static { DiskAttribute.deleteOnExitTemporaryFile = false; } protected final Map> - processorTable = new HashMap<>(64); + processorTable = new HashMap<>(64); public AbstractHTTPServer(int port, boolean useTLS) { this.port = port; @@ -138,7 +138,7 @@ public void sendError(ChannelHandlerContext ctx, HttpResponseStatus status) { FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); HttpHeaders responseHeaders = response.headers(); responseHeaders.add( - HttpHeaderNames.CONTENT_TYPE, String.format("text/plain; charset=%s", EventMeshConstants.DEFAULT_CHARSET) + HttpHeaderNames.CONTENT_TYPE, String.format("text/plain; charset=%s", EventMeshConstants.DEFAULT_CHARSET) ); responseHeaders.add(HttpHeaderNames.CONTENT_LENGTH, response.content().readableBytes()); responseHeaders.add(HttpHeaderNames.CONNECTION, HttpHeaderValues.KEEP_ALIVE); @@ -167,7 +167,7 @@ public void sendResponse(ChannelHandlerContext ctx, DefaultFullHttpResponse resp public void operationComplete(ChannelFuture f) { if (!f.isSuccess()) { httpLogger.warn("send response to [{}] fail, will close this channel", - RemotingHelper.parseChannelRemoteAddr(f.channel())); + RemotingHelper.parseChannelRemoteAddr(f.channel())); f.channel().close(); } } @@ -181,9 +181,9 @@ public void start() throws Exception { ServerBootstrap b = new ServerBootstrap(); SSLContext sslContext = useTLS ? SSLContextFactory.getSslContext() : null; b.group(this.bossGroup, this.workerGroup) - .channel(NioServerSocketChannel.class) - .childHandler(new HttpsServerInitializer(sslContext)) - .childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE); + .channel(NioServerSocketChannel.class) + .childHandler(new HttpsServerInitializer(sslContext)) + .childOption(ChannelOption.SO_KEEPALIVE, Boolean.TRUE); try { httpServerLogger.info("HTTPServer[port={}] started......", this.port); ChannelFuture future = b.bind(this.port).sync(); @@ -227,8 +227,8 @@ private Map parseHttpHeader(HttpRequest fullReq) { Map headerParam = new HashMap<>(); for (String key : fullReq.headers().names()) { if (StringUtils.equalsIgnoreCase(HttpHeaderNames.CONTENT_TYPE.toString(), key) - || StringUtils.equalsIgnoreCase(HttpHeaderNames.ACCEPT_ENCODING.toString(), key) - || StringUtils.equalsIgnoreCase(HttpHeaderNames.CONTENT_LENGTH.toString(), key)) { + || StringUtils.equalsIgnoreCase(HttpHeaderNames.ACCEPT_ENCODING.toString(), key) + || StringUtils.equalsIgnoreCase(HttpHeaderNames.CONTENT_LENGTH.toString(), key)) { continue; } headerParam.put(key, fullReq.headers().get(key)); @@ -268,7 +268,7 @@ private HttpResponseStatus validateHttpRequest(HttpRequest httpRequest) { private void preProcessHttpRequestHeader(ChannelHandlerContext ctx, HttpRequest httpRequest) { HttpHeaders requestHeaders = httpRequest.headers(); requestHeaders.set(ProtocolKey.ClientInstanceKey.IP, - RemotingHelper.parseChannelRemoteAddr(ctx.channel())); + RemotingHelper.parseChannelRemoteAddr(ctx.channel())); String protocolVersion = httpRequest.headers().get(ProtocolKey.VERSION); if (StringUtils.isBlank(protocolVersion)) { @@ -291,7 +291,7 @@ private Map parseHttpRequestBody(HttpRequest httpRequest) throws getDecoder.parameters().forEach((key, value) -> httpRequestBody.put(key, value.get(0))); } else if (HttpMethod.POST.equals(httpRequest.method())) { HttpPostRequestDecoder decoder = - new HttpPostRequestDecoder(defaultHttpDataFactory, httpRequest); + new HttpPostRequestDecoder(defaultHttpDataFactory, httpRequest); for (InterfaceHttpData parm : decoder.getBodyHttpDatas()) { if (parm.getHttpDataType() == InterfaceHttpData.HttpDataType.Attribute) { Attribute data = (Attribute) parm; @@ -324,9 +324,9 @@ public String get(HttpRequest carrier, String key) { } }); span = tracer.spanBuilder("HTTP " + httpRequest.method()) - .setParent(context) - .setSpanKind(SpanKind.SERVER) - .startSpan(); + .setParent(context) + .setSpanKind(SpanKind.SERVER) + .startSpan(); //attach the span to the server context context = context.with(SpanKey.SERVER_KEY, span); //put the context in channel @@ -347,9 +347,9 @@ public String get(HttpRequest carrier, String key) { final Map bodyMap = parseHttpRequestBody(httpRequest); String requestCode = - (httpRequest.method() == HttpMethod.POST) - ? httpRequest.headers().get(ProtocolKey.REQUEST_CODE) - : MapUtils.getString(bodyMap, StringUtils.lowerCase(ProtocolKey.REQUEST_CODE), ""); + (httpRequest.method() == HttpMethod.POST) + ? httpRequest.headers().get(ProtocolKey.REQUEST_CODE) + : MapUtils.getString(bodyMap, StringUtils.lowerCase(ProtocolKey.REQUEST_CODE), ""); requestCommand.setHttpMethod(httpRequest.method().name()); requestCommand.setHttpVersion(httpRequest.protocolVersion().protocolName()); @@ -364,10 +364,10 @@ public String get(HttpRequest carrier, String key) { HttpCommand responseCommand = null; if (StringUtils.isBlank(requestCode) - || !processorTable.containsKey(requestCode) - || !RequestCode.contains(Integer.valueOf(requestCode))) { + || !processorTable.containsKey(requestCode) + || !RequestCode.contains(Integer.valueOf(requestCode))) { responseCommand = - requestCommand.createHttpCommandResponse(EventMeshRetCode.EVENTMESH_REQUESTCODE_INVALID); + requestCommand.createHttpCommandResponse(EventMeshRetCode.EVENTMESH_REQUESTCODE_INVALID); sendResponse(ctx, responseCommand.httpResponse()); return; } @@ -386,7 +386,7 @@ public String get(HttpRequest carrier, String key) { } AsyncContext asyncContext = - new AsyncContext<>(requestCommand, responseCommand, asyncContextCompleteHandler); + new AsyncContext<>(requestCommand, responseCommand, asyncContextCompleteHandler); processEventMeshRequest(ctx, asyncContext); } catch (Exception ex) { httpServerLogger.error("AbrstractHTTPServer.HTTPHandler.channelRead0 err", ex); @@ -410,7 +410,7 @@ public void processEventMeshRequest(final ChannelHandlerContext ctx, HttpRequestProcessor processor = choosed.getObject1(); if (processor.rejectRequest()) { HttpCommand responseCommand = - request.createHttpCommandResponse(EventMeshRetCode.EVENTMESH_REJECT_BY_PROCESSOR_ERROR); + request.createHttpCommandResponse(EventMeshRetCode.EVENTMESH_REJECT_BY_PROCESSOR_ERROR); asyncContext.onComplete(responseCommand); if (asyncContext.isComplete()) { if (httpLogger.isDebugEnabled()) { @@ -427,7 +427,7 @@ public void processEventMeshRequest(final ChannelHandlerContext ctx, } metrics.summaryMetrics - .recordHTTPReqResTimeCost(System.currentTimeMillis() - request.getReqTime()); + .recordHTTPReqResTimeCost(System.currentTimeMillis() - request.getReqTime()); if (httpLogger.isDebugEnabled()) { httpLogger.debug("{}", asyncContext.getResponse()); @@ -487,8 +487,8 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { int c = connections.incrementAndGet(); if (c > 20000) { httpServerLogger - .warn("client|http|channelActive|remoteAddress={}|msg={}", remoteAddress, - "too many client(20000) connect this eventMesh server"); + .warn("client|http|channelActive|remoteAddress={}|msg={}", remoteAddress, + "too many client(20000) connect this eventMesh server"); ctx.close(); return; } @@ -509,7 +509,7 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) { if (event.state().equals(IdleState.ALL_IDLE)) { final String remoteAddress = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); httpServerLogger.info("client|http|userEventTriggered|remoteAddress={}|msg={}", - remoteAddress, evt.getClass().getName()); + remoteAddress, evt.getClass().getName()); ctx.close(); } } @@ -537,10 +537,10 @@ protected void initChannel(SocketChannel channel) { pipeline.addFirst("ssl", new SslHandler(sslEngine)); } pipeline.addLast(new HttpRequestDecoder(), - new HttpResponseEncoder(), - new HttpConnectionHandler(), - new HttpObjectAggregator(Integer.MAX_VALUE), - new HTTPHandler()); + new HttpResponseEncoder(), + new HttpConnectionHandler(), + new HttpObjectAggregator(Integer.MAX_VALUE), + new HTTPHandler()); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractRemotingServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractRemotingServer.java index bcf31bfd0b..311ae2e086 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractRemotingServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/AbstractRemotingServer.java @@ -17,16 +17,17 @@ package org.apache.eventmesh.runtime.boot; +import org.apache.eventmesh.common.utils.ThreadUtils; + import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicInteger; -import io.netty.channel.EventLoopGroup; -import io.netty.channel.nio.NioEventLoopGroup; - -import org.apache.eventmesh.common.utils.ThreadUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; + public abstract class AbstractRemotingServer { public Logger logger = LoggerFactory.getLogger(this.getClass()); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java index 8e223f0ee3..06e6ab6be2 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshHTTPServer.java @@ -57,10 +57,10 @@ public class EventMeshHTTPServer extends AbstractHTTPServer { private EventMeshHTTPConfiguration eventMeshHttpConfiguration; public final ConcurrentHashMap localConsumerGroupMapping = - new ConcurrentHashMap<>(); + new ConcurrentHashMap<>(); public final ConcurrentHashMap> localClientInfoMapping = - new ConcurrentHashMap<>(); + new ConcurrentHashMap<>(); public EventMeshHTTPServer(EventMeshServer eventMeshServer, EventMeshHTTPConfiguration eventMeshHttpConfiguration) { @@ -109,44 +109,44 @@ public void shutdownThreadPool() throws Exception { public void initThreadPool() throws Exception { BlockingQueue batchMsgThreadPoolQueue = - new LinkedBlockingQueue(eventMeshHttpConfiguration.eventMeshServerBatchBlockQSize); + new LinkedBlockingQueue(eventMeshHttpConfiguration.eventMeshServerBatchBlockQSize); batchMsgExecutor = - ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerBatchMsgThreadNum, - eventMeshHttpConfiguration.eventMeshServerBatchMsgThreadNum, batchMsgThreadPoolQueue, - "eventMesh-batchMsg-", true); + ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerBatchMsgThreadNum, + eventMeshHttpConfiguration.eventMeshServerBatchMsgThreadNum, batchMsgThreadPoolQueue, + "eventMesh-batchMsg-", true); BlockingQueue sendMsgThreadPoolQueue = - new LinkedBlockingQueue(eventMeshHttpConfiguration.eventMeshServerSendMsgBlockQSize); + new LinkedBlockingQueue(eventMeshHttpConfiguration.eventMeshServerSendMsgBlockQSize); sendMsgExecutor = - ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerSendMsgThreadNum, - eventMeshHttpConfiguration.eventMeshServerSendMsgThreadNum, sendMsgThreadPoolQueue, - "eventMesh-sendMsg-", true); + ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerSendMsgThreadNum, + eventMeshHttpConfiguration.eventMeshServerSendMsgThreadNum, sendMsgThreadPoolQueue, + "eventMesh-sendMsg-", true); BlockingQueue pushMsgThreadPoolQueue = - new LinkedBlockingQueue(eventMeshHttpConfiguration.eventMeshServerPushMsgBlockQSize); + new LinkedBlockingQueue(eventMeshHttpConfiguration.eventMeshServerPushMsgBlockQSize); pushMsgExecutor = - ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerPushMsgThreadNum, - eventMeshHttpConfiguration.eventMeshServerPushMsgThreadNum, pushMsgThreadPoolQueue, - "eventMesh-pushMsg-", true); + ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerPushMsgThreadNum, + eventMeshHttpConfiguration.eventMeshServerPushMsgThreadNum, pushMsgThreadPoolQueue, + "eventMesh-pushMsg-", true); BlockingQueue clientManageThreadPoolQueue = - new LinkedBlockingQueue(eventMeshHttpConfiguration.eventMeshServerClientManageBlockQSize); + new LinkedBlockingQueue(eventMeshHttpConfiguration.eventMeshServerClientManageBlockQSize); clientManageExecutor = - ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerClientManageThreadNum, - eventMeshHttpConfiguration.eventMeshServerClientManageThreadNum, clientManageThreadPoolQueue, - "eventMesh-clientManage-", true); + ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerClientManageThreadNum, + eventMeshHttpConfiguration.eventMeshServerClientManageThreadNum, clientManageThreadPoolQueue, + "eventMesh-clientManage-", true); BlockingQueue adminThreadPoolQueue = new LinkedBlockingQueue(50); adminExecutor = - ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerAdminThreadNum, - eventMeshHttpConfiguration.eventMeshServerAdminThreadNum, adminThreadPoolQueue, "eventMesh-admin-", - true); + ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerAdminThreadNum, + eventMeshHttpConfiguration.eventMeshServerAdminThreadNum, adminThreadPoolQueue, "eventMesh-admin-", + true); BlockingQueue replyMessageThreadPoolQueue = new LinkedBlockingQueue(100); replyMsgExecutor = - ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerReplyMsgThreadNum, - eventMeshHttpConfiguration.eventMeshServerReplyMsgThreadNum, replyMessageThreadPoolQueue, - "eventMesh-replyMsg-", true); + ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpConfiguration.eventMeshServerReplyMsgThreadNum, + eventMeshHttpConfiguration.eventMeshServerReplyMsgThreadNum, replyMessageThreadPoolQueue, + "eventMesh-replyMsg-", true); } public ThreadPoolExecutor getBatchMsgExecutor() { @@ -246,7 +246,7 @@ public void registerHTTPRequestProcessor() { BatchSendMessageV2Processor batchSendMessageV2Processor = new BatchSendMessageV2Processor(this); registerProcessor(RequestCode.MSG_BATCH_SEND_V2.getRequestCode(), batchSendMessageV2Processor, - batchMsgExecutor); + batchMsgExecutor); SendSyncMessageProcessor sendSyncMessageProcessor = new SendSyncMessageProcessor(this); registerProcessor(RequestCode.MSG_SEND_SYNC.getRequestCode(), sendSyncMessageProcessor, sendMsgExecutor); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java index b6c5459ff7..8dde5d75f8 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshServer.java @@ -62,7 +62,9 @@ public void init() throws Exception { acl.init(eventMeshHttpConfiguration.eventMeshSecurityPluginType); } - if (eventMeshTCPConfiguration != null && eventMeshTCPConfiguration.eventMeshTcpServerEnabled && eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { + if (eventMeshTCPConfiguration != null + && eventMeshTCPConfiguration.eventMeshTcpServerEnabled + && eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { registry.init(eventMeshTCPConfiguration.eventMeshRegistryPluginType); } @@ -76,7 +78,7 @@ public void init() throws Exception { } String eventStore = System - .getProperty(EventMeshConstants.EVENT_STORE_PROPERTIES, System.getenv(EventMeshConstants.EVENT_STORE_ENV)); + .getProperty(EventMeshConstants.EVENT_STORE_PROPERTIES, System.getenv(EventMeshConstants.EVENT_STORE_ENV)); logger.info("eventStore : {}", eventStore); serviceState = ServiceState.INITED; @@ -88,8 +90,9 @@ public void start() throws Exception { acl.start(); } - if (eventMeshTCPConfiguration != null && eventMeshTCPConfiguration.eventMeshTcpServerEnabled && - eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { + if (eventMeshTCPConfiguration != null + && eventMeshTCPConfiguration.eventMeshTcpServerEnabled + && eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { registry.start(); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshStartup.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshStartup.java index 5ad3ba9083..ef6b129e27 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshStartup.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshStartup.java @@ -17,12 +17,13 @@ package org.apache.eventmesh.runtime.boot; -import java.io.File; - import org.apache.eventmesh.common.config.ConfigurationWrapper; import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration; import org.apache.eventmesh.runtime.configuration.EventMeshTCPConfiguration; import org.apache.eventmesh.runtime.constants.EventMeshConstants; + +import java.io.File; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java index 9c624421f8..87bf8d2dde 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/EventMeshTCPServer.java @@ -17,24 +17,12 @@ package org.apache.eventmesh.runtime.boot; -import java.util.concurrent.*; - -import com.google.common.util.concurrent.RateLimiter; - -import io.netty.bootstrap.ServerBootstrap; -import io.netty.buffer.PooledByteBufAllocator; -import io.netty.channel.*; -import io.netty.channel.socket.nio.NioServerSocketChannel; -import io.netty.handler.timeout.IdleStateHandler; -import io.netty.handler.traffic.ChannelTrafficShapingHandler; -import io.netty.handler.traffic.GlobalTrafficShapingHandler; - import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo; import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo; -import org.apache.eventmesh.common.exception.EventMeshException; -import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.ThreadPoolFactory; +import org.apache.eventmesh.common.exception.EventMeshException; import org.apache.eventmesh.common.protocol.tcp.codec.Codec; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.runtime.admin.controller.ClientManageController; import org.apache.eventmesh.runtime.configuration.EventMeshTCPConfiguration; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -49,6 +37,26 @@ import org.apache.eventmesh.runtime.registry.Registry; import org.apache.eventmesh.runtime.util.EventMeshThreadFactoryImpl; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.LinkedBlockingQueue; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.buffer.PooledByteBufAllocator; +import io.netty.channel.AdaptiveRecvByteBufAllocator; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelOption; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import io.netty.handler.timeout.IdleStateHandler; +import io.netty.handler.traffic.ChannelTrafficShapingHandler; +import io.netty.handler.traffic.GlobalTrafficShapingHandler; + +import com.google.common.util.concurrent.RateLimiter; + public class EventMeshTCPServer extends AbstractRemotingServer { private ClientSessionGroupMapping clientSessionGroupMapping; @@ -130,6 +138,27 @@ public EventMeshTCPServer(EventMeshServer eventMeshServer, private void startServer() throws Exception { Runnable r = () -> { ServerBootstrap bootstrap = new ServerBootstrap(); + ChannelInitializer channelInitializer = new ChannelInitializer() { + @Override + public void initChannel(Channel ch) throws Exception { + ch.pipeline() + .addLast(new Codec.Encoder()) + .addLast(new Codec.Decoder()) + .addLast("global-traffic-shaping", globalTrafficShapingHandler) + .addLast("channel-traffic-shaping", newCTSHandler()) + .addLast(new EventMeshTcpConnectionHandler(EventMeshTCPServer.this)) + .addLast( + workerGroup, + new IdleStateHandler( + eventMeshTCPConfiguration.eventMeshTcpIdleReadSeconds, + eventMeshTCPConfiguration.eventMeshTcpIdleWriteSeconds, + eventMeshTCPConfiguration.eventMeshTcpIdleAllSeconds), + new EventMeshTcpMessageDispatcher(EventMeshTCPServer.this), + new EventMeshTcpExceptionHandler(EventMeshTCPServer.this) + ); + } + }; + bootstrap.group(bossGroup, ioGroup) .channel(NioServerSocketChannel.class) .option(ChannelOption.SO_BACKLOG, 128) @@ -144,22 +173,7 @@ private void startServer() throws Exception { .option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(2048, 4096, 65536)) .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) .childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT) - .childHandler(new ChannelInitializer() { - @Override - public void initChannel(Channel ch) throws Exception { - ch.pipeline().addLast(new Codec.Encoder()) - .addLast(new Codec.Decoder()) - .addLast("global-traffic-shaping", globalTrafficShapingHandler) - .addLast("channel-traffic-shaping", newCTSHandler()) - .addLast(new EventMeshTcpConnectionHandler(EventMeshTCPServer.this)) - .addLast(workerGroup, new IdleStateHandler(eventMeshTCPConfiguration.eventMeshTcpIdleReadSeconds, - eventMeshTCPConfiguration.eventMeshTcpIdleWriteSeconds, - eventMeshTCPConfiguration.eventMeshTcpIdleAllSeconds), - new EventMeshTcpMessageDispatcher(EventMeshTCPServer.this), - new EventMeshTcpExceptionHandler(EventMeshTCPServer.this) - ); - } - }); + .childHandler(channelInitializer); try { int port = eventMeshTCPConfiguration.eventMeshTcpServerPort; ChannelFuture f = bootstrap.bind(port).sync(); @@ -199,8 +213,9 @@ public void init() throws Exception { eventMeshTcpMonitor = new EventMeshTcpMonitor(this); eventMeshTcpMonitor.init(); - if(eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { - eventMeshRebalanceService = new EventMeshRebalanceService(this, new EventmeshRebalanceImpl(this)); + if (eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { + eventMeshRebalanceService = new EventMeshRebalanceService(this, + new EventmeshRebalanceImpl(this)); eventMeshRebalanceService.init(); } logger.info("--------------------------EventMeshTCPServer Inited"); @@ -216,7 +231,7 @@ public void start() throws Exception { eventMeshTcpMonitor.start(); - if(eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { + if (eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { eventMeshRebalanceService.start(); selfRegisterToRegistry(); } @@ -233,7 +248,7 @@ public void shutdown() throws Exception { logger.info("shutdown bossGroup, no client is allowed to connect access server"); } - if(eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { + if (eventMeshTCPConfiguration.eventMeshServerRegistryEnable) { eventMeshRebalanceService.shutdown(); selfUnRegisterToRegistry(); @@ -272,21 +287,25 @@ private void selfRegisterToRegistry() throws Exception { throw new EventMeshException("eventMesh fail to register"); } - tcpRegisterTask = scheduler.scheduleAtFixedRate(() -> { - try { - boolean heartbeatResult = registerToRegistry(); - if (!heartbeatResult) { - logger.error("selfRegisterToRegistry fail"); - } - } catch (Exception ex) { - logger.error("selfRegisterToRegistry fail", ex); - } - }, eventMeshTCPConfiguration.eventMeshRegisterIntervalInMills, eventMeshTCPConfiguration.eventMeshRegisterIntervalInMills, TimeUnit.MILLISECONDS); + tcpRegisterTask = scheduler.scheduleAtFixedRate( + () -> { + try { + boolean heartbeatResult = registerToRegistry(); + if (!heartbeatResult) { + logger.error("selfRegisterToRegistry fail"); + } + } catch (Exception ex) { + logger.error("selfRegisterToRegistry fail", ex); + } + }, + eventMeshTCPConfiguration.eventMeshRegisterIntervalInMills, + eventMeshTCPConfiguration.eventMeshRegisterIntervalInMills, + TimeUnit.MILLISECONDS); } public boolean registerToRegistry() { boolean registerResult = false; - try{ + try { String endPoints = IPUtils.getLocalAddress() + EventMeshConstants.IP_PORT_SEPARATOR + eventMeshTCPConfiguration.eventMeshTcpServerPort; EventMeshRegisterInfo self = new EventMeshRegisterInfo(); @@ -295,7 +314,7 @@ public boolean registerToRegistry() { self.setEndPoint(endPoints); self.setEventMeshInstanceNumMap(clientSessionGroupMapping.prepareProxyClientDistributionData()); registerResult = registry.register(self); - }catch (Exception e){ + } catch (Exception e) { logger.warn("eventMesh register to registry failed", e); } @@ -318,11 +337,20 @@ private void selfUnRegisterToRegistry() throws Exception { private void initThreadPool() throws Exception { super.init("eventMesh-tcp"); - scheduler = ThreadPoolFactory.createScheduledExecutor(eventMeshTCPConfiguration.eventMeshTcpGlobalScheduler, new EventMeshThreadFactoryImpl("eventMesh-tcp-scheduler", true)); + scheduler = ThreadPoolFactory.createScheduledExecutor(eventMeshTCPConfiguration.eventMeshTcpGlobalScheduler, + new EventMeshThreadFactoryImpl("eventMesh-tcp-scheduler", true)); - taskHandleExecutorService = ThreadPoolFactory.createThreadPoolExecutor(eventMeshTCPConfiguration.eventMeshTcpTaskHandleExecutorPoolSize, eventMeshTCPConfiguration.eventMeshTcpTaskHandleExecutorPoolSize, new LinkedBlockingQueue(10000), new EventMeshThreadFactoryImpl("eventMesh-tcp-task-handle", true)); + taskHandleExecutorService = ThreadPoolFactory.createThreadPoolExecutor( + eventMeshTCPConfiguration.eventMeshTcpTaskHandleExecutorPoolSize, + eventMeshTCPConfiguration.eventMeshTcpTaskHandleExecutorPoolSize, + new LinkedBlockingQueue(10000), + new EventMeshThreadFactoryImpl("eventMesh-tcp-task-handle", true)); - broadcastMsgDownstreamExecutorService = ThreadPoolFactory.createThreadPoolExecutor(eventMeshTCPConfiguration.eventMeshTcpMsgDownStreamExecutorPoolSize, eventMeshTCPConfiguration.eventMeshTcpMsgDownStreamExecutorPoolSize, new LinkedBlockingQueue(10000), new EventMeshThreadFactoryImpl("eventMesh-tcp-msg-downstream", true)); + broadcastMsgDownstreamExecutorService = ThreadPoolFactory.createThreadPoolExecutor( + eventMeshTCPConfiguration.eventMeshTcpMsgDownStreamExecutorPoolSize, + eventMeshTCPConfiguration.eventMeshTcpMsgDownStreamExecutorPoolSize, + new LinkedBlockingQueue(10000), + new EventMeshThreadFactoryImpl("eventMesh-tcp-msg-downstream", true)); } private void shutdownThreadPool() { @@ -331,7 +359,8 @@ private void shutdownThreadPool() { } private GlobalTrafficShapingHandler newGTSHandler() { - GlobalTrafficShapingHandler handler = new GlobalTrafficShapingHandler(scheduler, 0, eventMeshTCPConfiguration.getGtc().getReadLimit()) { + GlobalTrafficShapingHandler handler = new GlobalTrafficShapingHandler(scheduler, 0, + eventMeshTCPConfiguration.getGtc().getReadLimit()) { @Override protected long calculateSize(Object msg) { return 1; @@ -342,7 +371,8 @@ protected long calculateSize(Object msg) { } private ChannelTrafficShapingHandler newCTSHandler() { - ChannelTrafficShapingHandler handler = new ChannelTrafficShapingHandler(0, eventMeshTCPConfiguration.getCtc().getReadLimit()) { + ChannelTrafficShapingHandler handler = new ChannelTrafficShapingHandler(0, + eventMeshTCPConfiguration.getCtc().getReadLimit()) { @Override protected long calculateSize(Object msg) { return 1; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/SSLContextFactory.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/SSLContextFactory.java index 529ee37ec9..bae2d55cba 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/SSLContextFactory.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/boot/SSLContextFactory.java @@ -16,18 +16,22 @@ * specific language governing permissions and limitations * under the License. */ + package org.apache.eventmesh.runtime.boot; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; + +import org.apache.commons.lang3.StringUtils; + import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; import java.security.KeyStore; + import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; -import org.apache.commons.lang3.StringUtils; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java index 05511b0368..8e37a4528d 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshHTTPConfiguration.java @@ -17,11 +17,13 @@ package org.apache.eventmesh.runtime.configuration; -import com.google.common.base.Preconditions; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.config.CommonConfiguration; import org.apache.eventmesh.common.config.ConfigurationWrapper; +import org.apache.commons.lang3.StringUtils; + +import com.google.common.base.Preconditions; + public class EventMeshHTTPConfiguration extends CommonConfiguration { public int httpServerPort = 10105; @@ -78,7 +80,8 @@ public void init() { if (configurationWrapper != null) { String httpServerPortStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_SERVER_HTTP_PORT); - Preconditions.checkState(StringUtils.isNotEmpty(httpServerPortStr) && StringUtils.isNumeric(httpServerPortStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_SERVER_HTTP_PORT)); + Preconditions.checkState(StringUtils.isNotEmpty(httpServerPortStr) + && StringUtils.isNumeric(httpServerPortStr), String.format("%s error", ConfKeys.KEYS_EVENTMESH_SERVER_HTTP_PORT)); httpServerPort = Integer.valueOf(StringUtils.deleteWhitespace(httpServerPortStr)); String eventMeshServerBatchMsgThreadNumStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_BATCHMSG_THREAD_NUM); @@ -87,7 +90,8 @@ public void init() { } String eventMeshServerBatchMsgReqNumPerSecondStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_BATCHMSG_REQ_NUM_PER_SECOND); - if (StringUtils.isNotEmpty(eventMeshServerBatchMsgReqNumPerSecondStr) && StringUtils.isNumeric(eventMeshServerBatchMsgReqNumPerSecondStr)) { + if (StringUtils.isNotEmpty(eventMeshServerBatchMsgReqNumPerSecondStr) + && StringUtils.isNumeric(eventMeshServerBatchMsgReqNumPerSecondStr)) { eventMeshBatchMsgRequestNumPerSecond = Integer.valueOf(eventMeshServerBatchMsgReqNumPerSecondStr); } @@ -96,83 +100,115 @@ public void init() { eventMeshServerBatchMsgBatchEnabled = Boolean.valueOf(eventMeshServerBatchMsgBatchEnableStr); } - String eventMeshServerAsyncAccumulationThresholdStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ASYNC_ACCUMULATION_THRESHOLD); - if (StringUtils.isNotEmpty(eventMeshServerAsyncAccumulationThresholdStr) && StringUtils.isNumeric(eventMeshServerAsyncAccumulationThresholdStr)) { - eventMeshServerAsyncAccumulationThreshold = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerAsyncAccumulationThresholdStr)); + String eventMeshServerAsyncAccumulationThresholdStr = + configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ASYNC_ACCUMULATION_THRESHOLD); + if (StringUtils.isNotEmpty(eventMeshServerAsyncAccumulationThresholdStr) + && StringUtils.isNumeric(eventMeshServerAsyncAccumulationThresholdStr)) { + eventMeshServerAsyncAccumulationThreshold = + Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerAsyncAccumulationThresholdStr)); } - String eventMeshServerSendMsgThreadNumStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_SENDMSG_THREAD_NUM); - if (StringUtils.isNotEmpty(eventMeshServerSendMsgThreadNumStr) && StringUtils.isNumeric(eventMeshServerSendMsgThreadNumStr)) { + String eventMeshServerSendMsgThreadNumStr = + configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_SENDMSG_THREAD_NUM); + if (StringUtils.isNotEmpty(eventMeshServerSendMsgThreadNumStr) + && StringUtils.isNumeric(eventMeshServerSendMsgThreadNumStr)) { eventMeshServerSendMsgThreadNum = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerSendMsgThreadNumStr)); } - String eventMeshServerReplyMsgThreadNumStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_REPLYMSG_THREAD_NUM); - if (StringUtils.isNotEmpty(eventMeshServerReplyMsgThreadNumStr) && StringUtils.isNumeric(eventMeshServerReplyMsgThreadNumStr)) { + String eventMeshServerReplyMsgThreadNumStr = + configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_REPLYMSG_THREAD_NUM); + if (StringUtils.isNotEmpty(eventMeshServerReplyMsgThreadNumStr) + && StringUtils.isNumeric(eventMeshServerReplyMsgThreadNumStr)) { eventMeshServerReplyMsgThreadNum = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerReplyMsgThreadNumStr)); } - String eventMeshServerPushMsgThreadNumStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_PUSHMSG_THREAD_NUM); - if (StringUtils.isNotEmpty(eventMeshServerPushMsgThreadNumStr) && StringUtils.isNumeric(eventMeshServerPushMsgThreadNumStr)) { + String eventMeshServerPushMsgThreadNumStr = + configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_PUSHMSG_THREAD_NUM); + if (StringUtils.isNotEmpty(eventMeshServerPushMsgThreadNumStr) + && StringUtils.isNumeric(eventMeshServerPushMsgThreadNumStr)) { eventMeshServerPushMsgThreadNum = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerPushMsgThreadNumStr)); } - String eventMeshServerRegistryThreadNumStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_REGISTRY_THREAD_NUM); - if (StringUtils.isNotEmpty(eventMeshServerRegistryThreadNumStr) && StringUtils.isNumeric(eventMeshServerRegistryThreadNumStr)) { + String eventMeshServerRegistryThreadNumStr = + configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_REGISTRY_THREAD_NUM); + if (StringUtils.isNotEmpty(eventMeshServerRegistryThreadNumStr) + && StringUtils.isNumeric(eventMeshServerRegistryThreadNumStr)) { eventMeshServerRegistryThreadNum = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerRegistryThreadNumStr)); } - String eventMeshServerClientManageThreadNumStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_CLIENTMANAGE_THREAD_NUM); - if (StringUtils.isNotEmpty(eventMeshServerClientManageThreadNumStr) && StringUtils.isNumeric(eventMeshServerClientManageThreadNumStr)) { + String eventMeshServerClientManageThreadNumStr = + configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_CLIENTMANAGE_THREAD_NUM); + if (StringUtils.isNotEmpty(eventMeshServerClientManageThreadNumStr) + && StringUtils.isNumeric(eventMeshServerClientManageThreadNumStr)) { eventMeshServerClientManageThreadNum = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerClientManageThreadNumStr)); } - String eventMeshServerPullRegistryIntervalStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_PULL_REGISTRY_INTERVAL); - if (StringUtils.isNotEmpty(eventMeshServerPullRegistryIntervalStr) && StringUtils.isNumeric(eventMeshServerPullRegistryIntervalStr)) { + String eventMeshServerPullRegistryIntervalStr = + configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_PULL_REGISTRY_INTERVAL); + if (StringUtils.isNotEmpty(eventMeshServerPullRegistryIntervalStr) + && StringUtils.isNumeric(eventMeshServerPullRegistryIntervalStr)) { eventMeshServerPullRegistryInterval = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerPullRegistryIntervalStr)); } - String eventMeshServerAdminThreadNumStr = configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ADMIN_THREAD_NUM); - if (StringUtils.isNotEmpty(eventMeshServerAdminThreadNumStr) && StringUtils.isNumeric(eventMeshServerAdminThreadNumStr)) { + String eventMeshServerAdminThreadNumStr = + configurationWrapper.getProp(ConfKeys.KEYS_EVENTMESH_ADMIN_THREAD_NUM); + if (StringUtils.isNotEmpty(eventMeshServerAdminThreadNumStr) + && StringUtils.isNumeric(eventMeshServerAdminThreadNumStr)) { eventMeshServerAdminThreadNum = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerAdminThreadNumStr)); } - String eventMeshServerRetryBlockQSizeStr = configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_RETRY_BLOCKQ_SIZE); - if (StringUtils.isNotEmpty(eventMeshServerRetryBlockQSizeStr) && StringUtils.isNumeric(eventMeshServerRetryBlockQSizeStr)) { + String eventMeshServerRetryBlockQSizeStr = + configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_RETRY_BLOCKQ_SIZE); + if (StringUtils.isNotEmpty(eventMeshServerRetryBlockQSizeStr) + && StringUtils.isNumeric(eventMeshServerRetryBlockQSizeStr)) { eventMeshServerRetryBlockQSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerRetryBlockQSizeStr)); } - String eventMeshServerBatchBlockQSizeStr = configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_BATCHMSG_BLOCKQ_SIZE); - if (StringUtils.isNotEmpty(eventMeshServerBatchBlockQSizeStr) && StringUtils.isNumeric(eventMeshServerBatchBlockQSizeStr)) { + String eventMeshServerBatchBlockQSizeStr = + configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_BATCHMSG_BLOCKQ_SIZE); + if (StringUtils.isNotEmpty(eventMeshServerBatchBlockQSizeStr) + && StringUtils.isNumeric(eventMeshServerBatchBlockQSizeStr)) { eventMeshServerBatchBlockQSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerBatchBlockQSizeStr)); } - String eventMeshServerSendMsgBlockQSizeStr = configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_SENDMSG_BLOCKQ_SIZE); - if (StringUtils.isNotEmpty(eventMeshServerSendMsgBlockQSizeStr) && StringUtils.isNumeric(eventMeshServerSendMsgBlockQSizeStr)) { + String eventMeshServerSendMsgBlockQSizeStr = + configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_SENDMSG_BLOCKQ_SIZE); + if (StringUtils.isNotEmpty(eventMeshServerSendMsgBlockQSizeStr) + && StringUtils.isNumeric(eventMeshServerSendMsgBlockQSizeStr)) { eventMeshServerSendMsgBlockQSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerSendMsgBlockQSizeStr)); } - String eventMeshServerPushMsgBlockQSizeStr = configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_PUSHMSG_BLOCKQ_SIZE); - if (StringUtils.isNotEmpty(eventMeshServerPushMsgBlockQSizeStr) && StringUtils.isNumeric(eventMeshServerPushMsgBlockQSizeStr)) { + String eventMeshServerPushMsgBlockQSizeStr = + configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_PUSHMSG_BLOCKQ_SIZE); + if (StringUtils.isNotEmpty(eventMeshServerPushMsgBlockQSizeStr) + && StringUtils.isNumeric(eventMeshServerPushMsgBlockQSizeStr)) { eventMeshServerPushMsgBlockQSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerPushMsgBlockQSizeStr)); } - String eventMeshServerClientManageBlockQSizeStr = configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_CLIENTM_BLOCKQ_SIZE); - if (StringUtils.isNotEmpty(eventMeshServerClientManageBlockQSizeStr) && StringUtils.isNumeric(eventMeshServerClientManageBlockQSizeStr)) { + String eventMeshServerClientManageBlockQSizeStr = + configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_CLIENTM_BLOCKQ_SIZE); + if (StringUtils.isNotEmpty(eventMeshServerClientManageBlockQSizeStr) + && StringUtils.isNumeric(eventMeshServerClientManageBlockQSizeStr)) { eventMeshServerClientManageBlockQSize = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerClientManageBlockQSizeStr)); } - String eventMeshServerBusyCheckIntervalStr = configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_BUSY_CHECK_INTERVAL); - if (StringUtils.isNotEmpty(eventMeshServerBusyCheckIntervalStr) && StringUtils.isNumeric(eventMeshServerBusyCheckIntervalStr)) { + String eventMeshServerBusyCheckIntervalStr = + configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_BUSY_CHECK_INTERVAL); + if (StringUtils.isNotEmpty(eventMeshServerBusyCheckIntervalStr) + && StringUtils.isNumeric(eventMeshServerBusyCheckIntervalStr)) { eventMeshServerBusyCheckInterval = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerBusyCheckIntervalStr)); } - String eventMeshServerConsumerEnabledStr = configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_CONSUMER_ENABLED); + String eventMeshServerConsumerEnabledStr = + configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_CONSUMER_ENABLED); if (StringUtils.isNotEmpty(eventMeshServerConsumerEnabledStr)) { eventMeshServerConsumerEnabled = Boolean.valueOf(StringUtils.deleteWhitespace(eventMeshServerConsumerEnabledStr)); } - String eventMeshServerRetryThreadNumStr = configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_RETRY_THREAD_NUM); - if (StringUtils.isNotEmpty(eventMeshServerRetryThreadNumStr) && StringUtils.isNumeric(eventMeshServerRetryThreadNumStr)) { + String eventMeshServerRetryThreadNumStr = + configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_RETRY_THREAD_NUM); + if (StringUtils.isNotEmpty(eventMeshServerRetryThreadNumStr) + && StringUtils.isNumeric(eventMeshServerRetryThreadNumStr)) { eventMeshServerRetryThreadNum = Integer.valueOf(StringUtils.deleteWhitespace(eventMeshServerRetryThreadNumStr)); } @@ -181,8 +217,10 @@ public void init() { eventMeshServerUseTls = Boolean.valueOf(StringUtils.deleteWhitespace(eventMeshServerUseTlsStr)); } - String eventMeshHttpMsgReqNumPerSecondStr = configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_SERVER_MSG_REQ_NUM_PER_SECOND); - if (StringUtils.isNotEmpty(eventMeshHttpMsgReqNumPerSecondStr) && StringUtils.isNumeric(eventMeshHttpMsgReqNumPerSecondStr)) { + String eventMeshHttpMsgReqNumPerSecondStr = + configurationWrapper.getProp(ConfKeys.KEY_EVENTMESH_SERVER_MSG_REQ_NUM_PER_SECOND); + if (StringUtils.isNotEmpty(eventMeshHttpMsgReqNumPerSecondStr) + && StringUtils.isNumeric(eventMeshHttpMsgReqNumPerSecondStr)) { eventMeshHttpMsgReqNumPerSecond = Integer.valueOf(eventMeshHttpMsgReqNumPerSecondStr); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java index fee44b465a..0ab59cb918 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/configuration/EventMeshTCPConfiguration.java @@ -88,48 +88,72 @@ public void init() { super.init(); eventMeshTcpServerPort = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_TCP_PORT, eventMeshTcpServerPort); - eventMeshTcpIdleReadSeconds = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_READER_IDLE_SECONDS, eventMeshTcpIdleReadSeconds); + eventMeshTcpIdleReadSeconds = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_READER_IDLE_SECONDS, + eventMeshTcpIdleReadSeconds); - eventMeshTcpIdleWriteSeconds = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_WRITER_IDLE_SECONDS, eventMeshTcpIdleWriteSeconds); + eventMeshTcpIdleWriteSeconds = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_WRITER_IDLE_SECONDS, + eventMeshTcpIdleWriteSeconds); - eventMeshTcpIdleAllSeconds = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_ALL_IDLE_SECONDS, eventMeshTcpIdleAllSeconds); + eventMeshTcpIdleAllSeconds = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_ALL_IDLE_SECONDS, + eventMeshTcpIdleAllSeconds); - eventMeshTcpMsgReqnumPerSecond = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_MSG_REQ_NUM_PER_SECONDS, eventMeshTcpMsgReqnumPerSecond); + eventMeshTcpMsgReqnumPerSecond = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_MSG_REQ_NUM_PER_SECONDS, + eventMeshTcpMsgReqnumPerSecond); - eventMeshTcpClientMaxNum = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_CLIENT_MAX_NUM, eventMeshTcpClientMaxNum); + eventMeshTcpClientMaxNum = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_CLIENT_MAX_NUM, + eventMeshTcpClientMaxNum); - eventMeshTcpServerEnabled = configurationWrapper.getBoolProp(ConfKeys.KEYS_EVENTMESH_TCP_SERVER_ENABLED, eventMeshTcpServerEnabled); + eventMeshTcpServerEnabled = configurationWrapper.getBoolProp(ConfKeys.KEYS_EVENTMESH_TCP_SERVER_ENABLED, + eventMeshTcpServerEnabled); - eventMeshTcpGlobalScheduler = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_GLOBAL_SCHEDULER, eventMeshTcpGlobalScheduler); + eventMeshTcpGlobalScheduler = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_GLOBAL_SCHEDULER, + eventMeshTcpGlobalScheduler); - eventMeshTcpTaskHandleExecutorPoolSize = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_TCP_TASK_HANDLE_POOL_SIZE, eventMeshTcpTaskHandleExecutorPoolSize); + eventMeshTcpTaskHandleExecutorPoolSize = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_TCP_TASK_HANDLE_POOL_SIZE, eventMeshTcpTaskHandleExecutorPoolSize); - eventMeshTcpMsgDownStreamExecutorPoolSize = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_TCP_MSG_DOWNSTREAM_POOL_SIZE, eventMeshTcpMsgDownStreamExecutorPoolSize); + eventMeshTcpMsgDownStreamExecutorPoolSize = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_TCP_MSG_DOWNSTREAM_POOL_SIZE, eventMeshTcpMsgDownStreamExecutorPoolSize); - eventMeshTcpSessionExpiredInMills = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_SESSION_EXPIRED_TIME, eventMeshTcpSessionExpiredInMills); + eventMeshTcpSessionExpiredInMills = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_SESSION_EXPIRED_TIME, eventMeshTcpSessionExpiredInMills); - eventMeshTcpSessionUpstreamBufferSize = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_SESSION_UPSTREAM_BUFFER_SIZE, eventMeshTcpSessionUpstreamBufferSize); + eventMeshTcpSessionUpstreamBufferSize = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_SESSION_UPSTREAM_BUFFER_SIZE, eventMeshTcpSessionUpstreamBufferSize); //========================================eventMesh retry config=============================================// - eventMeshTcpMsgAsyncRetryTimes = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_ASYNC_PUSH_RETRY_TIMES, eventMeshTcpMsgAsyncRetryTimes); - eventMeshTcpMsgSyncRetryTimes = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_SYNC_PUSH_RETRY_TIMES, eventMeshTcpMsgSyncRetryTimes); + eventMeshTcpMsgAsyncRetryTimes = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_ASYNC_PUSH_RETRY_TIMES, eventMeshTcpMsgAsyncRetryTimes); - eventMeshTcpMsgRetryAsyncDelayInMills = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_ASYNC_PUSH_RETRY_DELAY, eventMeshTcpMsgRetryAsyncDelayInMills); - eventMeshTcpMsgRetrySyncDelayInMills = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_SYNC_PUSH_RETRY_DELAY, eventMeshTcpMsgRetrySyncDelayInMills); + eventMeshTcpMsgSyncRetryTimes = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_SYNC_PUSH_RETRY_TIMES, eventMeshTcpMsgSyncRetryTimes); - eventMeshTcpMsgRetryQueueSize = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_PUSH_RETRY_QUEUE_SIZE, eventMeshTcpMsgRetryQueueSize); + eventMeshTcpMsgRetryAsyncDelayInMills = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_ASYNC_PUSH_RETRY_DELAY, eventMeshTcpMsgRetryAsyncDelayInMills); - eventMeshTcpRebalanceIntervalInMills = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_TCP_REBALANCE_INTERVAL, eventMeshTcpRebalanceIntervalInMills); + eventMeshTcpMsgRetrySyncDelayInMills = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_SYNC_PUSH_RETRY_DELAY, eventMeshTcpMsgRetrySyncDelayInMills); - eventMeshServerAdminPort = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_ADMIN_HTTP_PORT, eventMeshServerAdminPort); + eventMeshTcpMsgRetryQueueSize = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_RETRY_PUSH_RETRY_QUEUE_SIZE, eventMeshTcpMsgRetryQueueSize); - eventMeshTcpSendBackEnabled = configurationWrapper.getBoolProp(ConfKeys.KEYS_EVENTMESH_TCP_SEND_BACK_ENABLED, eventMeshTcpSendBackEnabled); + eventMeshTcpRebalanceIntervalInMills = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_TCP_REBALANCE_INTERVAL, eventMeshTcpRebalanceIntervalInMills); - eventMeshTcpPushFailIsolateTimeInMills = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_PUSH_FAIL_ISOLATE_TIME, eventMeshTcpPushFailIsolateTimeInMills); + eventMeshServerAdminPort = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_ADMIN_HTTP_PORT, eventMeshServerAdminPort); - gracefulShutdownSleepIntervalInMills = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_GRACEFUL_SHUTDOWN_SLEEP_TIME, gracefulShutdownSleepIntervalInMills); + eventMeshTcpSendBackEnabled = configurationWrapper.getBoolProp( + ConfKeys.KEYS_EVENTMESH_TCP_SEND_BACK_ENABLED, eventMeshTcpSendBackEnabled); - sleepIntervalInRebalanceRedirectMills = configurationWrapper.getIntProp(ConfKeys.KEYS_EVENTMESH_SERVER_REBALANCE_REDIRECT_SLEEP_TIME, sleepIntervalInRebalanceRedirectMills); + eventMeshTcpPushFailIsolateTimeInMills = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_PUSH_FAIL_ISOLATE_TIME, eventMeshTcpPushFailIsolateTimeInMills); + + gracefulShutdownSleepIntervalInMills = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_GRACEFUL_SHUTDOWN_SLEEP_TIME, gracefulShutdownSleepIntervalInMills); + + sleepIntervalInRebalanceRedirectMills = configurationWrapper.getIntProp( + ConfKeys.KEYS_EVENTMESH_SERVER_REBALANCE_REDIRECT_SLEEP_TIME, sleepIntervalInRebalanceRedirectMills); } @@ -220,11 +244,16 @@ public void setMaxTime(long maxTime) { @Override public String toString() { - return "TrafficShapingConfig{" + - "writeLimit=" + writeLimit + - ", readLimit=" + readLimit + - ", checkInterval=" + checkInterval + - ", maxTime=" + maxTime + + return "TrafficShapingConfig{" + + + "writeLimit=" + writeLimit + + + ", readLimit=" + readLimit + + + ", checkInterval=" + checkInterval + + + ", maxTime=" + maxTime + + '}'; } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorResource.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorResource.java index 38cf8e99cb..f47352eaed 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorResource.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/connector/ConnectorResource.java @@ -14,10 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.connector; import org.apache.eventmesh.api.connector.ConnectorResourceService; import org.apache.eventmesh.spi.EventMeshExtensionFactory; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -26,7 +28,7 @@ public class ConnectorResource { private static final Logger logger = LoggerFactory.getLogger(ConnectorResource.class); private static ConnectorResourceService connectorResourceService; - public void init(String connectorResourcePluginType) throws Exception{ + public void init(String connectorResourcePluginType) throws Exception { connectorResourceService = EventMeshExtensionFactory.getExtension(ConnectorResourceService.class, connectorResourcePluginType); if (connectorResourceService == null) { logger.error("can't load the connectorResourceService plugin, please check."); @@ -35,7 +37,7 @@ public void init(String connectorResourcePluginType) throws Exception{ connectorResourceService.init(); } - public void release()throws Exception{ + public void release() throws Exception { connectorResourceService.release(); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java index bd702989f3..3f85225935 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/constants/EventMeshConstants.java @@ -118,5 +118,4 @@ public class EventMeshConstants { public static final String STORE_TIME = "store" + Constants.MESSAGE_PROP_SEPARATOR + "time"; - } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupConf.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupConf.java index 9eda09656a..436fadf773 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupConf.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupConf.java @@ -50,10 +50,16 @@ public void setConsumerGroupTopicConf(Map consum @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } ConsumerGroupConf that = (ConsumerGroupConf) o; - return consumerGroup.equals(that.consumerGroup) && + + return consumerGroup.equals(that.consumerGroup) + && Objects.equals(consumerGroupTopicConf, that.consumerGroupTopicConf); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupTopicConf.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupTopicConf.java index a894b2e85b..670e9cac3b 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupTopicConf.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ConsumerGroupTopicConf.java @@ -17,18 +17,19 @@ package org.apache.eventmesh.runtime.core.consumergroup; +import org.apache.eventmesh.common.protocol.SubscriptionItem; + import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Set; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; - -import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + public class ConsumerGroupTopicConf { public static Logger logger = LoggerFactory.getLogger(ConsumerGroupTopicConf.class); @@ -44,8 +45,9 @@ public class ConsumerGroupTopicConf { /** * PUSH URL + * Map key:IDC value:URL list in IDC */ - private Map /** URL list in IDC */> idcUrls = Maps.newConcurrentMap(); + private Map> idcUrls = Maps.newConcurrentMap(); /** * ALL IDC URLs @@ -54,12 +56,19 @@ public class ConsumerGroupTopicConf { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } ConsumerGroupTopicConf that = (ConsumerGroupTopicConf) o; - return consumerGroup.equals(that.consumerGroup) && - Objects.equals(topic, that.topic) && - Objects.equals(subscriptionItem, that.subscriptionItem) && + return consumerGroup.equals(that.consumerGroup) + && + Objects.equals(topic, that.topic) + && + Objects.equals(subscriptionItem, that.subscriptionItem) + && Objects.equals(idcUrls, that.idcUrls); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ProducerGroupConf.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ProducerGroupConf.java index 8518850cab..970de8c688 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ProducerGroupConf.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/consumergroup/ProducerGroupConf.java @@ -40,8 +40,12 @@ public String toString() { @Override public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } ProducerGroupConf that = (ProducerGroupConf) o; return groupName == that.groupName; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQConsumerWrapper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQConsumerWrapper.java index 5d03e81a49..edce54a88f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQConsumerWrapper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQConsumerWrapper.java @@ -17,20 +17,22 @@ package org.apache.eventmesh.runtime.core.plugin; -import java.util.List; -import java.util.Properties; - -import io.cloudevents.CloudEvent; import org.apache.eventmesh.api.AbstractContext; import org.apache.eventmesh.api.EventListener; import org.apache.eventmesh.api.consumer.Consumer; import org.apache.eventmesh.api.factory.ConnectorPluginFactory; + +import java.util.List; +import java.util.Properties; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; + public class MQConsumerWrapper extends MQWrapper { - public Logger logger = LoggerFactory.getLogger(this.getClass()); + public final Logger logger = LoggerFactory.getLogger(this.getClass()); protected Consumer meshMQPushConsumer; @@ -67,9 +69,9 @@ public synchronized void shutdown() throws Exception { started.compareAndSet(false, true); } -// public void registerMessageListener(MessageListenerConcurrently messageListenerConcurrently) { -// meshMQPushConsumer.registerMessageListener(messageListenerConcurrently); -// } + //public void registerMessageListener(MessageListenerConcurrently messageListenerConcurrently) { + // meshMQPushConsumer.registerMessageListener(messageListenerConcurrently); + //} public void updateOffset(List events, AbstractContext eventMeshConsumeConcurrentlyContext) { meshMQPushConsumer.updateOffset(events, eventMeshConsumeConcurrentlyContext); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQProducerWrapper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQProducerWrapper.java index f781071126..73411a6fc2 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQProducerWrapper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQProducerWrapper.java @@ -17,12 +17,13 @@ package org.apache.eventmesh.runtime.core.plugin; -import java.util.Properties; - import org.apache.eventmesh.api.RequestReplyCallback; import org.apache.eventmesh.api.SendCallback; import org.apache.eventmesh.api.factory.ConnectorPluginFactory; import org.apache.eventmesh.api.producer.Producer; + +import java.util.Properties; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQWrapper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQWrapper.java index f8ae78c112..c77d18e787 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQWrapper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/plugin/MQWrapper.java @@ -16,12 +16,14 @@ * specific language governing permissions and limitations * under the License. */ + package org.apache.eventmesh.runtime.core.plugin; -import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.commons.lang3.StringUtils; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; + +import java.util.concurrent.atomic.AtomicBoolean; public abstract class MQWrapper { @@ -31,7 +33,8 @@ public abstract class MQWrapper { public static String CURRENT_EVENT_STORE = EVENT_STORE_DEFIBUS; - public static final String EVENT_STORE_CONF = System.getProperty(EventMeshConstants.EVENT_STORE_PROPERTIES, System.getenv(EventMeshConstants.EVENT_STORE_ENV)); + public static final String EVENT_STORE_CONF = System.getProperty(EventMeshConstants.EVENT_STORE_PROPERTIES, + System.getenv(EventMeshConstants.EVENT_STORE_ENV)); static { if (StringUtils.isNotBlank(EVENT_STORE_CONF)) { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/async/CompleteHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/async/CompleteHandler.java index 6faa01f98d..49eeaaf585 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/async/CompleteHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/async/CompleteHandler.java @@ -17,6 +17,11 @@ package org.apache.eventmesh.runtime.core.protocol.http.async; +/** + * CompleteHandler + * + * @param + */ public interface CompleteHandler { void onResponse(T t); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerGroupManager.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerGroupManager.java index 93377ac2ea..7d4ddab9bd 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerGroupManager.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerGroupManager.java @@ -17,15 +17,16 @@ package org.apache.eventmesh.runtime.core.protocol.http.consumer; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupConf; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupTopicConf; +import org.apache.commons.lang3.StringUtils; + +import java.util.Map; +import java.util.Set; +import java.util.concurrent.atomic.AtomicBoolean; + public class ConsumerGroupManager { protected AtomicBoolean started = new AtomicBoolean(Boolean.FALSE); @@ -86,9 +87,9 @@ public ConsumerGroupConf getConsumerGroupConfig() { } public void unsubscribe(String consumerGroup) throws Exception { - if(StringUtils.equals(consumerGroupConfig.getConsumerGroup(), consumerGroup)){ + if (StringUtils.equals(consumerGroupConfig.getConsumerGroup(), consumerGroup)) { Set topics = consumerGroupConfig.getConsumerGroupTopicConf().keySet(); - for (String topic : topics){ + for (String topic : topics) { ConsumerGroupTopicConf consumerGroupTopicConf = consumerGroupConfig.getConsumerGroupTopicConf().get(topic); eventMeshConsumer.unsubscribe(topic, consumerGroupTopicConf.getSubscriptionItem().getMode()); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerManager.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerManager.java index 4c23663832..fc89fad6ca 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerManager.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/ConsumerManager.java @@ -53,14 +53,14 @@ public class ConsumerManager { * consumerGroup to ConsumerGroupManager. */ private ConcurrentHashMap consumerTable = - new ConcurrentHashMap<>(); + new ConcurrentHashMap<>(); private static final int DEFAULT_UPDATE_TIME = 3 * 30 * 1000; public Logger logger = LoggerFactory.getLogger(this.getClass()); private ScheduledExecutorService scheduledExecutorService = - Executors.newSingleThreadScheduledExecutor(); + Executors.newSingleThreadScheduledExecutor(); public ConsumerManager(EventMeshHTTPServer eventMeshHTTPServer) { this.eventMeshHTTPServer = eventMeshHTTPServer; @@ -79,7 +79,7 @@ public void run() { logger.info("clientInfo check start....."); synchronized (eventMeshHTTPServer.localClientInfoMapping) { Map> clientInfoMap = - eventMeshHTTPServer.localClientInfoMapping; + eventMeshHTTPServer.localClientInfoMapping; if (clientInfoMap.size() > 0) { for (String key : clientInfoMap.keySet()) { String consumerGroup = key.split("@")[0]; @@ -91,10 +91,10 @@ public void run() { Client client = clientIterator.next(); //The time difference is greater than 3 heartbeat cycles if (System.currentTimeMillis() - client.lastUpTime.getTime() - > DEFAULT_UPDATE_TIME) { + > DEFAULT_UPDATE_TIME) { logger.warn( - "client {} lastUpdate time {} over three heartbeat cycles", - JsonUtils.serialize(client), client.lastUpTime); + "client {} lastUpdate time {} over three heartbeat cycles", + JsonUtils.serialize(client), client.lastUpTime); clientIterator.remove(); isChange = true; } @@ -103,14 +103,14 @@ public void run() { if (clientList.size() > 0) { //change url logger.info("consumerGroup {} client info changing", - consumerGroup); + consumerGroup); Map> idcUrls = new HashMap<>(); Set clientUrls = new HashSet<>(); for (Client client : clientList) { clientUrls.add(client.url); if (idcUrls.containsKey(client.idc)) { idcUrls.get(client.idc) - .add(StringUtils.deleteWhitespace(client.url)); + .add(StringUtils.deleteWhitespace(client.url)); } else { List urls = new ArrayList<>(); urls.add(client.url); @@ -119,18 +119,18 @@ public void run() { } synchronized (eventMeshHTTPServer.localConsumerGroupMapping) { ConsumerGroupConf consumerGroupConf = - eventMeshHTTPServer.localConsumerGroupMapping - .get(consumerGroup); + eventMeshHTTPServer.localConsumerGroupMapping + .get(consumerGroup); Map map = - consumerGroupConf.getConsumerGroupTopicConf(); + consumerGroupConf.getConsumerGroupTopicConf(); for (String topicKey : map.keySet()) { if (StringUtils.equals(topic, topicKey)) { ConsumerGroupTopicConf latestTopicConf = - new ConsumerGroupTopicConf(); + new ConsumerGroupTopicConf(); latestTopicConf.setConsumerGroup(consumerGroup); latestTopicConf.setTopic(topic); latestTopicConf.setSubscriptionItem( - map.get(topicKey).getSubscriptionItem()); + map.get(topicKey).getSubscriptionItem()); latestTopicConf.setUrls(clientUrls); latestTopicConf.setIdcUrls(idcUrls); @@ -139,11 +139,11 @@ public void run() { } } eventMeshHTTPServer.localConsumerGroupMapping - .put(consumerGroup, consumerGroupConf); + .put(consumerGroup, consumerGroupConf); logger.info( - "consumerGroup {} client info changed, " - + "consumerGroupConf {}", consumerGroup, - JsonUtils.serialize(consumerGroupConf)); + "consumerGroup {} client info changed, " + + "consumerGroupConf {}", consumerGroup, + JsonUtils.serialize(consumerGroupConf)); try { notifyConsumerManager(consumerGroup, consumerGroupConf); } catch (Exception e) { @@ -153,7 +153,7 @@ public void run() { } else { logger.info("consumerGroup {} client info removed", - consumerGroup); + consumerGroup); //remove try { notifyConsumerManager(consumerGroup, null); @@ -162,7 +162,7 @@ public void run() { } eventMeshHTTPServer.localConsumerGroupMapping.keySet() - .removeIf(s -> StringUtils.equals(consumerGroup, s)); + .removeIf(s -> StringUtils.equals(consumerGroup, s)); } } @@ -178,9 +178,9 @@ public void run() { */ public void notifyConsumerManager(String consumerGroup, ConsumerGroupConf latestConsumerGroupConfig) - throws Exception { + throws Exception { ConsumerGroupManager cgm = - eventMeshHTTPServer.getConsumerManager().getConsumer(consumerGroup); + eventMeshHTTPServer.getConsumerManager().getConsumer(consumerGroup); if (latestConsumerGroupConfig == null) { ConsumerGroupStateEvent notification = new ConsumerGroupStateEvent(); notification.action = ConsumerGroupStateEvent.ConsumerGroupStateAction.DELETE; @@ -234,7 +234,7 @@ public boolean contains(String consumerGroup) { public synchronized void addConsumer(String consumerGroup, ConsumerGroupConf consumerGroupConfig) throws Exception { ConsumerGroupManager cgm = - new ConsumerGroupManager(eventMeshHTTPServer, consumerGroupConfig); + new ConsumerGroupManager(eventMeshHTTPServer, consumerGroupConfig); cgm.init(); cgm.start(); consumerTable.put(consumerGroup, cgm); @@ -245,7 +245,7 @@ public synchronized void addConsumer(String consumerGroup, */ public synchronized void restartConsumer(String consumerGroup, ConsumerGroupConf consumerGroupConfig) - throws Exception { + throws Exception { if (consumerTable.containsKey(consumerGroup)) { ConsumerGroupManager cgm = consumerTable.get(consumerGroup); cgm.refresh(consumerGroupConfig); @@ -270,7 +270,7 @@ public synchronized void delConsumer(String consumerGroup) throws Exception { if (consumerTable.containsKey(consumerGroup)) { ConsumerGroupManager cgm = consumerTable.remove(consumerGroup); logger.info("start unsubscribe topic with consumer group manager {}", - JsonUtils.serialize(cgm)); + JsonUtils.serialize(cgm)); cgm.unsubscribe(consumerGroup); cgm.shutdown(); } @@ -282,29 +282,29 @@ public void onChange(ConsumerGroupTopicConfChangeEvent event) { try { logger.info("onChange event:{}", event); if (event.action - == ConsumerGroupTopicConfChangeEvent.ConsumerGroupTopicConfChangeAction.NEW) { + == ConsumerGroupTopicConfChangeEvent.ConsumerGroupTopicConfChangeAction.NEW) { ConsumerGroupManager manager = getConsumer(event.consumerGroup); if (Objects.isNull(manager)) { return; } manager.getConsumerGroupConfig().getConsumerGroupTopicConf() - .put(event.topic, event.newTopicConf); + .put(event.topic, event.newTopicConf); return; } if (event.action - == ConsumerGroupTopicConfChangeEvent.ConsumerGroupTopicConfChangeAction.CHANGE) { + == ConsumerGroupTopicConfChangeEvent.ConsumerGroupTopicConfChangeAction.CHANGE) { ConsumerGroupManager manager = getConsumer(event.consumerGroup); if (Objects.isNull(manager)) { return; } manager.getConsumerGroupConfig().getConsumerGroupTopicConf() - .replace(event.topic, event.newTopicConf); + .replace(event.topic, event.newTopicConf); return; } if (event.action - == ConsumerGroupTopicConfChangeEvent.ConsumerGroupTopicConfChangeAction.DELETE) { + == ConsumerGroupTopicConfChangeEvent.ConsumerGroupTopicConfChangeAction.DELETE) { ConsumerGroupManager manager = getConsumer(event.consumerGroup); if (Objects.isNull(manager)) { return; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/EventMeshConsumer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/EventMeshConsumer.java index fd4a704f1d..96398d46fe 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/EventMeshConsumer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/EventMeshConsumer.java @@ -17,15 +17,13 @@ package org.apache.eventmesh.runtime.core.protocol.http.consumer; -import java.util.List; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicBoolean; - -import io.cloudevents.CloudEvent; - -import io.cloudevents.core.builder.CloudEventBuilder; -import org.apache.commons.collections4.MapUtils; -import org.apache.eventmesh.api.*; +import org.apache.eventmesh.api.AbstractContext; +import org.apache.eventmesh.api.AsyncConsumeContext; +import org.apache.eventmesh.api.EventListener; +import org.apache.eventmesh.api.EventMeshAction; +import org.apache.eventmesh.api.EventMeshAsyncConsumeContext; +import org.apache.eventmesh.api.SendCallback; +import org.apache.eventmesh.api.SendResult; import org.apache.eventmesh.api.exception.OnExceptionContext; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.SubscriptionItem; @@ -40,9 +38,19 @@ import org.apache.eventmesh.runtime.core.protocol.http.push.HTTPMessageHandler; import org.apache.eventmesh.runtime.core.protocol.http.push.MessageHandler; import org.apache.eventmesh.runtime.util.EventMeshUtil; + +import org.apache.commons.collections4.MapUtils; + +import java.util.List; +import java.util.Properties; +import java.util.concurrent.atomic.AtomicBoolean; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; + public class EventMeshConsumer { private EventMeshHTTPServer eventMeshHTTPServer; @@ -111,49 +119,56 @@ public void subscribe(String topic, SubscriptionItem subscriptionItem) throws Ex @Override public void consume(CloudEvent event, AsyncConsumeContext context) { String topic = event.getSubject(); -// String topic = message.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION); + //String topic = message.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION); String bizSeqNo = (String) event.getExtension(Constants.PROPERTY_MESSAGE_SEARCH_KEYS); String uniqueId = (String) event.getExtension(Constants.RMB_UNIQ_ID); event = CloudEventBuilder.from(event) .withExtension(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())) .build(); -// message.getUserProperties().put(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())); + //message.getUserProperties().put(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())); if (messageLogger.isDebugEnabled()) { messageLogger.debug("message|mq2eventMesh|topic={}|event={}", topic, event); } else { messageLogger.info("message|mq2eventMesh|topic={}|bizSeqNo={}|uniqueId={}", topic, bizSeqNo, uniqueId); } - ConsumerGroupTopicConf currentTopicConfig = MapUtils.getObject(consumerGroupConf.getConsumerGroupTopicConf(), topic, null); - EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = (EventMeshAsyncConsumeContext)context; + ConsumerGroupTopicConf currentTopicConfig = MapUtils.getObject(consumerGroupConf.getConsumerGroupTopicConf(), + topic, null); + EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = (EventMeshAsyncConsumeContext) context; if (currentTopicConfig == null) { logger.error("no topicConfig found, consumerGroup:{} topic:{}", consumerGroupConf.getConsumerGroup(), topic); try { sendMessageBack(event, uniqueId, bizSeqNo); -// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); -// context.ack(); + //context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, + // EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + //context.ack(); eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); return; } catch (Exception ex) { + //ignore } } - HandleMsgContext handleMsgContext = new HandleMsgContext(EventMeshUtil.buildPushMsgSeqNo(), consumerGroupConf.getConsumerGroup(), EventMeshConsumer.this, - topic, event, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig); + HandleMsgContext handleMsgContext = new HandleMsgContext(EventMeshUtil.buildPushMsgSeqNo(), + consumerGroupConf.getConsumerGroup(), EventMeshConsumer.this, + topic, event, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), + consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig); if (httpMessageHandler.handle(handleMsgContext)) { -// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); -// context.ack(); + //context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, + // EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); + //context.ack(); eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck); } else { try { sendMessageBack(event, uniqueId, bizSeqNo); } catch (Exception e) { - + //ignore } -// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); -// context.ack(); + //context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, + // EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + //context.ack(); eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); } } @@ -165,7 +180,8 @@ public void consume(CloudEvent event, AsyncConsumeContext context) { public void consume(CloudEvent event, AsyncConsumeContext context) { event = CloudEventBuilder.from(event) - .withExtension(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())) + .withExtension(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, + String.valueOf(System.currentTimeMillis())) .build(); String topic = event.getSubject(); @@ -175,38 +191,47 @@ public void consume(CloudEvent event, AsyncConsumeContext context) { if (messageLogger.isDebugEnabled()) { messageLogger.debug("message|mq2eventMesh|topic={}|msg={}", topic, event); } else { - messageLogger.info("message|mq2eventMesh|topic={}|bizSeqNo={}|uniqueId={}", topic, bizSeqNo, uniqueId); + messageLogger.info("message|mq2eventMesh|topic={}|bizSeqNo={}|uniqueId={}", topic, bizSeqNo, + uniqueId); } - ConsumerGroupTopicConf currentTopicConfig = MapUtils.getObject(consumerGroupConf.getConsumerGroupTopicConf(), topic, null); - EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = (EventMeshAsyncConsumeContext)context; + ConsumerGroupTopicConf currentTopicConfig = MapUtils.getObject( + consumerGroupConf.getConsumerGroupTopicConf(), topic, null); + EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = (EventMeshAsyncConsumeContext) context; if (currentTopicConfig == null) { - logger.error("no topicConfig found, consumerGroup:{} topic:{}", consumerGroupConf.getConsumerGroup(), topic); + logger.error("no topicConfig found, consumerGroup:{} topic:{}", + consumerGroupConf.getConsumerGroup(), topic); try { sendMessageBack(event, uniqueId, bizSeqNo); -// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); -// context.ack(); + //context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, + // EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + //context.ack(); eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); return; } catch (Exception ex) { + //ignore } } - HandleMsgContext handleMsgContext = new HandleMsgContext(EventMeshUtil.buildPushMsgSeqNo(), consumerGroupConf.getConsumerGroup(), EventMeshConsumer.this, - topic, event, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig); + HandleMsgContext handleMsgContext = new HandleMsgContext(EventMeshUtil.buildPushMsgSeqNo(), + consumerGroupConf.getConsumerGroup(), EventMeshConsumer.this, + topic, event, subscriptionItem, eventMeshAsyncConsumeContext.getAbstractContext(), + consumerGroupConf, eventMeshHTTPServer, bizSeqNo, uniqueId, currentTopicConfig); if (httpMessageHandler.handle(handleMsgContext)) { -// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); -// context.ack(); + //context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, + // EventMeshConsumeConcurrentlyStatus.CONSUME_FINISH.name()); + //context.ack(); eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck); } else { try { sendMessageBack(event, uniqueId, bizSeqNo); } catch (Exception e) { - + //ignore } -// context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); -// context.ack(); + //context.attributes().put(NonStandardKeys.MESSAGE_CONSUME_STATUS, + // EventMeshConsumeConcurrentlyStatus.CONSUME_SUCCESS.name()); + //context.ack(); eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); } } @@ -223,14 +248,14 @@ public void unsubscribe(String topic, SubscriptionMode subscriptionMode) throws } } -// public boolean isPause() { -// return persistentMqConsumer.isPause() && broadcastMqConsumer.isPause(); -// } -// -// public void pause() { -// persistentMqConsumer.pause(); -// broadcastMqConsumer.pause(); -// } + //public boolean isPause() { + // return persistentMqConsumer.isPause() && broadcastMqConsumer.isPause(); + //} + // + //public void pause() { + // persistentMqConsumer.pause(); + // broadcastMqConsumer.pause(); + //} public synchronized void shutdown() throws Exception { persistentMqConsumer.shutdown(); @@ -239,7 +264,8 @@ public synchronized void shutdown() throws Exception { started4Broadcast.compareAndSet(true, false); } - public void updateOffset(String topic, SubscriptionMode subscriptionMode, List events, AbstractContext context) { + public void updateOffset(String topic, SubscriptionMode subscriptionMode, List events, + AbstractContext context) { if (SubscriptionMode.BROADCASTING.equals(subscriptionMode)) { broadcastMqConsumer.updateOffset(events, context); } else { @@ -261,11 +287,13 @@ public void sendMessageBack(final CloudEvent event, final String uniqueId, Strin = eventMeshHTTPServer.getProducerManager().getEventMeshProducer(consumerGroupConf.getConsumerGroup()); if (sendMessageBack == null) { - logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqNo:{}, uniqueId:{}", consumerGroupConf.getConsumerGroup(), bizSeqNo, uniqueId); + logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqNo:{}, uniqueId:{}", + consumerGroupConf.getConsumerGroup(), bizSeqNo, uniqueId); return; } - final SendMessageContext sendMessageBackContext = new SendMessageContext(bizSeqNo, event, sendMessageBack, eventMeshHTTPServer); + final SendMessageContext sendMessageBackContext = new SendMessageContext(bizSeqNo, event, sendMessageBack, + eventMeshHTTPServer); sendMessageBack.send(sendMessageBackContext, new SendCallback() { @Override @@ -274,13 +302,15 @@ public void onSuccess(SendResult sendResult) { @Override public void onException(OnExceptionContext context) { - logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqno:{}, uniqueId:{}", consumerGroupConf.getConsumerGroup(), bizSeqNo, uniqueId); + logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqno:{}, uniqueId:{}", + consumerGroupConf.getConsumerGroup(), bizSeqNo, uniqueId); } -// @Override -// public void onException(Throwable e) { -// logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqno:{}, uniqueId:{}", consumerGroupConf.getConsumerGroup(), bizSeqNo, uniqueId); -// } + //@Override + //public void onException(Throwable e) { + // logger.warn("consumer:{} consume fail, sendMessageBack, bizSeqno:{}, uniqueId:{}", + // consumerGroupConf.getConsumerGroup(), bizSeqNo, uniqueId); + //} }); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/HandleMsgContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/HandleMsgContext.java index 711a6dd030..cf0ba7f642 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/HandleMsgContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/consumer/HandleMsgContext.java @@ -17,13 +17,6 @@ package org.apache.eventmesh.runtime.core.protocol.http.consumer; -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import io.cloudevents.CloudEvent; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.api.AbstractContext; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.SubscriptionItem; @@ -31,9 +24,19 @@ import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupConf; import org.apache.eventmesh.runtime.core.consumergroup.ConsumerGroupTopicConf; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; + public class HandleMsgContext { public Logger messageLogger = LoggerFactory.getLogger("message"); @@ -86,7 +89,7 @@ public HandleMsgContext(String msgRandomNo, String consumerGroup, EventMeshConsu this.consumeTopicConfig = consumeTopicConfig; String ttlStr = (String) event.getExtension(Constants.PROPERTY_MESSAGE_TIMEOUT); - this.ttl = StringUtils.isNumeric(ttlStr)? Integer.parseInt(ttlStr): EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; + this.ttl = StringUtils.isNumeric(ttlStr) ? Integer.parseInt(ttlStr) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; } public void addProp(String key, String val) { @@ -195,10 +198,10 @@ public EventMeshHTTPServer getEventMeshHTTPServer() { public void finish() { if (eventMeshConsumer != null && context != null && event != null) { if (messageLogger.isDebugEnabled()) { -// messageLogger.debug("messageAcked|topic={}|msgId={}|cluster={}|broker={}|queueId={}|queueOffset={}", topic, -// msg.getMsgId(), msg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_CLUSTER), -// msg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_BROKER), -// msg.getQueueId(), msg.getQueueOffset()); + //messageLogger.debug("messageAcked|topic={}|msgId={}|cluster={}|broker={}|queueId={}|queueOffset={}", topic, + // msg.getMsgId(), msg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_CLUSTER), + // msg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_BROKER), + // msg.getQueueId(), msg.getQueueOffset()); } eventMeshConsumer.updateOffset(topic, subscriptionItem.getMode(), Arrays.asList(event), context); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/AdminMetricsProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/AdminMetricsProcessor.java index a8153c60a6..b1e0688bd9 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/AdminMetricsProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/AdminMetricsProcessor.java @@ -17,15 +17,16 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; -import io.netty.channel.ChannelHandlerContext; - import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.core.protocol.http.async.AsyncContext; import org.apache.eventmesh.runtime.core.protocol.http.processor.inf.HttpRequestProcessor; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public class AdminMetricsProcessor implements HttpRequestProcessor { private EventMeshHTTPServer eventMeshHTTPServer; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/AdminShutdownProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/AdminShutdownProcessor.java index 97db4bba44..d1881ad983 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/AdminShutdownProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/AdminShutdownProcessor.java @@ -17,10 +17,10 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; -import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.common.EventMeshRetCode; import org.apache.eventmesh.common.protocol.http.common.RequestCode; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.runtime.boot.EventMeshServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.http.async.AsyncContext; @@ -47,9 +47,9 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext HttpCommand responseEventMeshCommand; cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", - RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), - EventMeshConstants.PROTOCOL_HTTP, - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); + RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), + EventMeshConstants.PROTOCOL_HTTP, + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); eventMeshServer.shutdown(); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageProcessor.java index 24e6119f63..afdd365d80 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageProcessor.java @@ -17,17 +17,10 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; -import io.cloudevents.CloudEvent; -import io.cloudevents.CloudEventData; -import io.cloudevents.core.builder.CloudEventBuilder; -import io.netty.channel.ChannelHandlerContext; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.api.SendCallback; import org.apache.eventmesh.api.SendResult; import org.apache.eventmesh.api.exception.OnExceptionContext; import org.apache.eventmesh.common.protocol.ProtocolTransportObject; -import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageBatchRequestBody; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageBatchResponseBody; @@ -38,6 +31,7 @@ import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageBatchRequestHeader; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageBatchResponseHeader; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.protocol.api.ProtocolAdaptor; import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; import org.apache.eventmesh.runtime.acl.Acl; @@ -48,8 +42,9 @@ import org.apache.eventmesh.runtime.core.protocol.http.producer.EventMeshProducer; import org.apache.eventmesh.runtime.core.protocol.http.producer.SendMessageContext; import org.apache.eventmesh.runtime.util.RemotingHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.List; @@ -58,6 +53,14 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.cloudevents.CloudEvent; +import io.cloudevents.CloudEventData; +import io.cloudevents.core.builder.CloudEventBuilder; +import io.netty.channel.ChannelHandlerContext; + public class BatchSendMessageProcessor implements HttpRequestProcessor { public Logger cmdLogger = LoggerFactory.getLogger("cmd"); @@ -77,14 +80,17 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext HttpCommand responseEventMeshCommand; - cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), + cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", RequestCode.get( + Integer.valueOf(asyncContext.getRequest().getRequestCode())), EventMeshConstants.PROTOCOL_HTTP, RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); - SendMessageBatchRequestHeader sendMessageBatchRequestHeader = (SendMessageBatchRequestHeader) asyncContext.getRequest().getHeader(); + SendMessageBatchRequestHeader sendMessageBatchRequestHeader = + (SendMessageBatchRequestHeader) asyncContext.getRequest().getHeader(); SendMessageBatchResponseHeader sendMessageBatchResponseHeader = - SendMessageBatchResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, + SendMessageBatchResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtils.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); @@ -95,7 +101,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext if (CollectionUtils.isEmpty(eventList)) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchResponseHeader, - SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -113,7 +120,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || StringUtils.isBlank(event.getSubject())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchResponseHeader, - SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -129,7 +137,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || StringUtils.isBlank(sys)) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchResponseHeader, - SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -146,7 +155,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || eventSize != eventList.size()) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchResponseHeader, - SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -157,7 +167,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext .tryAcquire(eventSize, EventMeshConstants.DEFAULT_FASTFAIL_TIMEOUT_IN_MILLISECONDS, TimeUnit.MILLISECONDS)) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchResponseHeader, - SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR.getErrMsg())); + SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR.getErrMsg())); eventMeshHTTPServer.metrics.summaryMetrics .recordSendBatchMsgDiscard(eventSize); asyncContext.onComplete(responseEventMeshCommand); @@ -171,12 +182,13 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext if (!batchEventMeshProducer.getStarted().get()) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchResponseHeader, - SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_BATCH_PRODUCER_STOPED_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_BATCH_PRODUCER_STOPED_ERR.getErrMsg())); + SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_BATCH_PRODUCER_STOPED_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_BATCH_PRODUCER_STOPED_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } - long batchStartTime = System.currentTimeMillis(); + final long batchStartTime = System.currentTimeMillis(); String remoteAddr = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); int requestCode = Integer.parseInt(asyncContext.getRequest().getRequestCode()); @@ -194,7 +206,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext String subsystem = Objects.requireNonNull(cloudEvent.getExtension(ProtocolKey.ClientInstanceKey.SYS)).toString(); //do acl check - if(eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerSecurityEnable) { + if (eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerSecurityEnable) { try { Acl.doAclCheckInHttpSend(remoteAddr, user, pass, subsystem, cloudEvent.getSubject(), requestCode); } catch (Exception e) { @@ -239,7 +251,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext if (CollectionUtils.isEmpty(eventList)) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchResponseHeader, - SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + SendMessageBatchResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -251,20 +264,21 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext for (List eventlist : topicBatchMessageMappings.values()) { // TODO: Implementation in API. Consider whether to put it in the plug-in. CloudEvent event = null; -// Message omsMsg = new Message(); -// try { -// msgBatch = msgBatch.generateFromList(batchMsgs); -// for (Message message : msgBatch.getMessages()) { -// // TODO: Detect the maximum length of messages for different producers. -// Validators.checkMessage(message, batchEventMeshProducer.getMqProducerWrapper().getDefaultMQProducer()); -// MessageClientIDSetter.setUniqID(message); -// } -// msgBatch.setBody(msgBatch.encode()); -// } catch (Exception e) { -// continue; -// } - - final SendMessageContext sendMessageContext = new SendMessageContext(batchId, event, batchEventMeshProducer, eventMeshHTTPServer); + //Message omsMsg = new Message(); + //try { + // msgBatch = msgBatch.generateFromList(batchMsgs); + // for (Message message : msgBatch.getMessages()) { + // // TODO: Detect the maximum length of messages for different producers. + // Validators.checkMessage(message, batchEventMeshProducer.getMqProducerWrapper().getDefaultMQProducer()); + // MessageClientIDSetter.setUniqID(message); + // } + // msgBatch.setBody(msgBatch.encode()); + //} catch (Exception e) { + // continue; + //} + + final SendMessageContext sendMessageContext = new SendMessageContext(batchId, event, batchEventMeshProducer, + eventMeshHTTPServer); sendMessageContext.setEventList(eventlist); batchEventMeshProducer.send(sendMessageContext, new SendCallback() { @Override @@ -281,7 +295,8 @@ public void onException(OnExceptionContext context) { } } else { for (CloudEvent event : eventList) { - final SendMessageContext sendMessageContext = new SendMessageContext(batchId, event, batchEventMeshProducer, eventMeshHTTPServer); + final SendMessageContext sendMessageContext = new SendMessageContext(batchId, event, batchEventMeshProducer, + eventMeshHTTPServer); batchEventMeshProducer.send(sendMessageContext, new SendCallback() { @Override public void onSuccess(SendResult sendResult) { @@ -305,7 +320,8 @@ public void onException(OnExceptionContext context) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageBatchResponseHeader, - SendMessageBatchResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(), EventMeshRetCode.SUCCESS.getErrMsg())); + SendMessageBatchResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(), + EventMeshRetCode.SUCCESS.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageV2Processor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageV2Processor.java index b15add641d..a1485e6ee6 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageV2Processor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/BatchSendMessageV2Processor.java @@ -20,7 +20,6 @@ import org.apache.eventmesh.api.SendCallback; import org.apache.eventmesh.api.SendResult; import org.apache.eventmesh.api.exception.OnExceptionContext; -import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.protocol.ProtocolTransportObject; import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageBatchV2RequestBody; @@ -32,6 +31,7 @@ import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageBatchV2RequestHeader; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageBatchV2ResponseHeader; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.protocol.api.ProtocolAdaptor; import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; import org.apache.eventmesh.runtime.acl.Acl; @@ -72,88 +72,88 @@ public BatchSendMessageV2Processor(EventMeshHTTPServer eventMeshHTTPServer) { @Override public void processRequest(ChannelHandlerContext ctx, AsyncContext asyncContext) - throws Exception { + throws Exception { HttpCommand responseEventMeshCommand; final HttpCommand request = asyncContext.getRequest(); final Integer requestCode = Integer.valueOf(request.getRequestCode()); cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", - RequestCode.get(requestCode), - EventMeshConstants.PROTOCOL_HTTP, - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); + RequestCode.get(requestCode), + EventMeshConstants.PROTOCOL_HTTP, + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); SendMessageBatchV2RequestHeader sendMessageBatchV2RequestHeader = - (SendMessageBatchV2RequestHeader) asyncContext.getRequest().getHeader(); + (SendMessageBatchV2RequestHeader) asyncContext.getRequest().getHeader(); String protocolType = sendMessageBatchV2RequestHeader.getProtocolType(); ProtocolAdaptor httpCommandProtocolAdaptor = - ProtocolPluginFactory.getProtocolAdaptor(protocolType); + ProtocolPluginFactory.getProtocolAdaptor(protocolType); CloudEvent event = httpCommandProtocolAdaptor.toCloudEvent(asyncContext.getRequest()); SendMessageBatchV2ResponseHeader sendMessageBatchV2ResponseHeader = - SendMessageBatchV2ResponseHeader.buildHeader( - requestCode, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, - IPUtils.getLocalAddress(), - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC - ); + SendMessageBatchV2ResponseHeader.buildHeader( + requestCode, + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, + IPUtils.getLocalAddress(), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC + ); // todo: use validate processor to check //validate event if (StringUtils.isBlank(event.getId()) - || event.getSource() == null - || event.getSpecVersion() == null - || StringUtils.isBlank(event.getType()) - || StringUtils.isBlank(event.getSubject())) { + || event.getSource() == null + || event.getSpecVersion() == null + || StringUtils.isBlank(event.getType()) + || StringUtils.isBlank(event.getSubject())) { responseEventMeshCommand = request.createHttpCommandResponse( - sendMessageBatchV2ResponseHeader, - SendMessageBatchV2ResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + sendMessageBatchV2ResponseHeader, + SendMessageBatchV2ResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } String idc = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.IDC)) - .toString(); + .toString(); String pid = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.PID)) - .toString(); + .toString(); String sys = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.SYS)) - .toString(); + .toString(); //validate event-extension if (StringUtils.isBlank(idc) - || StringUtils.isBlank(pid) - || !StringUtils.isNumeric(pid) - || StringUtils.isBlank(sys)) { + || StringUtils.isBlank(pid) + || !StringUtils.isNumeric(pid) + || StringUtils.isBlank(sys)) { responseEventMeshCommand = request.createHttpCommandResponse( - sendMessageBatchV2ResponseHeader, - SendMessageBatchV2ResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + sendMessageBatchV2ResponseHeader, + SendMessageBatchV2ResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } String bizNo = - Objects.requireNonNull(event.getExtension(SendMessageBatchV2RequestBody.BIZSEQNO)) - .toString(); + Objects.requireNonNull(event.getExtension(SendMessageBatchV2RequestBody.BIZSEQNO)) + .toString(); String producerGroup = - Objects.requireNonNull(event.getExtension(SendMessageBatchV2RequestBody.PRODUCERGROUP)) - .toString(); + Objects.requireNonNull(event.getExtension(SendMessageBatchV2RequestBody.PRODUCERGROUP)) + .toString(); String topic = event.getSubject(); if (StringUtils.isBlank(bizNo) - || StringUtils.isBlank(topic) - || StringUtils.isBlank(producerGroup) - || event.getData() == null) { + || StringUtils.isBlank(topic) + || StringUtils.isBlank(producerGroup) + || event.getData() == null) { responseEventMeshCommand = request.createHttpCommandResponse( - sendMessageBatchV2ResponseHeader, - SendMessageBatchV2ResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + sendMessageBatchV2ResponseHeader, + SendMessageBatchV2ResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -170,40 +170,40 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext //String errorMsg = String.format("CLIENT HAS NO PERMISSION,send failed, topic:%s, subsys:%s, realIp:%s", topic, subsys, realIp); responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageBatchV2ResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_ACL_ERR.getRetCode(), - e.getMessage())); + sendMessageBatchV2ResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_ACL_ERR.getRetCode(), + e.getMessage())); asyncContext.onComplete(responseEventMeshCommand); aclLogger - .warn("CLIENT HAS NO PERMISSION,BatchSendMessageV2Processor send failed", e); + .warn("CLIENT HAS NO PERMISSION,BatchSendMessageV2Processor send failed", e); return; } } if (!eventMeshHTTPServer.getBatchRateLimiter() - .tryAcquire(EventMeshConstants.DEFAULT_FASTFAIL_TIMEOUT_IN_MILLISECONDS, - TimeUnit.MILLISECONDS)) { + .tryAcquire(EventMeshConstants.DEFAULT_FASTFAIL_TIMEOUT_IN_MILLISECONDS, + TimeUnit.MILLISECONDS)) { responseEventMeshCommand = request.createHttpCommandResponse( - sendMessageBatchV2ResponseHeader, - SendMessageBatchV2ResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR.getErrMsg())); + sendMessageBatchV2ResponseHeader, + SendMessageBatchV2ResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_BATCH_SPEED_OVER_LIMIT_ERR.getErrMsg())); eventMeshHTTPServer.metrics.summaryMetrics - .recordSendBatchMsgDiscard(1); + .recordSendBatchMsgDiscard(1); asyncContext.onComplete(responseEventMeshCommand); return; } EventMeshProducer batchEventMeshProducer = - eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup); + eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup); batchEventMeshProducer.getMqProducerWrapper().getMeshMQProducer().setExtFields(); if (!batchEventMeshProducer.getStarted().get()) { responseEventMeshCommand = request.createHttpCommandResponse( - sendMessageBatchV2ResponseHeader, - SendMessageBatchV2ResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_BATCH_PRODUCER_STOPED_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_BATCH_PRODUCER_STOPED_ERR.getErrMsg())); + sendMessageBatchV2ResponseHeader, + SendMessageBatchV2ResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_BATCH_PRODUCER_STOPED_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_BATCH_PRODUCER_STOPED_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -213,20 +213,20 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext String ttl = String.valueOf(EventMeshConstants.DEFAULT_MSG_TTL_MILLS); // todo: use hashmap to avoid copy if (StringUtils.isBlank(event.getExtension(SendMessageRequestBody.TTL).toString()) - && !StringUtils.isNumeric(event.getExtension(SendMessageRequestBody.TTL).toString())) { + && !StringUtils.isNumeric(event.getExtension(SendMessageRequestBody.TTL).toString())) { event = CloudEventBuilder.from(event).withExtension(SendMessageRequestBody.TTL, ttl) - .build(); + .build(); } try { event = CloudEventBuilder.from(event) - .withExtension("msgtype", "persistent") - .withExtension(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, - String.valueOf(System.currentTimeMillis())) - .withExtension(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, - String.valueOf(System.currentTimeMillis())) - .build(); + .withExtension("msgtype", "persistent") + .withExtension(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, + String.valueOf(System.currentTimeMillis())) + .withExtension(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, + String.valueOf(System.currentTimeMillis())) + .build(); if (batchMessageLogger.isDebugEnabled()) { batchMessageLogger.debug("msg2MQMsg suc, topic:{}, msg:{}", topic, event.getData()); } @@ -234,11 +234,12 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext } catch (Exception e) { batchMessageLogger.error("msg2MQMsg err, topic:{}, msg:{}", topic, event.getData(), e); responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageBatchV2ResponseHeader, - SendMessageBatchV2ResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getErrMsg() + - EventMeshUtil.stackTrace(e, 2))); + sendMessageBatchV2ResponseHeader, + SendMessageBatchV2ResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getErrMsg() + + + EventMeshUtil.stackTrace(e, 2))); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -246,7 +247,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext eventMeshHTTPServer.metrics.summaryMetrics.recordSendBatchMsg(1); final SendMessageContext sendMessageContext = - new SendMessageContext(bizNo, event, batchEventMeshProducer, eventMeshHTTPServer); + new SendMessageContext(bizNo, event, batchEventMeshProducer, eventMeshHTTPServer); try { batchEventMeshProducer.send(sendMessageContext, new SendCallback() { @@ -254,10 +255,10 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext public void onSuccess(SendResult sendResult) { long batchEndTime = System.currentTimeMillis(); eventMeshHTTPServer.metrics.summaryMetrics - .recordBatchSendMsgCost(batchEndTime - batchStartTime); + .recordBatchSendMsgCost(batchEndTime - batchStartTime); batchMessageLogger.debug( - "batchMessageV2|eventMesh2mq|REQ|ASYNC|bizSeqNo={}|send2MQCost={}ms|topic={}", - bizNo, batchEndTime - batchStartTime, topic); + "batchMessageV2|eventMesh2mq|REQ|ASYNC|bizSeqNo={}|send2MQCost={}ms|topic={}", + bizNo, batchEndTime - batchStartTime, topic); } @Override @@ -265,34 +266,35 @@ public void onException(OnExceptionContext context) { long batchEndTime = System.currentTimeMillis(); eventMeshHTTPServer.getHttpRetryer().pushRetry(sendMessageContext.delay(10000)); eventMeshHTTPServer.metrics.summaryMetrics - .recordBatchSendMsgCost(batchEndTime - batchStartTime); + .recordBatchSendMsgCost(batchEndTime - batchStartTime); batchMessageLogger.error( - "batchMessageV2|eventMesh2mq|REQ|ASYNC|bizSeqNo={}|send2MQCost={}ms|topic={}", - bizNo, batchEndTime - batchStartTime, topic, context.getException()); + "batchMessageV2|eventMesh2mq|REQ|ASYNC|bizSeqNo={}|send2MQCost={}ms|topic={}", + bizNo, batchEndTime - batchStartTime, topic, context.getException()); } }); } catch (Exception e) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageBatchV2ResponseHeader, - SendMessageBatchV2ResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_SEND_BATCHLOG_MSG_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_SEND_BATCHLOG_MSG_ERR.getErrMsg() + - EventMeshUtil.stackTrace(e, 2))); + sendMessageBatchV2ResponseHeader, + SendMessageBatchV2ResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_SEND_BATCHLOG_MSG_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_SEND_BATCHLOG_MSG_ERR.getErrMsg() + + + EventMeshUtil.stackTrace(e, 2))); asyncContext.onComplete(responseEventMeshCommand); long batchEndTime = System.currentTimeMillis(); eventMeshHTTPServer.getHttpRetryer().pushRetry(sendMessageContext.delay(10000)); eventMeshHTTPServer.metrics.summaryMetrics - .recordBatchSendMsgCost(batchEndTime - batchStartTime); + .recordBatchSendMsgCost(batchEndTime - batchStartTime); batchMessageLogger.error( - "batchMessageV2|eventMesh2mq|REQ|ASYNC|bizSeqNo={}|send2MQCost={}ms|topic={}", - bizNo, batchEndTime - batchStartTime, topic, e); + "batchMessageV2|eventMesh2mq|REQ|ASYNC|bizSeqNo={}|send2MQCost={}ms|topic={}", + bizNo, batchEndTime - batchStartTime, topic, e); } responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageBatchV2ResponseHeader, - SendMessageBatchV2ResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(), - EventMeshRetCode.SUCCESS.getErrMsg())); + sendMessageBatchV2ResponseHeader, + SendMessageBatchV2ResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(), + EventMeshRetCode.SUCCESS.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HeartBeatProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HeartBeatProcessor.java index 45e21dae42..a2e4e709ed 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HeartBeatProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/HeartBeatProcessor.java @@ -17,7 +17,6 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; -import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.body.client.HeartbeatRequestBody; import org.apache.eventmesh.common.protocol.http.body.client.HeartbeatResponseBody; @@ -26,6 +25,7 @@ import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.protocol.http.header.client.HeartbeatRequestHeader; import org.apache.eventmesh.common.protocol.http.header.client.HeartbeatResponseHeader; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.runtime.acl.Acl; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -66,41 +66,41 @@ public HeartBeatProcessor(EventMeshHTTPServer eventMeshHTTPServer) { public void processRequest(ChannelHandlerContext ctx, AsyncContext asyncContext) throws Exception { HttpCommand responseEventMeshCommand; httpLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", - RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), - EventMeshConstants.PROTOCOL_HTTP, - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); + RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), + EventMeshConstants.PROTOCOL_HTTP, + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); HeartbeatRequestHeader heartbeatRequestHeader = (HeartbeatRequestHeader) asyncContext.getRequest().getHeader(); HeartbeatRequestBody heartbeatRequestBody = (HeartbeatRequestBody) asyncContext.getRequest().getBody(); HeartbeatResponseHeader heartbeatResponseHeader = - HeartbeatResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, - IPUtils.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + HeartbeatResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, + IPUtils.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); //validate header if (StringUtils.isBlank(heartbeatRequestHeader.getIdc()) - || StringUtils.isBlank(heartbeatRequestHeader.getPid()) - || !StringUtils.isNumeric(heartbeatRequestHeader.getPid()) - || StringUtils.isBlank(heartbeatRequestHeader.getSys())) { + || StringUtils.isBlank(heartbeatRequestHeader.getPid()) + || !StringUtils.isNumeric(heartbeatRequestHeader.getPid()) + || StringUtils.isBlank(heartbeatRequestHeader.getSys())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - heartbeatResponseHeader, - HeartbeatResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + heartbeatResponseHeader, + HeartbeatResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } //validate body if (StringUtils.isBlank(heartbeatRequestBody.getClientType()) - || StringUtils.isBlank(heartbeatRequestBody.getConsumerGroup()) - || CollectionUtils.isEmpty(heartbeatRequestBody.getHeartbeatEntities())) { + || StringUtils.isBlank(heartbeatRequestBody.getConsumerGroup()) + || CollectionUtils.isEmpty(heartbeatRequestBody.getHeartbeatEntities())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - heartbeatResponseHeader, - HeartbeatResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + heartbeatResponseHeader, + HeartbeatResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -113,8 +113,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext String consumerGroup = heartbeatRequestBody.getConsumerGroup(); List heartbeatEntities = heartbeatRequestBody.getHeartbeatEntities(); for (HeartbeatRequestBody.HeartbeatEntity heartbeatEntity : heartbeatEntities) { - String topic = heartbeatEntity.topic; - String url = heartbeatEntity.url; + Client client = new Client(); client.env = env; client.idc = idc; @@ -122,8 +121,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext client.ip = ip; client.pid = pid; client.consumerGroup = consumerGroup; - client.topic = topic; - client.url = url; + client.topic = heartbeatEntity.topic; + client.url = heartbeatEntity.url; client.lastUpTime = new Date(); @@ -138,14 +137,14 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext String pass = heartbeatRequestHeader.getPasswd(); int requestCode = Integer.valueOf(heartbeatRequestHeader.getCode()); try { - Acl.doAclCheckInHttpHeartbeat(remoteAddr, user, pass, sys, topic, requestCode); + Acl.doAclCheckInHttpHeartbeat(remoteAddr, user, pass, sys, client.topic, requestCode); } catch (Exception e) { //String errorMsg = String.format("CLIENT HAS NO PERMISSION,send failed, topic:%s, subsys:%s, realIp:%s", topic, subsys, realIp); responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - heartbeatResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_ACL_ERR.getRetCode(), e.getMessage())); + heartbeatResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_ACL_ERR.getRetCode(), e.getMessage())); asyncContext.onComplete(responseEventMeshCommand); aclLogger.warn("CLIENT HAS NO PERMISSION,HeartBeatProcessor subscribe failed", e); return; @@ -169,10 +168,10 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext synchronized (eventMeshHTTPServer.localClientInfoMapping) { for (Map.Entry> groupTopicClientMapping : tmp.entrySet()) { List localClientList = - eventMeshHTTPServer.localClientInfoMapping.get(groupTopicClientMapping.getKey()); + eventMeshHTTPServer.localClientInfoMapping.get(groupTopicClientMapping.getKey()); if (CollectionUtils.isEmpty(localClientList)) { eventMeshHTTPServer.localClientInfoMapping - .put(groupTopicClientMapping.getKey(), groupTopicClientMapping.getValue()); + .put(groupTopicClientMapping.getKey(), groupTopicClientMapping.getValue()); } else { List tmpClientList = groupTopicClientMapping.getValue(); supplyClientInfoList(tmpClientList, localClientList); @@ -194,8 +193,9 @@ public void onResponse(HttpCommand httpCommand) { } eventMeshHTTPServer.sendResponse(ctx, httpCommand.httpResponse()); eventMeshHTTPServer.metrics.summaryMetrics.recordHTTPReqResTimeCost( - System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); + System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); } catch (Exception ex) { + //ignore } } }; @@ -204,13 +204,13 @@ public void onResponse(HttpCommand httpCommand) { asyncContext.onComplete(responseEventMeshCommand, handler); } catch (Exception e) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( - heartbeatResponseHeader, - HeartbeatResponseBody.buildBody(EventMeshRetCode.EVENTMESH_HEARTBEAT_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_HEARTBEAT_ERR.getErrMsg() + EventMeshUtil.stackTrace(e, 2))); + heartbeatResponseHeader, + HeartbeatResponseBody.buildBody(EventMeshRetCode.EVENTMESH_HEARTBEAT_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_HEARTBEAT_ERR.getErrMsg() + EventMeshUtil.stackTrace(e, 2))); asyncContext.onComplete(err); long endTime = System.currentTimeMillis(); httpLogger.error("message|eventMesh2mq|REQ|ASYNC|heartBeatMessageCost={}ms", - endTime - startTime, e); + endTime - startTime, e); eventMeshHTTPServer.metrics.summaryMetrics.recordSendMsgFailed(); eventMeshHTTPServer.metrics.summaryMetrics.recordSendMsgCost(endTime - startTime); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/ReplyMessageProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/ReplyMessageProcessor.java index 8114f4cc90..cb5e1d4876 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/ReplyMessageProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/ReplyMessageProcessor.java @@ -17,16 +17,10 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; -import io.cloudevents.CloudEvent; -import io.cloudevents.core.builder.CloudEventBuilder; -import io.netty.channel.ChannelHandlerContext; - -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.api.SendCallback; import org.apache.eventmesh.api.SendResult; import org.apache.eventmesh.api.exception.OnExceptionContext; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.protocol.ProtocolTransportObject; import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.body.message.ReplyMessageResponseBody; @@ -37,6 +31,7 @@ import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.protocol.http.header.message.ReplyMessageRequestHeader; import org.apache.eventmesh.common.protocol.http.header.message.ReplyMessageResponseHeader; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.protocol.api.ProtocolAdaptor; import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; @@ -48,12 +43,19 @@ import org.apache.eventmesh.runtime.core.protocol.http.producer.SendMessageContext; import org.apache.eventmesh.runtime.util.EventMeshUtil; import org.apache.eventmesh.runtime.util.RemotingHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.util.Objects; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; +import io.netty.channel.ChannelHandlerContext; + public class ReplyMessageProcessor implements HttpRequestProcessor { public Logger messageLogger = LoggerFactory.getLogger("message"); @@ -77,14 +79,15 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); ReplyMessageRequestHeader replyMessageRequestHeader = (ReplyMessageRequestHeader) asyncContext.getRequest().getHeader(); -// ReplyMessageRequestBody replyMessageRequestBody = (ReplyMessageRequestBody) asyncContext.getRequest().getBody(); + //ReplyMessageRequestBody replyMessageRequestBody = (ReplyMessageRequestBody) asyncContext.getRequest().getBody(); String protocolType = replyMessageRequestHeader.getProtocolType(); ProtocolAdaptor httpCommandProtocolAdaptor = ProtocolPluginFactory.getProtocolAdaptor(protocolType); CloudEvent event = httpCommandProtocolAdaptor.toCloudEvent(asyncContext.getRequest()); ReplyMessageResponseHeader replyMessageResponseHeader = - ReplyMessageResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, + ReplyMessageResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtils.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); @@ -97,7 +100,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || StringUtils.isBlank(event.getSubject())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( replyMessageResponseHeader, - ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -113,7 +117,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || StringUtils.isBlank(sys)) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( replyMessageResponseHeader, - ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -129,7 +134,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || event.getData() == null) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( replyMessageResponseHeader, - ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -151,63 +157,71 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext if (!eventMeshProducer.getStarted().get()) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( replyMessageResponseHeader, - ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getErrMsg())); + ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } long startTime = System.currentTimeMillis(); -// Message rocketMQMsg; -// Message omsMsg = new Message(); + //Message rocketMQMsg; + //Message omsMsg = new Message(); String replyTopic = EventMeshConstants.RR_REPLY_TOPIC; String origTopic = event.getSubject(); -// Map extFields = replyMessageRequestBody.getExtFields(); + //Map extFields = replyMessageRequestBody.getExtFields(); final String replyMQCluster = event.getExtension(EventMeshConstants.PROPERTY_MESSAGE_CLUSTER).toString(); -// final String replyMQCluster = MapUtils.getString(extFields, EventMeshConstants.PROPERTY_MESSAGE_CLUSTER, null); + //final String replyMQCluster = MapUtils.getString(extFields, EventMeshConstants.PROPERTY_MESSAGE_CLUSTER, null); if (!org.apache.commons.lang3.StringUtils.isEmpty(replyMQCluster)) { replyTopic = replyMQCluster + "-" + replyTopic; } else { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( replyMessageResponseHeader, - ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getErrMsg())); + ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } try { // body -// omsMsg.setBody(replyMessageRequestBody.getContent().getBytes(EventMeshConstants.DEFAULT_CHARSET)); + //omsMsg.setBody(replyMessageRequestBody.getContent().getBytes(EventMeshConstants.DEFAULT_CHARSET)); event = CloudEventBuilder.from(event) .withSubject(replyTopic) .withExtension("msgtype", "persistent") .withExtension(Constants.PROPERTY_MESSAGE_TIMEOUT, String.valueOf(EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS)) .withExtension(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())) .build(); -// omsMsg.setTopic(replyTopic); + + //omsMsg.setTopic(replyTopic); // topic -// omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION, replyTopic); -// if (!StringUtils.isBlank(sendMessageRequestBody.getTag())) { -// omsMsg.putUserHeaders("Tag", sendMessageRequestBody.getTag()); -// } -// rocketMQMsg = new Message(replyTopic, -// replyMessageRequestBody.getContent().getBytes(EventMeshConstants.DEFAULT_CHARSET)); -// omsMsg.putUserProperties("msgType", "persistent"); -// rocketMQMsg.putUserProperty(DeFiBusConstant.KEY, DeFiBusConstant.PERSISTENT); -// for (Map.Entry entry : extFields.entrySet()) { -// omsMsg.putUserProperties(entry.getKey(), entry.getValue()); -// } - -// //for rocketmq support -// MessageAccessor.putProperty(rocketMQMsg, MessageConst.PROPERTY_MESSAGE_TYPE, MixAll.REPLY_MESSAGE_FLAG); -// MessageAccessor.putProperty(rocketMQMsg, MessageConst.PROPERTY_CORRELATION_ID, rocketMQMsg.getProperty(DeFiBusConstant.PROPERTY_RR_REQUEST_ID)); -// MessageAccessor.putProperty(rocketMQMsg, MessageConst.PROPERTY_MESSAGE_REPLY_TO_CLIENT, rocketMQMsg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_REPLY_TO)); + //omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION, replyTopic); + //if (!StringUtils.isBlank(sendMessageRequestBody.getTag())) { + // omsMsg.putUserHeaders("Tag", sendMessageRequestBody.getTag()); + //} + //rocketMQMsg = new Message(replyTopic, + // replyMessageRequestBody.getContent().getBytes(EventMeshConstants.DEFAULT_CHARSET)); + //omsMsg.putUserProperties("msgType", "persistent"); + //rocketMQMsg.putUserProperty(DeFiBusConstant.KEY, DeFiBusConstant.PERSISTENT); + //for (Map.Entry entry : extFields.entrySet()) { + // omsMsg.putUserProperties(entry.getKey(), entry.getValue()); + //} + // + ////for rocketmq support + //MessageAccessor.putProperty(rocketMQMsg, MessageConst.PROPERTY_MESSAGE_TYPE, MixAll.REPLY_MESSAGE_FLAG); + //MessageAccessor.putProperty(rocketMQMsg, MessageConst.PROPERTY_CORRELATION_ID, + // rocketMQMsg.getProperty(DeFiBusConstant.PROPERTY_RR_REQUEST_ID)); + //MessageAccessor.putProperty(rocketMQMsg, MessageConst.PROPERTY_MESSAGE_REPLY_TO_CLIENT, + // rocketMQMsg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_REPLY_TO)); // ttl -// omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_TIMEOUT, String.valueOf(EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS)); -//// MessageAccessor.putProperty(rocketMQMsg, DeFiBusConstant.PROPERTY_MESSAGE_TTL, String.valueOf(EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS)); -// omsMsg.putUserProperties(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())); + //omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_TIMEOUT, + // String.valueOf(EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS)); + ////MessageAccessor.putProperty(rocketMQMsg, DeFiBusConstant.PROPERTY_MESSAGE_TTL, + // String.valueOf(EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS)); + //omsMsg.putUserProperties(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, + // String.valueOf(System.currentTimeMillis())); if (messageLogger.isDebugEnabled()) { messageLogger.debug("msg2MQMsg suc, bizSeqNo={}, topic={}", bizNo, replyTopic); } @@ -216,7 +230,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext messageLogger.error("msg2MQMsg err, bizSeqNo={}, topic={}", bizNo, replyTopic, e); responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( replyMessageResponseHeader, - ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(e, 2))); + ReplyMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(e, 2))); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -232,8 +247,10 @@ public void onResponse(HttpCommand httpCommand) { httpLogger.debug("{}", httpCommand); } eventMeshHTTPServer.sendResponse(ctx, httpCommand.httpResponse()); - eventMeshHTTPServer.metrics.summaryMetrics.recordHTTPReqResTimeCost(System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); + eventMeshHTTPServer.metrics.summaryMetrics.recordHTTPReqResTimeCost( + System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); } catch (Exception ex) { + //ignore } } }; @@ -263,7 +280,8 @@ public void onException(OnExceptionContext context) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( replyMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(context.getException(), 2))); + EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getErrMsg() + + EventMeshUtil.stackTrace(context.getException(), 2))); asyncContext.onComplete(err, handler); long endTime = System.currentTimeMillis(); eventMeshHTTPServer.metrics.summaryMetrics.recordReplyMsgFailed(); @@ -273,23 +291,23 @@ public void onException(OnExceptionContext context) { origTopic, bizNo, uniqueId, context.getException()); } -// @Override -// public void onException(Throwable e) { -// HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( -// replyMessageResponseHeader, -// SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getRetCode(), -// EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(e, 2))); -// asyncContext.onComplete(err, handler); -// long endTime = System.currentTimeMillis(); -// eventMeshHTTPServer.metrics.summaryMetrics.recordReplyMsgFailed(); -// eventMeshHTTPServer.metrics.summaryMetrics.recordReplyMsgCost(endTime - startTime); -// messageLogger.error("message|eventMesh2mq|RSP|SYNC|reply2MQCost={}|topic={}|origTopic={}|bizSeqNo={}|uniqueId={}", -// endTime - startTime, -// replyMQCluster + "-" + EventMeshConstants.RR_REPLY_TOPIC, -// replyMessageRequestBody.getOrigTopic(), -// replyMessageRequestBody.getBizSeqNo(), -// replyMessageRequestBody.getUniqueId(), e); -// } + //@Override + //public void onException(Throwable e) { + // HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( + // replyMessageResponseHeader, + // SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getRetCode(), + // EventMeshRetCode.EVENTMESH_REPLY_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(e, 2))); + // asyncContext.onComplete(err, handler); + // long endTime = System.currentTimeMillis(); + // eventMeshHTTPServer.metrics.summaryMetrics.recordReplyMsgFailed(); + // eventMeshHTTPServer.metrics.summaryMetrics.recordReplyMsgCost(endTime - startTime); + // messageLogger.error("message|eventMesh2mq|RSP|SYNC|reply2MQCost={}|topic={}|origTopic={}|bizSeqNo={}|uniqueId={}", + // endTime - startTime, + // replyMQCluster + "-" + EventMeshConstants.RR_REPLY_TOPIC, + // replyMessageRequestBody.getOrigTopic(), + // replyMessageRequestBody.getBizSeqNo(), + // replyMessageRequestBody.getUniqueId(), e); + //} }); } catch (Exception ex) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java index 5cbbd302de..fbb8082a50 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendAsyncMessageProcessor.java @@ -17,13 +17,9 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; -import io.cloudevents.core.builder.CloudEventBuilder; - -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.api.SendCallback; import org.apache.eventmesh.api.SendResult; import org.apache.eventmesh.api.exception.OnExceptionContext; -import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.protocol.ProtocolTransportObject; import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody; @@ -33,6 +29,7 @@ import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageRequestHeader; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageResponseHeader; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.protocol.api.ProtocolAdaptor; import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; import org.apache.eventmesh.runtime.acl.Acl; @@ -45,13 +42,17 @@ import org.apache.eventmesh.runtime.core.protocol.http.producer.SendMessageContext; import org.apache.eventmesh.runtime.util.EventMeshUtil; import org.apache.eventmesh.runtime.util.RemotingHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.util.Objects; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; import io.netty.channel.ChannelHandlerContext; public class SendAsyncMessageProcessor implements HttpRequestProcessor { @@ -75,15 +76,17 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext HttpCommand responseEventMeshCommand; - cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), + cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", RequestCode.get( + Integer.valueOf(asyncContext.getRequest().getRequestCode())), EventMeshConstants.PROTOCOL_HTTP, RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); SendMessageRequestHeader sendMessageRequestHeader = (SendMessageRequestHeader) asyncContext.getRequest().getHeader(); -// SendMessageRequestBody sendMessageRequestBody = (SendMessageRequestBody) asyncContext.getRequest().getBody(); + //SendMessageRequestBody sendMessageRequestBody = (SendMessageRequestBody) asyncContext.getRequest().getBody(); SendMessageResponseHeader sendMessageResponseHeader = - SendMessageResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, + SendMessageResponseHeader.buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, IPUtils.getLocalAddress(), eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); @@ -100,7 +103,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || StringUtils.isBlank(event.getSubject())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageResponseHeader, - SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -116,7 +120,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || StringUtils.isBlank(sys)) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageResponseHeader, - SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -134,13 +139,14 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || event.getData() == null) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageResponseHeader, - SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } //do acl check - if(eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerSecurityEnable) { + if (eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerSecurityEnable) { String remoteAddr = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); String user = event.getExtension(ProtocolKey.ClientInstanceKey.USERNAME).toString(); String pass = event.getExtension(ProtocolKey.ClientInstanceKey.PASSWD).toString(); @@ -148,7 +154,7 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext int requestCode = Integer.parseInt(asyncContext.getRequest().getRequestCode()); try { Acl.doAclCheckInHttpSend(remoteAddr, user, pass, subsystem, topic, requestCode); - }catch (Exception e){ + } catch (Exception e) { //String errorMsg = String.format("CLIENT HAS NO PERMISSION,send failed, topic:%s, subsys:%s, realIp:%s", topic, subsys, realIp); responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( @@ -177,7 +183,8 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext if (!eventMeshProducer.getStarted().get()) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageResponseHeader, - SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getErrMsg())); + SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -190,30 +197,30 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext try { // body -// omsMsg.setBody(sendMessageRequestBody.getContent().getBytes(EventMeshConstants.DEFAULT_CHARSET)); -// // topic -// omsMsg.setTopic(sendMessageRequestBody.getTopic()); -// omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION, sendMessageRequestBody.getTopic()); -// -// if (!StringUtils.isBlank(sendMessageRequestBody.getTag())) { -// omsMsg.putUserProperties(EventMeshConstants.TAG, sendMessageRequestBody.getTag()); -// } + //omsMsg.setBody(sendMessageRequestBody.getContent().getBytes(EventMeshConstants.DEFAULT_CHARSET)); + //// topic + //omsMsg.setTopic(sendMessageRequestBody.getTopic()); + //omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION, sendMessageRequestBody.getTopic()); + // + //if (!StringUtils.isBlank(sendMessageRequestBody.getTag())) { + // omsMsg.putUserProperties(EventMeshConstants.TAG, sendMessageRequestBody.getTag()); + //} // ttl -// omsMsg.putUserProperties(Constants.PROPERTY_MESSAGE_TIMEOUT, ttl); -// // bizNo -// omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_SEARCH_KEYS, sendMessageRequestBody.getBizSeqNo()); + //omsMsg.putUserProperties(Constants.PROPERTY_MESSAGE_TIMEOUT, ttl); + //// bizNo + //omsMsg.putSystemProperties(Constants.PROPERTY_MESSAGE_SEARCH_KEYS, sendMessageRequestBody.getBizSeqNo()); event = CloudEventBuilder.from(event) .withExtension("msgtype", "persistent") .withExtension(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())) .withExtension(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, String.valueOf(System.currentTimeMillis())) .build(); -// omsMsg.putUserProperties("msgType", "persistent"); -// omsMsg.putUserProperties(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())); -// omsMsg.putUserProperties(Constants.RMB_UNIQ_ID, sendMessageRequestBody.getUniqueId()); -// omsMsg.putUserProperties(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, String.valueOf(System.currentTimeMillis())); + //omsMsg.putUserProperties("msgType", "persistent"); + //omsMsg.putUserProperties(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())); + //omsMsg.putUserProperties(Constants.RMB_UNIQ_ID, sendMessageRequestBody.getUniqueId()); + //omsMsg.putUserProperties(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, String.valueOf(System.currentTimeMillis())); // new rocketmq client can't support put DeFiBusConstant.PROPERTY_MESSAGE_TTL -// rocketMQMsg.putUserProperty(DeFiBusConstant.PROPERTY_MESSAGE_TTL, ttl); + //rocketMQMsg.putUserProperty(DeFiBusConstant.PROPERTY_MESSAGE_TTL, ttl); if (messageLogger.isDebugEnabled()) { messageLogger.debug("msg2MQMsg suc, bizSeqNo={}, topic={}", bizNo, topic); @@ -222,12 +229,14 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext messageLogger.error("msg2MQMsg err, bizSeqNo={}, topic={}", bizNo, topic, e); responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( sendMessageResponseHeader, - SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getRetCode(), EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(e, 2))); + SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(e, 2))); asyncContext.onComplete(responseEventMeshCommand); return; } - final SendMessageContext sendMessageContext = new SendMessageContext(bizNo, event, eventMeshProducer, eventMeshHTTPServer); + final SendMessageContext sendMessageContext = new SendMessageContext(bizNo, event, eventMeshProducer, + eventMeshHTTPServer); eventMeshHTTPServer.metrics.summaryMetrics.recordSendMsg(); long startTime = System.currentTimeMillis(); @@ -240,8 +249,10 @@ public void onResponse(HttpCommand httpCommand) { httpLogger.debug("{}", httpCommand); } eventMeshHTTPServer.sendResponse(ctx, httpCommand.httpResponse()); - eventMeshHTTPServer.metrics.summaryMetrics.recordHTTPReqResTimeCost(System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); + eventMeshHTTPServer.metrics.summaryMetrics.recordHTTPReqResTimeCost( + System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); } catch (Exception ex) { + //ignore } } }; @@ -258,7 +269,8 @@ public void onResponse(HttpCommand httpCommand) { public void onSuccess(SendResult sendResult) { HttpCommand succ = asyncContext.getRequest().createHttpCommandResponse( sendMessageResponseHeader, - SendMessageResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(), EventMeshRetCode.SUCCESS.getErrMsg() + sendResult.toString())); + SendMessageResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(), + EventMeshRetCode.SUCCESS.getErrMsg() + sendResult.toString())); asyncContext.onComplete(succ, handler); long endTime = System.currentTimeMillis(); eventMeshHTTPServer.metrics.summaryMetrics.recordSendMsgCost(endTime - startTime); @@ -271,7 +283,8 @@ public void onException(OnExceptionContext context) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(context.getException(), 2))); + EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getErrMsg() + + EventMeshUtil.stackTrace(context.getException(), 2))); asyncContext.onComplete(err, handler); eventMeshHTTPServer.getHttpRetryer().pushRetry(sendMessageContext.delay(10000)); @@ -286,7 +299,8 @@ public void onException(OnExceptionContext context) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( sendMessageResponseHeader, SendMessageResponseBody.buildBody(EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getErrMsg() + EventMeshUtil.stackTrace(ex, 2))); + EventMeshRetCode.EVENTMESH_SEND_ASYNC_MSG_ERR.getErrMsg() + + EventMeshUtil.stackTrace(ex, 2))); asyncContext.onComplete(err); eventMeshHTTPServer.getHttpRetryer().pushRetry(sendMessageContext.delay(10000)); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendSyncMessageProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendSyncMessageProcessor.java index dff902ab5d..dc43e53b02 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendSyncMessageProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SendSyncMessageProcessor.java @@ -17,11 +17,7 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; -import io.cloudevents.CloudEvent; -import io.cloudevents.core.builder.CloudEventBuilder; - import org.apache.eventmesh.api.RequestReplyCallback; -import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.protocol.ProtocolTransportObject; import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageRequestBody; @@ -30,6 +26,7 @@ import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.protocol.http.header.message.SendMessageResponseHeader; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.protocol.api.ProtocolAdaptor; import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; @@ -52,6 +49,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; import io.netty.channel.ChannelHandlerContext; public class SendSyncMessageProcessor implements HttpRequestProcessor { @@ -72,25 +71,25 @@ public SendSyncMessageProcessor(EventMeshHTTPServer eventMeshHTTPServer) { @Override public void processRequest(ChannelHandlerContext ctx, AsyncContext asyncContext) - throws Exception { + throws Exception { HttpCommand responseEventMeshCommand; cmdLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", - RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), - EventMeshConstants.PROTOCOL_HTTP, - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); + RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), + EventMeshConstants.PROTOCOL_HTTP, + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); ProtocolAdaptor httpCommandProtocolAdaptor = ProtocolPluginFactory.getProtocolAdaptor("cloudevents"); CloudEvent event = httpCommandProtocolAdaptor.toCloudEvent(asyncContext.getRequest()); SendMessageResponseHeader sendMessageResponseHeader = - SendMessageResponseHeader - .buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, - IPUtils.getLocalAddress(), - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + SendMessageResponseHeader + .buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, + IPUtils.getLocalAddress(), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); //validate event if (event == null @@ -100,58 +99,58 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || StringUtils.isBlank(event.getType()) || StringUtils.isBlank(event.getSubject())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + sendMessageResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } String idc = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.IDC)) - .toString(); + .toString(); String pid = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.PID)) - .toString(); + .toString(); String sys = Objects.requireNonNull(event.getExtension(ProtocolKey.ClientInstanceKey.SYS)) - .toString(); + .toString(); //validate event-extension if (StringUtils.isBlank(idc) - || StringUtils.isBlank(pid) - || !StringUtils.isNumeric(pid) - || StringUtils.isBlank(sys)) { + || StringUtils.isBlank(pid) + || !StringUtils.isNumeric(pid) + || StringUtils.isBlank(sys)) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + sendMessageResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } String bizNo = - Objects.requireNonNull(event.getExtension(SendMessageRequestBody.BIZSEQNO)).toString(); + Objects.requireNonNull(event.getExtension(SendMessageRequestBody.BIZSEQNO)).toString(); String uniqueId = - Objects.requireNonNull(event.getExtension(SendMessageRequestBody.UNIQUEID)).toString(); + Objects.requireNonNull(event.getExtension(SendMessageRequestBody.UNIQUEID)).toString(); String producerGroup = - Objects.requireNonNull(event.getExtension(SendMessageRequestBody.PRODUCERGROUP)) - .toString(); + Objects.requireNonNull(event.getExtension(SendMessageRequestBody.PRODUCERGROUP)) + .toString(); String topic = event.getSubject(); String ttl = - Objects.requireNonNull(event.getExtension(SendMessageRequestBody.TTL)).toString(); + Objects.requireNonNull(event.getExtension(SendMessageRequestBody.TTL)).toString(); //validate body if (StringUtils.isBlank(bizNo) - || StringUtils.isBlank(uniqueId) - || StringUtils.isBlank(producerGroup) - || StringUtils.isBlank(topic) - || event.getData() == null - || StringUtils.isBlank(ttl)) { + || StringUtils.isBlank(uniqueId) + || StringUtils.isBlank(producerGroup) + || StringUtils.isBlank(topic) + || event.getData() == null + || StringUtils.isBlank(ttl)) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + sendMessageResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -168,10 +167,10 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext } catch (Exception e) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_ACL_ERR.getRetCode(), - e.getMessage())); + sendMessageResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_ACL_ERR.getRetCode(), + e.getMessage())); asyncContext.onComplete(responseEventMeshCommand); aclLogger.warn("CLIENT HAS NO PERMISSION,SendSyncMessageProcessor send failed", e); return; @@ -180,27 +179,27 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext // control flow rate limit if (!eventMeshHTTPServer.getMsgRateLimiter() - .tryAcquire(EventMeshConstants.DEFAULT_FASTFAIL_TIMEOUT_IN_MILLISECONDS, - TimeUnit.MILLISECONDS)) { + .tryAcquire(EventMeshConstants.DEFAULT_FASTFAIL_TIMEOUT_IN_MILLISECONDS, + TimeUnit.MILLISECONDS)) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_HTTP_MES_SEND_OVER_LIMIT_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_HTTP_MES_SEND_OVER_LIMIT_ERR.getErrMsg())); + sendMessageResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_HTTP_MES_SEND_OVER_LIMIT_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_HTTP_MES_SEND_OVER_LIMIT_ERR.getErrMsg())); eventMeshHTTPServer.metrics.summaryMetrics.recordHTTPDiscard(); asyncContext.onComplete(responseEventMeshCommand); return; } EventMeshProducer eventMeshProducer = - eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup); + eventMeshHTTPServer.getProducerManager().getEventMeshProducer(producerGroup); if (!eventMeshProducer.getStarted().get()) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getErrMsg())); + sendMessageResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_GROUP_PRODUCER_STOPED_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -219,18 +218,18 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext } catch (Exception e) { messageLogger.error("msg2MQMsg err, bizSeqNo={}, topic={}", bizNo, topic, e); responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getErrMsg() - + EventMeshUtil.stackTrace(e, 2))); + sendMessageResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PACKAGE_MSG_ERR.getErrMsg() + + EventMeshUtil.stackTrace(e, 2))); asyncContext.onComplete(responseEventMeshCommand); return; } final SendMessageContext sendMessageContext = - new SendMessageContext(bizNo, event, eventMeshProducer, - eventMeshHTTPServer); + new SendMessageContext(bizNo, event, eventMeshProducer, + eventMeshHTTPServer); eventMeshHTTPServer.metrics.summaryMetrics.recordSendMsg(); long startTime = System.currentTimeMillis(); @@ -244,7 +243,7 @@ public void onResponse(HttpCommand httpCommand) { } eventMeshHTTPServer.sendResponse(ctx, httpCommand.httpResponse()); eventMeshHTTPServer.metrics.summaryMetrics.recordHTTPReqResTimeCost( - System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); + System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); } catch (Exception ex) { // ignore } @@ -257,35 +256,35 @@ public void onResponse(HttpCommand httpCommand) { @Override public void onSuccess(CloudEvent event) { messageLogger.info("message|mq2eventMesh|RSP|SYNC|rrCost={}ms|topic={}" - + "|bizSeqNo={}|uniqueId={}", System.currentTimeMillis() - startTime, - topic, bizNo, uniqueId); + + "|bizSeqNo={}|uniqueId={}", System.currentTimeMillis() - startTime, + topic, bizNo, uniqueId); try { event = CloudEventBuilder.from(event) .withExtension(EventMeshConstants.RSP_EVENTMESH2C_TIMESTAMP, - String.valueOf(System.currentTimeMillis())) - .withExtension(EventMeshConstants.RSP_MQ2EVENTMESH_TIMESTAMP, - String.valueOf(System.currentTimeMillis())) - .build(); + String.valueOf(System.currentTimeMillis())) + .withExtension(EventMeshConstants.RSP_MQ2EVENTMESH_TIMESTAMP, + String.valueOf(System.currentTimeMillis())) + .build(); final String rtnMsg = new String(event.getData().toBytes(), - EventMeshConstants.DEFAULT_CHARSET); + EventMeshConstants.DEFAULT_CHARSET); HttpCommand succ = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(), - JsonUtils.serialize(SendMessageResponseBody.ReplyMessage.builder() - .topic(topic) - .body(rtnMsg) - .properties(EventMeshUtil.getEventProp(event)) - .build()))); + sendMessageResponseHeader, + SendMessageResponseBody.buildBody(EventMeshRetCode.SUCCESS.getRetCode(), + JsonUtils.serialize(SendMessageResponseBody.ReplyMessage.builder() + .topic(topic) + .body(rtnMsg) + .properties(EventMeshUtil.getEventProp(event)) + .build()))); asyncContext.onComplete(succ, handler); } catch (Exception ex) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody.buildBody( - EventMeshRetCode.EVENTMESH_WAITING_RR_MSG_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_WAITING_RR_MSG_ERR.getErrMsg() - + EventMeshUtil.stackTrace(ex, 2))); + sendMessageResponseHeader, + SendMessageResponseBody.buildBody( + EventMeshRetCode.EVENTMESH_WAITING_RR_MSG_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_WAITING_RR_MSG_ERR.getErrMsg() + + EventMeshUtil.stackTrace(ex, 2))); asyncContext.onComplete(err, handler); messageLogger.warn("message|mq2eventMesh|RSP", ex); } @@ -294,27 +293,27 @@ public void onSuccess(CloudEvent event) { @Override public void onException(Throwable e) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_WAITING_RR_MSG_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_WAITING_RR_MSG_ERR.getErrMsg() - + EventMeshUtil.stackTrace(e, 2))); + sendMessageResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_WAITING_RR_MSG_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_WAITING_RR_MSG_ERR.getErrMsg() + + EventMeshUtil.stackTrace(e, 2))); asyncContext.onComplete(err, handler); eventMeshHTTPServer.getHttpRetryer().pushRetry(sendMessageContext.delay(10000)); messageLogger.error( - "message|mq2eventMesh|RSP|SYNC|rrCost={}ms|topic={}" - + "|bizSeqNo={}|uniqueId={}", System.currentTimeMillis() - startTime, - topic, bizNo, uniqueId, e); + "message|mq2eventMesh|RSP|SYNC|rrCost={}ms|topic={}" + + "|bizSeqNo={}|uniqueId={}", System.currentTimeMillis() - startTime, + topic, bizNo, uniqueId, e); } }, Integer.parseInt(ttl)); } catch (Exception ex) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( - sendMessageResponseHeader, - SendMessageResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_SEND_SYNC_MSG_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_SEND_SYNC_MSG_ERR.getErrMsg() - + EventMeshUtil.stackTrace(ex, 2))); + sendMessageResponseHeader, + SendMessageResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_SEND_SYNC_MSG_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_SEND_SYNC_MSG_ERR.getErrMsg() + + EventMeshUtil.stackTrace(ex, 2))); asyncContext.onComplete(err); eventMeshHTTPServer.getHttpRetryer().pushRetry(sendMessageContext.delay(10000)); @@ -322,8 +321,8 @@ public void onException(Throwable e) { eventMeshHTTPServer.metrics.summaryMetrics.recordSendMsgFailed(); eventMeshHTTPServer.metrics.summaryMetrics.recordSendMsgCost(endTime - startTime); messageLogger.error( - "message|eventMesh2mq|REQ|SYNC|send2MQCost={}ms|topic={}|bizSeqNo={}|uniqueId={}", - endTime - startTime, topic, bizNo, uniqueId, ex); + "message|eventMesh2mq|REQ|SYNC|send2MQCost={}ms|topic={}|bizSeqNo={}|uniqueId={}", + endTime - startTime, topic, bizNo, uniqueId, ex); } return; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java index 0c75e7ab03..98aed2c50f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/SubscribeProcessor.java @@ -17,9 +17,8 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; -import org.apache.eventmesh.common.utils.IPUtils; -import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.SubscriptionItem; +import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.body.client.SubscribeRequestBody; import org.apache.eventmesh.common.protocol.http.body.client.SubscribeResponseBody; import org.apache.eventmesh.common.protocol.http.body.message.SendMessageResponseBody; @@ -27,6 +26,7 @@ import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.protocol.http.header.client.SubscribeRequestHeader; import org.apache.eventmesh.common.protocol.http.header.client.SubscribeResponseHeader; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.acl.Acl; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; @@ -76,31 +76,31 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext final Integer requestCode = Integer.valueOf(asyncContext.getRequest().getRequestCode()); httpLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", - RequestCode.get(requestCode), - EventMeshConstants.PROTOCOL_HTTP, - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress() + RequestCode.get(requestCode), + EventMeshConstants.PROTOCOL_HTTP, + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress() ); SubscribeRequestHeader subscribeRequestHeader = (SubscribeRequestHeader) request.getHeader(); SubscribeRequestBody subscribeRequestBody = (SubscribeRequestBody) request.getBody(); SubscribeResponseHeader subscribeResponseHeader = - SubscribeResponseHeader - .buildHeader(requestCode, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, - IPUtils.getLocalAddress(), - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + SubscribeResponseHeader + .buildHeader(requestCode, + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, + IPUtils.getLocalAddress(), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); //validate header if (StringUtils.isBlank(subscribeRequestHeader.getIdc()) - || StringUtils.isBlank(subscribeRequestHeader.getPid()) - || !StringUtils.isNumeric(subscribeRequestHeader.getPid()) - || StringUtils.isBlank(subscribeRequestHeader.getSys())) { + || StringUtils.isBlank(subscribeRequestHeader.getPid()) + || !StringUtils.isNumeric(subscribeRequestHeader.getPid()) + || StringUtils.isBlank(subscribeRequestHeader.getSys())) { responseEventMeshCommand = request.createHttpCommandResponse( - subscribeResponseHeader, - SubscribeResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + subscribeResponseHeader, + SubscribeResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -111,10 +111,10 @@ public void processRequest(ChannelHandlerContext ctx, AsyncContext || StringUtils.isBlank(subscribeRequestBody.getConsumerGroup())) { responseEventMeshCommand = request.createHttpCommandResponse( - subscribeResponseHeader, - SubscribeResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + subscribeResponseHeader, + SubscribeResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -234,7 +234,7 @@ public void onResponse(HttpCommand httpCommand) { } eventMeshHTTPServer.sendResponse(ctx, httpCommand.httpResponse()); eventMeshHTTPServer.metrics.summaryMetrics.recordHTTPReqResTimeCost( - System.currentTimeMillis() - request.getReqTime()); + System.currentTimeMillis() - request.getReqTime()); } catch (Exception ex) { // ignore } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/UnSubscribeProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/UnSubscribeProcessor.java index 7d9eb87e1a..3e1c2a1c5e 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/UnSubscribeProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/UnSubscribeProcessor.java @@ -17,7 +17,6 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor; -import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.body.client.UnSubscribeRequestBody; import org.apache.eventmesh.common.protocol.http.body.client.UnSubscribeResponseBody; @@ -25,6 +24,7 @@ import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.protocol.http.header.client.UnSubscribeRequestHeader; import org.apache.eventmesh.common.protocol.http.header.client.UnSubscribeResponseHeader; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -66,49 +66,49 @@ public UnSubscribeProcessor(EventMeshHTTPServer eventMeshHTTPServer) { @Override public void processRequest(ChannelHandlerContext ctx, AsyncContext asyncContext) - throws Exception { + throws Exception { HttpCommand responseEventMeshCommand; httpLogger.info("cmd={}|{}|client2eventMesh|from={}|to={}", - RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), - EventMeshConstants.PROTOCOL_HTTP, - RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); + RequestCode.get(Integer.valueOf(asyncContext.getRequest().getRequestCode())), + EventMeshConstants.PROTOCOL_HTTP, + RemotingHelper.parseChannelRemoteAddr(ctx.channel()), IPUtils.getLocalAddress()); UnSubscribeRequestHeader unSubscribeRequestHeader = - (UnSubscribeRequestHeader) asyncContext.getRequest().getHeader(); + (UnSubscribeRequestHeader) asyncContext.getRequest().getHeader(); UnSubscribeRequestBody unSubscribeRequestBody = - (UnSubscribeRequestBody) asyncContext.getRequest().getBody(); + (UnSubscribeRequestBody) asyncContext.getRequest().getBody(); UnSubscribeResponseHeader unSubscribeResponseHeader = - UnSubscribeResponseHeader - .buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, - IPUtils.getLocalAddress(), - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, - eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); + UnSubscribeResponseHeader + .buildHeader(Integer.valueOf(asyncContext.getRequest().getRequestCode()), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshCluster, + IPUtils.getLocalAddress(), + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshEnv, + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshIDC); //validate header if (StringUtils.isBlank(unSubscribeRequestHeader.getIdc()) - || StringUtils.isBlank(unSubscribeRequestHeader.getPid()) - || !StringUtils.isNumeric(unSubscribeRequestHeader.getPid()) - || StringUtils.isBlank(unSubscribeRequestHeader.getSys())) { + || StringUtils.isBlank(unSubscribeRequestHeader.getPid()) + || !StringUtils.isNumeric(unSubscribeRequestHeader.getPid()) + || StringUtils.isBlank(unSubscribeRequestHeader.getSys())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - unSubscribeResponseHeader, - UnSubscribeResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); + unSubscribeResponseHeader, + UnSubscribeResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_HEADER_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } //validate body if (StringUtils.isBlank(unSubscribeRequestBody.getUrl()) - || CollectionUtils.isEmpty(unSubscribeRequestBody.getTopics()) - || StringUtils.isBlank(unSubscribeRequestBody.getConsumerGroup())) { + || CollectionUtils.isEmpty(unSubscribeRequestBody.getTopics()) + || StringUtils.isBlank(unSubscribeRequestBody.getConsumerGroup())) { responseEventMeshCommand = asyncContext.getRequest().createHttpCommandResponse( - unSubscribeResponseHeader, - UnSubscribeResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); + unSubscribeResponseHeader, + UnSubscribeResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_PROTOCOL_BODY_ERR.getErrMsg())); asyncContext.onComplete(responseEventMeshCommand); return; } @@ -130,7 +130,7 @@ public void onResponse(HttpCommand httpCommand) { } eventMeshHTTPServer.sendResponse(ctx, httpCommand.httpResponse()); eventMeshHTTPServer.metrics.summaryMetrics.recordHTTPReqResTimeCost( - System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); + System.currentTimeMillis() - asyncContext.getRequest().getReqTime()); } catch (Exception ex) { // ignore } @@ -144,12 +144,12 @@ public void onResponse(HttpCommand httpCommand) { for (String unSubTopic : unSubTopicList) { List groupTopicClients = eventMeshHTTPServer.localClientInfoMapping - .get(consumerGroup + "@" + unSubTopic); + .get(consumerGroup + "@" + unSubTopic); Iterator clientIterator = groupTopicClients.iterator(); while (clientIterator.hasNext()) { Client client = clientIterator.next(); if (StringUtils.equals(client.pid, pid) - && StringUtils.equals(client.url, unSubscribeUrl)) { + && StringUtils.equals(client.url, unSubscribeUrl)) { httpLogger.warn("client {} start unsubscribe", JsonUtils.serialize(client)); clientIterator.remove(); } @@ -164,7 +164,7 @@ public void onResponse(HttpCommand httpCommand) { clientUrls.add(client.url); if (idcUrls.containsKey(client.idc)) { idcUrls.get(client.idc) - .add(StringUtils.deleteWhitespace(client.url)); + .add(StringUtils.deleteWhitespace(client.url)); } else { List urls = new ArrayList<>(); urls.add(client.url); @@ -175,18 +175,18 @@ public void onResponse(HttpCommand httpCommand) { } synchronized (eventMeshHTTPServer.localConsumerGroupMapping) { ConsumerGroupConf consumerGroupConf = - eventMeshHTTPServer.localConsumerGroupMapping.get(consumerGroup); + eventMeshHTTPServer.localConsumerGroupMapping.get(consumerGroup); Map map = - consumerGroupConf.getConsumerGroupTopicConf(); + consumerGroupConf.getConsumerGroupTopicConf(); for (String topicKey : map.keySet()) { // only modify the topic to subscribe if (StringUtils.equals(unSubTopic, topicKey)) { ConsumerGroupTopicConf latestTopicConf = - new ConsumerGroupTopicConf(); + new ConsumerGroupTopicConf(); latestTopicConf.setConsumerGroup(consumerGroup); latestTopicConf.setTopic(unSubTopic); latestTopicConf - .setSubscriptionItem(map.get(topicKey).getSubscriptionItem()); + .setSubscriptionItem(map.get(topicKey).getSubscriptionItem()); latestTopicConf.setUrls(clientUrls); latestTopicConf.setIdcUrls(idcUrls); @@ -195,7 +195,7 @@ public void onResponse(HttpCommand httpCommand) { } } eventMeshHTTPServer.localConsumerGroupMapping - .put(consumerGroup, consumerGroupConf); + .put(consumerGroup, consumerGroupConf); } } else { isChange = false; @@ -206,61 +206,61 @@ public void onResponse(HttpCommand httpCommand) { if (isChange) { try { eventMeshHTTPServer.getConsumerManager().notifyConsumerManager(consumerGroup, - eventMeshHTTPServer.localConsumerGroupMapping.get(consumerGroup)); + eventMeshHTTPServer.localConsumerGroupMapping.get(consumerGroup)); responseEventMeshCommand = - asyncContext.getRequest().createHttpCommandResponse(EventMeshRetCode.SUCCESS); + asyncContext.getRequest().createHttpCommandResponse(EventMeshRetCode.SUCCESS); asyncContext.onComplete(responseEventMeshCommand, handler); } catch (Exception e) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( - unSubscribeResponseHeader, - UnSubscribeResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_UNSUBSCRIBE_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_UNSUBSCRIBE_ERR.getErrMsg() - + EventMeshUtil.stackTrace(e, 2))); + unSubscribeResponseHeader, + UnSubscribeResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_UNSUBSCRIBE_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_UNSUBSCRIBE_ERR.getErrMsg() + + EventMeshUtil.stackTrace(e, 2))); asyncContext.onComplete(err); long endTime = System.currentTimeMillis(); httpLogger.error( - "message|eventMesh2mq|REQ|ASYNC|send2MQCost={}ms" - + "|topic={}|bizSeqNo={}|uniqueId={}", endTime - startTime, - JsonUtils.serialize(unSubscribeRequestBody.getTopics()), - unSubscribeRequestBody.getUrl(), e); + "message|eventMesh2mq|REQ|ASYNC|send2MQCost={}ms" + + "|topic={}|bizSeqNo={}|uniqueId={}", endTime - startTime, + JsonUtils.serialize(unSubscribeRequestBody.getTopics()), + unSubscribeRequestBody.getUrl(), e); eventMeshHTTPServer.metrics.summaryMetrics.recordSendMsgFailed(); eventMeshHTTPServer.metrics.summaryMetrics - .recordSendMsgCost(endTime - startTime); + .recordSendMsgCost(endTime - startTime); } } else { //remove try { eventMeshHTTPServer.getConsumerManager() - .notifyConsumerManager(consumerGroup, null); + .notifyConsumerManager(consumerGroup, null); responseEventMeshCommand = - asyncContext.getRequest().createHttpCommandResponse(EventMeshRetCode.SUCCESS); + asyncContext.getRequest().createHttpCommandResponse(EventMeshRetCode.SUCCESS); asyncContext.onComplete(responseEventMeshCommand, handler); // clean ClientInfo eventMeshHTTPServer.localClientInfoMapping.keySet() - .removeIf(s -> StringUtils.contains(s, consumerGroup)); + .removeIf(s -> StringUtils.contains(s, consumerGroup)); // clean ConsumerGroupInfo eventMeshHTTPServer.localConsumerGroupMapping.keySet() - .removeIf(s -> StringUtils.equals(consumerGroup, s)); + .removeIf(s -> StringUtils.equals(consumerGroup, s)); } catch (Exception e) { HttpCommand err = asyncContext.getRequest().createHttpCommandResponse( - unSubscribeResponseHeader, - UnSubscribeResponseBody - .buildBody(EventMeshRetCode.EVENTMESH_UNSUBSCRIBE_ERR.getRetCode(), - EventMeshRetCode.EVENTMESH_UNSUBSCRIBE_ERR.getErrMsg() - + EventMeshUtil.stackTrace(e, 2))); + unSubscribeResponseHeader, + UnSubscribeResponseBody + .buildBody(EventMeshRetCode.EVENTMESH_UNSUBSCRIBE_ERR.getRetCode(), + EventMeshRetCode.EVENTMESH_UNSUBSCRIBE_ERR.getErrMsg() + + EventMeshUtil.stackTrace(e, 2))); asyncContext.onComplete(err); long endTime = System.currentTimeMillis(); httpLogger.error( - "message|eventMesh2mq|REQ|ASYNC|send2MQCost={}ms" - + "|topic={}|bizSeqNo={}|uniqueId={}", endTime - startTime, - JsonUtils.serialize(unSubscribeRequestBody.getTopics()), - unSubscribeRequestBody.getUrl(), e); + "message|eventMesh2mq|REQ|ASYNC|send2MQCost={}ms" + + "|topic={}|bizSeqNo={}|uniqueId={}", endTime - startTime, + JsonUtils.serialize(unSubscribeRequestBody.getTopics()), + unSubscribeRequestBody.getUrl(), e); eventMeshHTTPServer.metrics.summaryMetrics.recordSendMsgFailed(); eventMeshHTTPServer.metrics.summaryMetrics - .recordSendMsgCost(endTime - startTime); + .recordSendMsgCost(endTime - startTime); } } } @@ -289,7 +289,7 @@ private void registerClient(UnSubscribeRequestHeader unSubscribeRequestHeader, String groupTopicKey = client.consumerGroup + "@" + client.topic; if (eventMeshHTTPServer.localClientInfoMapping.containsKey(groupTopicKey)) { List localClients = - eventMeshHTTPServer.localClientInfoMapping.get(groupTopicKey); + eventMeshHTTPServer.localClientInfoMapping.get(groupTopicKey); boolean isContains = false; for (Client localClient : localClients) { if (StringUtils.equals(localClient.url, client.url)) { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/Client.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/Client.java index 58711b16d1..119c1dea2e 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/Client.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/Client.java @@ -16,6 +16,7 @@ * specific language governing permissions and limitations * under the License. */ + package org.apache.eventmesh.runtime.core.protocol.http.processor.inf; import java.util.Date; @@ -48,16 +49,16 @@ public class Client { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("endPoint={env=").append(env) - .append(",idc=").append(idc) - .append(",consumerGroup=").append(consumerGroup) - .append(",topic=").append(topic) - .append(",url=").append(url) - .append(",sys=").append(sys) - .append(",ip=").append(ip) - .append(",pid=").append(pid) - .append(",hostname=").append(hostname) - .append(",apiVersion=").append(apiVersion) - .append(",registerTime=").append("}"); + .append(",idc=").append(idc) + .append(",consumerGroup=").append(consumerGroup) + .append(",topic=").append(topic) + .append(",url=").append(url) + .append(",sys=").append(sys) + .append(",ip=").append(ip) + .append(",pid=").append(pid) + .append(",hostname=").append(hostname) + .append(",apiVersion=").append(apiVersion) + .append(",registerTime=").append("}"); return sb.toString(); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/HttpRequestProcessor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/HttpRequestProcessor.java index 4f256d66e5..41354f44c3 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/HttpRequestProcessor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/processor/inf/HttpRequestProcessor.java @@ -17,11 +17,14 @@ package org.apache.eventmesh.runtime.core.protocol.http.processor.inf; -import io.netty.channel.ChannelHandlerContext; - import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.runtime.core.protocol.http.async.AsyncContext; +import io.netty.channel.ChannelHandlerContext; + +/** + * HttpRequestProcessor + */ public interface HttpRequestProcessor { void processRequest(final ChannelHandlerContext ctx, final AsyncContext asyncContext) diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/EventMeshProducer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/EventMeshProducer.java index 34c8d7d5d2..ff488d3fbc 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/EventMeshProducer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/EventMeshProducer.java @@ -17,15 +17,16 @@ package org.apache.eventmesh.runtime.core.protocol.http.producer; -import java.util.Properties; -import java.util.concurrent.atomic.AtomicBoolean; - import org.apache.eventmesh.api.RequestReplyCallback; import org.apache.eventmesh.api.SendCallback; import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration; import org.apache.eventmesh.runtime.core.consumergroup.ProducerGroupConf; import org.apache.eventmesh.runtime.core.plugin.MQProducerWrapper; import org.apache.eventmesh.runtime.util.EventMeshUtil; + +import java.util.Properties; +import java.util.concurrent.atomic.AtomicBoolean; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -69,13 +70,15 @@ public MQProducerWrapper getMqProducerWrapper() { return mqProducerWrapper; } - public synchronized void init(EventMeshHTTPConfiguration eventMeshHttpConfiguration, ProducerGroupConf producerGroupConfig) throws Exception { + public synchronized void init(EventMeshHTTPConfiguration eventMeshHttpConfiguration, + ProducerGroupConf producerGroupConfig) throws Exception { this.producerGroupConfig = producerGroupConfig; this.eventMeshHttpConfiguration = eventMeshHttpConfiguration; Properties keyValue = new Properties(); keyValue.put("producerGroup", producerGroupConfig.getGroupName()); - keyValue.put("instanceName", EventMeshUtil.buildMeshClientID(producerGroupConfig.getGroupName(), eventMeshHttpConfiguration.eventMeshCluster)); + keyValue.put("instanceName", EventMeshUtil.buildMeshClientID(producerGroupConfig.getGroupName(), + eventMeshHttpConfiguration.eventMeshCluster)); //TODO for defibus keyValue.put("eventMeshIDC", eventMeshHttpConfiguration.eventMeshIDC); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/ProducerManager.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/ProducerManager.java index 7e66dab935..ebf65b4e50 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/ProducerManager.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/ProducerManager.java @@ -17,10 +17,11 @@ package org.apache.eventmesh.runtime.core.protocol.http.producer; -import java.util.concurrent.ConcurrentHashMap; - import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.core.consumergroup.ProducerGroupConf; + +import java.util.concurrent.ConcurrentHashMap; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/SendMessageContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/SendMessageContext.java index 8569951014..3153b55177 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/SendMessageContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/producer/SendMessageContext.java @@ -17,22 +17,24 @@ package org.apache.eventmesh.runtime.core.protocol.http.producer; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import io.cloudevents.CloudEvent; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.api.SendCallback; import org.apache.eventmesh.api.SendResult; import org.apache.eventmesh.api.exception.OnExceptionContext; import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.core.protocol.http.retry.RetryContext; + +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; + public class SendMessageContext extends RetryContext { public static Logger logger = LoggerFactory.getLogger("retry"); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AbstractHTTPPushRequest.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AbstractHTTPPushRequest.java index e7294b837c..dd60a622c5 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AbstractHTTPPushRequest.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AbstractHTTPPushRequest.java @@ -17,16 +17,6 @@ package org.apache.eventmesh.runtime.core.protocol.http.push; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.atomic.AtomicBoolean; - -import com.google.common.collect.Lists; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.RandomUtils; import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -34,6 +24,17 @@ import org.apache.eventmesh.runtime.core.protocol.http.retry.HttpRetryer; import org.apache.eventmesh.runtime.core.protocol.http.retry.RetryContext; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.RandomUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicBoolean; + +import com.google.common.collect.Lists; + public abstract class AbstractHTTPPushRequest extends RetryContext { public EventMeshHTTPServer eventMeshHTTPServer; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java index 43750ad446..8d687a2c60 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/AsyncHTTPPushRequest.java @@ -17,21 +17,19 @@ package org.apache.eventmesh.runtime.core.protocol.http.push; -import io.cloudevents.CloudEvent; -import io.cloudevents.core.builder.CloudEventBuilder; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.http.HttpCommand; -import org.apache.eventmesh.common.utils.IPUtils; -import org.apache.eventmesh.common.protocol.ProtocolTransportObject; -import org.apache.eventmesh.common.utils.RandomStringUtils; import org.apache.eventmesh.common.exception.JsonException; +import org.apache.eventmesh.common.protocol.ProtocolTransportObject; import org.apache.eventmesh.common.protocol.SubscriptionType; +import org.apache.eventmesh.common.protocol.http.HttpCommand; import org.apache.eventmesh.common.protocol.http.body.message.PushMessageRequestBody; import org.apache.eventmesh.common.protocol.http.common.ClientRetCode; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.common.RequestCode; +import org.apache.eventmesh.common.utils.IPUtils; import org.apache.eventmesh.common.utils.JsonUtils; +import org.apache.eventmesh.common.utils.RandomStringUtils; import org.apache.eventmesh.protocol.api.ProtocolAdaptor; import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -52,11 +50,18 @@ import java.io.IOException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; + import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.collect.Sets; @@ -101,13 +106,13 @@ public void tryHTTPRequest() { builder.addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA); builder.addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()); builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHCLUSTER, - handleMsgContext.getEventMeshHTTPServer() - .getEventMeshHttpConfiguration().eventMeshCluster); + handleMsgContext.getEventMeshHTTPServer() + .getEventMeshHttpConfiguration().eventMeshCluster); builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHIP, IPUtils.getLocalAddress()); builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHENV, - handleMsgContext.getEventMeshHTTPServer().getEventMeshHttpConfiguration().eventMeshEnv); + handleMsgContext.getEventMeshHTTPServer().getEventMeshHttpConfiguration().eventMeshEnv); builder.addHeader(ProtocolKey.EventMeshInstanceKey.EVENTMESHIDC, - handleMsgContext.getEventMeshHTTPServer().getEventMeshHttpConfiguration().eventMeshIDC); + handleMsgContext.getEventMeshHTTPServer().getEventMeshHttpConfiguration().eventMeshIDC); CloudEvent event = CloudEventBuilder.from(handleMsgContext.getEvent()) .withExtension(EventMeshConstants.REQ_EVENTMESH2C_TIMESTAMP, @@ -122,7 +127,7 @@ public void tryHTTPRequest() { ProtocolAdaptor protocolAdaptor = ProtocolPluginFactory.getProtocolAdaptor(protocolType); ProtocolTransportObject protocolTransportObject = - protocolAdaptor.fromCloudEvent(handleMsgContext.getEvent()); + protocolAdaptor.fromCloudEvent(handleMsgContext.getEvent()); content = ((HttpCommand) protocolTransportObject).getBody().toMap().get("content").toString(); } catch (Exception ex) { return; @@ -132,25 +137,25 @@ public void tryHTTPRequest() { body.add(new BasicNameValuePair(PushMessageRequestBody.CONTENT, content)); if (StringUtils.isBlank(handleMsgContext.getBizSeqNo())) { body.add(new BasicNameValuePair(PushMessageRequestBody.BIZSEQNO, - RandomStringUtils.generateNum(20))); + RandomStringUtils.generateNum(20))); } else { body.add(new BasicNameValuePair(PushMessageRequestBody.BIZSEQNO, - handleMsgContext.getBizSeqNo())); + handleMsgContext.getBizSeqNo())); } if (StringUtils.isBlank(handleMsgContext.getUniqueId())) { body.add(new BasicNameValuePair(PushMessageRequestBody.UNIQUEID, - RandomStringUtils.generateNum(20))); + RandomStringUtils.generateNum(20))); } else { body.add(new BasicNameValuePair(PushMessageRequestBody.UNIQUEID, - handleMsgContext.getUniqueId())); + handleMsgContext.getUniqueId())); } body.add(new BasicNameValuePair(PushMessageRequestBody.RANDOMNO, - handleMsgContext.getMsgRandomNo())); + handleMsgContext.getMsgRandomNo())); body.add(new BasicNameValuePair(PushMessageRequestBody.TOPIC, handleMsgContext.getTopic())); body.add(new BasicNameValuePair(PushMessageRequestBody.EXTFIELDS, - JsonUtils.serialize(EventMeshUtil.getEventProp(handleMsgContext.getEvent())))); + JsonUtils.serialize(EventMeshUtil.getEventProp(handleMsgContext.getEvent())))); builder.setEntity(new UrlEncodedFormEntity(body, StandardCharsets.UTF_8)); @@ -161,7 +166,7 @@ public void tryHTTPRequest() { addToWaitingMap(this); cmdLogger.info("cmd={}|eventMesh2client|from={}|to={}", requestCode, - IPUtils.getLocalAddress(), currPushUrl); + IPUtils.getLocalAddress(), currPushUrl); try { httpClientPool.getClient().execute(builder, new ResponseHandler() { @@ -173,9 +178,9 @@ public Object handleResponse(HttpResponse response) { if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { eventMeshHTTPServer.metrics.summaryMetrics.recordHttpPushMsgFailed(); messageLogger.info( - "message|eventMesh2client|exception|url={}|topic={}|bizSeqNo={}" - + "|uniqueId={}|cost={}", currPushUrl, handleMsgContext.getTopic(), - handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), cost); + "message|eventMesh2client|exception|url={}|topic={}|bizSeqNo={}" + + "|uniqueId={}|cost={}", currPushUrl, handleMsgContext.getTopic(), + handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), cost); delayRetry(); if (isComplete()) { @@ -185,17 +190,17 @@ public Object handleResponse(HttpResponse response) { String res = ""; try { res = EntityUtils.toString(response.getEntity(), - Charset.forName(EventMeshConstants.DEFAULT_CHARSET)); + Charset.forName(EventMeshConstants.DEFAULT_CHARSET)); } catch (IOException e) { handleMsgContext.finish(); return new Object(); } ClientRetCode result = processResponseContent(res); messageLogger.info( - "message|eventMesh2client|{}|url={}|topic={}|bizSeqNo={}" - + "|uniqueId={}|cost={}", - result, currPushUrl, handleMsgContext.getTopic(), - handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), cost); + "message|eventMesh2client|{}|url={}|topic={}|bizSeqNo={}" + + "|uniqueId={}|cost={}", + result, currPushUrl, handleMsgContext.getTopic(), + handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), cost); if (result == ClientRetCode.OK) { complete(); if (isComplete()) { @@ -224,13 +229,13 @@ public Object handleResponse(HttpResponse response) { if (messageLogger.isDebugEnabled()) { messageLogger.debug("message|eventMesh2client|url={}|topic={}|event={}", currPushUrl, - handleMsgContext.getTopic(), - handleMsgContext.getEvent()); + handleMsgContext.getTopic(), + handleMsgContext.getEvent()); } else { messageLogger - .info("message|eventMesh2client|url={}|topic={}|bizSeqNo={}|uniqueId={}", - currPushUrl, handleMsgContext.getTopic(), - handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId()); + .info("message|eventMesh2client|url={}|topic={}|bizSeqNo={}|uniqueId={}", + currPushUrl, handleMsgContext.getTopic(), + handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId()); } } catch (IOException e) { messageLogger.error("push2client err", e); @@ -246,16 +251,16 @@ public Object handleResponse(HttpResponse response) { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("asyncPushRequest={") - .append("bizSeqNo=").append(handleMsgContext.getBizSeqNo()) - .append(",startIdx=").append(startIdx) - .append(",retryTimes=").append(retryTimes) - .append(",uniqueId=").append(handleMsgContext.getUniqueId()) - .append(",executeTime=") - .append(DateFormatUtils.format(executeTime, Constants.DATE_FORMAT)) - .append(",lastPushTime=") - .append(DateFormatUtils.format(lastPushTime, Constants.DATE_FORMAT)) - .append(",createTime=") - .append(DateFormatUtils.format(createTime, Constants.DATE_FORMAT)).append("}"); + .append("bizSeqNo=").append(handleMsgContext.getBizSeqNo()) + .append(",startIdx=").append(startIdx) + .append(",retryTimes=").append(retryTimes) + .append(",uniqueId=").append(handleMsgContext.getUniqueId()) + .append(",executeTime=") + .append(DateFormatUtils.format(executeTime, Constants.DATE_FORMAT)) + .append(",lastPushTime=") + .append(DateFormatUtils.format(lastPushTime, Constants.DATE_FORMAT)) + .append(",createTime=") + .append(DateFormatUtils.format(createTime, Constants.DATE_FORMAT)).append("}"); return sb.toString(); } @@ -266,8 +271,8 @@ ClientRetCode processResponseContent(String content) { try { Map ret = - JsonUtils.deserialize(content, new TypeReference>() { - }); + JsonUtils.deserialize(content, new TypeReference>() { + }); Integer retCode = (Integer) ret.get("retCode"); if (retCode != null && ClientRetCode.contains(retCode)) { return ClientRetCode.get(retCode); @@ -276,15 +281,15 @@ ClientRetCode processResponseContent(String content) { return ClientRetCode.FAIL; } catch (NumberFormatException e) { messageLogger.warn("url:{}, bizSeqno:{}, uniqueId:{}, httpResponse:{}", currPushUrl, - handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), content); + handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), content); return ClientRetCode.FAIL; } catch (JsonException e) { messageLogger.warn("url:{}, bizSeqno:{}, uniqueId:{}, httpResponse:{}", currPushUrl, - handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), content); + handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), content); return ClientRetCode.FAIL; } catch (Throwable t) { messageLogger.warn("url:{}, bizSeqno:{}, uniqueId:{}, httpResponse:{}", currPushUrl, - handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), content); + handleMsgContext.getBizSeqNo(), handleMsgContext.getUniqueId(), content); return ClientRetCode.FAIL; } } @@ -295,7 +300,7 @@ private void addToWaitingMap(AsyncHTTPPushRequest request) { return; } waitingRequests - .put(request.handleMsgContext.getConsumerGroup(), Sets.newConcurrentHashSet()); + .put(request.handleMsgContext.getConsumerGroup(), Sets.newConcurrentHashSet()); waitingRequests.get(request.handleMsgContext.getConsumerGroup()).add(request); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/HTTPClientPool.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/HTTPClientPool.java index c2480f92da..28eec0ab0f 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/HTTPClientPool.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/HTTPClientPool.java @@ -17,16 +17,16 @@ package org.apache.eventmesh.runtime.core.protocol.http.push; -import java.util.Iterator; -import java.util.List; - -import com.google.common.collect.Lists; - import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.RandomUtils; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; +import java.util.Iterator; +import java.util.List; + +import com.google.common.collect.Lists; + public class HTTPClientPool { private List clients = Lists.newArrayList(); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/HTTPMessageHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/HTTPMessageHandler.java index f0e0ee87f7..1bdfd7f625 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/HTTPMessageHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/HTTPMessageHandler.java @@ -17,6 +17,12 @@ package org.apache.eventmesh.runtime.core.protocol.http.push; +import org.apache.eventmesh.common.ThreadPoolFactory; +import org.apache.eventmesh.runtime.core.protocol.http.consumer.EventMeshConsumer; +import org.apache.eventmesh.runtime.core.protocol.http.consumer.HandleMsgContext; + +import org.apache.commons.collections4.MapUtils; + import java.util.Map; import java.util.Set; import java.util.concurrent.RejectedExecutionException; @@ -24,16 +30,12 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; - -import org.apache.commons.collections4.MapUtils; -import org.apache.eventmesh.common.ThreadPoolFactory; -import org.apache.eventmesh.runtime.core.protocol.http.consumer.EventMeshConsumer; -import org.apache.eventmesh.runtime.core.protocol.http.consumer.HandleMsgContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + public class HTTPMessageHandler implements MessageHandler { public Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -44,7 +46,7 @@ public class HTTPMessageHandler implements MessageHandler { private ThreadPoolExecutor pushExecutor; - private final Integer CONSUMER_GROUP_WAITING_REQUEST_THRESHOLD = 10000; + private static final Integer CONSUMER_GROUP_WAITING_REQUEST_THRESHOLD = 10000; private void checkTimeout() { waitingRequests.entrySet().stream().forEach(entry -> { @@ -81,7 +83,8 @@ public boolean handle(final HandleMsgContext handleMsgContext) { }); return true; } catch (RejectedExecutionException e) { - logger.warn("pushMsgThreadPoolQueue is full, so reject, current task size {}", handleMsgContext.getEventMeshHTTPServer().getPushMsgExecutor().getQueue().size(), e); + logger.warn("pushMsgThreadPoolQueue is full, so reject, current task size {}", + handleMsgContext.getEventMeshHTTPServer().getPushMsgExecutor().getQueue().size(), e); return false; } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/MessageHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/MessageHandler.java index 403ed8e3f5..bf29c0e5ed 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/MessageHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/push/MessageHandler.java @@ -19,6 +19,9 @@ import org.apache.eventmesh.runtime.core.protocol.http.consumer.HandleMsgContext; +/** + * MessageHandler + */ public interface MessageHandler { boolean handle(HandleMsgContext handleMsgContext); } \ No newline at end of file diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/retry/DelayRetryable.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/retry/DelayRetryable.java index 194322576a..f79a6c2005 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/retry/DelayRetryable.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/retry/DelayRetryable.java @@ -19,6 +19,9 @@ import java.util.concurrent.Delayed; +/** + * DelayRetryable + */ public interface DelayRetryable extends Delayed { boolean retry() throws Exception; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/retry/HttpRetryer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/retry/HttpRetryer.java index 9faaece997..e4d09d2cb8 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/retry/HttpRetryer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/http/retry/HttpRetryer.java @@ -17,6 +17,8 @@ package org.apache.eventmesh.runtime.core.protocol.http.retry; +import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; + import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.DelayQueue; import java.util.concurrent.ThreadFactory; @@ -24,7 +26,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -58,7 +59,8 @@ public void init() { pool = new ThreadPoolExecutor(eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerRetryThreadNum, eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerRetryThreadNum, 60000, - TimeUnit.MILLISECONDS, new ArrayBlockingQueue(eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerRetryBlockQSize), + TimeUnit.MILLISECONDS, new ArrayBlockingQueue( + eventMeshHTTPServer.getEventMeshHttpConfiguration().eventMeshServerRetryBlockQSize), new ThreadFactory() { private AtomicInteger count = new AtomicInteger(); @@ -69,7 +71,8 @@ public Thread newThread(Runnable r) { thread.setDaemon(true); return thread; } - }, new ThreadPoolExecutor.AbortPolicy()); + }, + new ThreadPoolExecutor.AbortPolicy()); dispatcher = new Thread(new Runnable() { @Override diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcp2Client.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcp2Client.java index 8c71b587d2..0d300f7c86 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcp2Client.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcp2Client.java @@ -53,8 +53,8 @@ public static InetSocketAddress serverGoodby2Client(EventMeshTCPServer eventMesh long startTime = System.currentTimeMillis(); Package msg = new Package(); msg.setHeader( - new Header(SERVER_GOODBYE_REQUEST, OPStatus.SUCCESS.getCode(), "graceful normal quit from eventmesh", - null)); + new Header(SERVER_GOODBYE_REQUEST, OPStatus.SUCCESS.getCode(), "graceful normal quit from eventmesh", + null)); eventMeshTCPServer.getScheduler().submit(new Runnable() { @Override @@ -108,24 +108,24 @@ public static void goodBye2Client(ChannelHandlerContext ctx, eventMeshTcpMonitor.getEventMesh2clientMsgNum().incrementAndGet(); logger.info("goodBye2Client client[{}]", RemotingHelper.parseChannelRemoteAddr(ctx.channel())); ctx.writeAndFlush(pkg).addListener( - new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) throws Exception { - Utils.logSucceedMessageFlow(pkg, null, startTime, startTime); - try { - mapping.closeSession(ctx); - } catch (Exception e) { - logger.warn("close session failed!", e); + new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture future) throws Exception { + Utils.logSucceedMessageFlow(pkg, null, startTime, startTime); + try { + mapping.closeSession(ctx); + } catch (Exception e) { + logger.warn("close session failed!", e); + } } } - } ); } public static String redirectClient2NewEventMesh(EventMeshTCPServer eventMeshTCPServer, String newEventMeshIp, int port, Session session, ClientSessionGroupMapping mapping) { logger.info("begin to gracefully redirect Client {}, newIPPort[{}]", session.getClient(), - newEventMeshIp + ":" + port); + newEventMeshIp + ":" + port); try { long startTime = System.currentTimeMillis(); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpConnectionHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpConnectionHandler.java index f091ac41aa..685abc6a6b 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpConnectionHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpConnectionHandler.java @@ -17,18 +17,19 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.util.RemotingHelper; + import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.timeout.IdleState; import io.netty.handler.timeout.IdleStateEvent; -import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.util.RemotingHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class EventMeshTcpConnectionHandler extends ChannelDuplexHandler { public static AtomicInteger connections = new AtomicInteger(0); @@ -60,7 +61,8 @@ public void channelActive(ChannelHandlerContext ctx) throws Exception { int c = connections.incrementAndGet(); if (c > eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpClientMaxNum) { - logger.warn("client|tcp|channelActive|remoteAddress={}|msg={}", remoteAddress, "too many client connect " + + logger.warn("client|tcp|channelActive|remoteAddress={}|msg={}", remoteAddress, "too many client connect " + + "this eventMesh server"); ctx.close(); return; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpExceptionHandler.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpExceptionHandler.java index d6ed12a30f..d9aace846a 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpExceptionHandler.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpExceptionHandler.java @@ -17,16 +17,17 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client; -import io.netty.channel.ChannelDuplexHandler; -import io.netty.channel.ChannelHandlerContext; - import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelDuplexHandler; +import io.netty.channel.ChannelHandlerContext; + public class EventMeshTcpExceptionHandler extends ChannelDuplexHandler { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -49,9 +50,11 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E } if (session != null) { - EventMeshTcp2Client.goodBye2Client(eventMeshTCPServer, session, errMsg, OPStatus.FAIL.getCode(), eventMeshTCPServer.getClientSessionGroupMapping()); + EventMeshTcp2Client.goodBye2Client(eventMeshTCPServer, session, errMsg, OPStatus.FAIL.getCode(), + eventMeshTCPServer.getClientSessionGroupMapping()); } else { - EventMeshTcp2Client.goodBye2Client(ctx, errMsg, eventMeshTCPServer.getClientSessionGroupMapping(), eventMeshTCPServer.getEventMeshTcpMonitor()); + EventMeshTcp2Client.goodBye2Client(ctx, errMsg, eventMeshTCPServer.getClientSessionGroupMapping(), + eventMeshTCPServer.getEventMeshTcpMonitor()); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpMessageDispatcher.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpMessageDispatcher.java index 83497bc077..8b6c6e7056 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpMessageDispatcher.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/EventMeshTcpMessageDispatcher.java @@ -17,18 +17,30 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; - -import org.apache.eventmesh.common.protocol.tcp.*; +import org.apache.eventmesh.common.protocol.tcp.Command; +import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; +import org.apache.eventmesh.common.protocol.tcp.Header; +import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.SessionState; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.*; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.GoodbyeTask; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.HeartBeatTask; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.HelloTask; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.ListenTask; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.MessageAckTask; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.MessageTransferTask; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.RecommendTask; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.SubscribeTask; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.task.UnSubscribeTask; import org.apache.eventmesh.runtime.util.EventMeshUtil; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; + public class EventMeshTcpMessageDispatcher extends SimpleChannelInboundHandler { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -79,18 +91,18 @@ protected void channelRead0(ChannelHandlerContext ctx, Package pkg) throws Excep } } - private void writeToClient(Command cmd, Package pkg, ChannelHandlerContext ctx, Exception e){ - try{ + private void writeToClient(Command cmd, Package pkg, ChannelHandlerContext ctx, Exception e) { + try { Package res = new Package(); res.setHeader(new Header(getReplyCommand(cmd), OPStatus.FAIL.getCode(), e.toString(), pkg.getHeader() .getSeq())); ctx.writeAndFlush(res); - }catch (Exception ex){ + } catch (Exception ex) { logger.warn("writeToClient failed", ex); } } - private Command getReplyCommand(Command cmd){ + private Command getReplyCommand(Command cmd) { switch (cmd) { case HELLO_REQUEST: return Command.HELLO_RESPONSE; @@ -122,7 +134,8 @@ private void logMessageFlow(ChannelHandlerContext ctx, Package pkg, Command cmd) messageLogger.info("pkg|c2eventMesh|cmd={}|Msg={}|user={}", cmd, EventMeshUtil.printMqMessage((EventMeshMessage) pkg .getBody()), eventMeshTCPServer.getClientSessionGroupMapping().getSession(ctx).getClient()); } else { - messageLogger.info("pkg|c2eventMesh|cmd={}|pkg={}|user={}", cmd, pkg, eventMeshTCPServer.getClientSessionGroupMapping().getSession(ctx).getClient()); + messageLogger.info("pkg|c2eventMesh|cmd={}|pkg={}|user={}", cmd, pkg, + eventMeshTCPServer.getClientSessionGroupMapping().getSession(ctx).getClient()); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java index e789374675..809b1eee33 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientGroupWrapper.java @@ -17,12 +17,14 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.group; -import io.cloudevents.CloudEvent; -import io.cloudevents.core.builder.CloudEventBuilder; -import org.apache.eventmesh.api.*; +import org.apache.eventmesh.api.AsyncConsumeContext; import org.apache.eventmesh.api.EventListener; +import org.apache.eventmesh.api.EventMeshAction; +import org.apache.eventmesh.api.EventMeshAsyncConsumeContext; +import org.apache.eventmesh.api.RequestReplyCallback; +import org.apache.eventmesh.api.SendCallback; +import org.apache.eventmesh.api.SendResult; import org.apache.eventmesh.api.exception.OnExceptionContext; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.utils.JsonUtils; @@ -43,7 +45,13 @@ import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Objects; +import java.util.Properties; +import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.locks.ReadWriteLock; @@ -52,6 +60,9 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; + public class ClientGroupWrapper { @@ -93,7 +104,7 @@ public class ClientGroupWrapper { private MQConsumerWrapper broadCastMsgConsumer; private ConcurrentHashMap> topic2sessionInGroupMapping = - new ConcurrentHashMap>(); + new ConcurrentHashMap>(); public AtomicBoolean producerStarted = new AtomicBoolean(Boolean.FALSE); @@ -111,11 +122,11 @@ public ClientGroupWrapper(String sysId, String producerGroup, String consumerGro this.eventMeshTcpMonitor = eventMeshTCPServer.getEventMeshTcpMonitor(); this.downstreamDispatchStrategy = downstreamDispatchStrategy; this.persistentMsgConsumer = new MQConsumerWrapper( - eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshConnectorPluginType); + eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshConnectorPluginType); this.broadCastMsgConsumer = new MQConsumerWrapper( - eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshConnectorPluginType); + eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshConnectorPluginType); this.mqProducerWrapper = new MQProducerWrapper( - eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshConnectorPluginType); + eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshConnectorPluginType); } public ConcurrentHashMap> getTopic2sessionInGroupMapping() { @@ -137,13 +148,13 @@ public boolean hasSubscription(String topic) { } public boolean send(UpStreamMsgContext upStreamMsgContext, SendCallback sendCallback) - throws Exception { + throws Exception { mqProducerWrapper.send(upStreamMsgContext.getEvent(), sendCallback); return true; } public void request(UpStreamMsgContext upStreamMsgContext, RequestReplyCallback rrCallback, long timeout) - throws Exception { + throws Exception { mqProducerWrapper.request(upStreamMsgContext.getEvent(), rrCallback, timeout); } @@ -158,8 +169,8 @@ public void onSuccess(SendResult sendResult) { public void onException(OnExceptionContext context) { String bizSeqNo = (String) upStreamMsgContext.getEvent().getExtension(EventMeshConstants.PROPERTY_MESSAGE_KEYS); logger.error("reply err! topic:{}, bizSeqNo:{}, client:{}", - upStreamMsgContext.getEvent().getSubject(), bizSeqNo, - upStreamMsgContext.getSession().getClient(), context.getException()); + upStreamMsgContext.getEvent().getSubject(), bizSeqNo, + upStreamMsgContext.getSession().getClient(), context.getException()); } }); return true; @@ -171,7 +182,7 @@ public MQProducerWrapper getMqProducerWrapper() { public boolean addSubscription(String topic, Session session) throws Exception { if (session == null || !StringUtils.equalsIgnoreCase(consumerGroup, - EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { + EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { logger.error("addSubscription param error,topic:{},session:{}", topic, session); return false; } @@ -186,15 +197,15 @@ public boolean addSubscription(String topic, Session session) throws Exception { r = topic2sessionInGroupMapping.get(topic).add(session); if (r) { logger.info("addSubscription success, group:{} topic:{} client:{}", consumerGroup, - topic, session.getClient()); + topic, session.getClient()); } else { logger - .warn("addSubscription fail, group:{} topic:{} client:{}", consumerGroup, topic, - session.getClient()); + .warn("addSubscription fail, group:{} topic:{} client:{}", consumerGroup, topic, + session.getClient()); } } catch (Exception e) { logger - .error("addSubscription error! topic:{} client:{}", topic, session.getClient(), e); + .error("addSubscription error! topic:{} client:{}", topic, session.getClient(), e); throw new Exception("addSubscription fail"); } finally { this.groupLock.writeLock().unlock(); @@ -204,8 +215,8 @@ public boolean addSubscription(String topic, Session session) throws Exception { public boolean removeSubscription(String topic, Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(consumerGroup, - EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { + || !StringUtils.equalsIgnoreCase(consumerGroup, + EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { logger.error("removeSubscription param error,topic:{},session:{}", topic, session); return false; } @@ -217,22 +228,22 @@ public boolean removeSubscription(String topic, Session session) { r = topic2sessionInGroupMapping.get(topic).remove(session); if (r) { logger.info( - "removeSubscription remove session success, group:{} topic:{} client:{}", - consumerGroup, topic, session.getClient()); + "removeSubscription remove session success, group:{} topic:{} client:{}", + consumerGroup, topic, session.getClient()); } else { logger.warn( - "removeSubscription remove session failed, group:{} topic:{} client:{}", - consumerGroup, topic, session.getClient()); + "removeSubscription remove session failed, group:{} topic:{} client:{}", + consumerGroup, topic, session.getClient()); } } if (CollectionUtils.size(topic2sessionInGroupMapping.get(topic)) == 0) { topic2sessionInGroupMapping.remove(topic); logger.info("removeSubscription remove topic success, group:{} topic:{}", - consumerGroup, topic); + consumerGroup, topic); } } catch (Exception e) { logger.error("removeSubscription error! topic:{} client:{}", topic, session.getClient(), - e); + e); } finally { this.groupLock.writeLock().unlock(); } @@ -247,7 +258,7 @@ public synchronized void startClientGroupProducer() throws Exception { Properties keyValue = new Properties(); keyValue.put("producerGroup", producerGroup); keyValue.put("instanceName", EventMeshUtil - .buildMeshTcpClientID(sysId, "PUB", eventMeshTCPConfiguration.eventMeshCluster)); + .buildMeshTcpClientID(sysId, "PUB", eventMeshTCPConfiguration.eventMeshCluster)); //TODO for defibus keyValue.put("eventMeshIDC", eventMeshTCPConfiguration.eventMeshIDC); @@ -285,8 +296,8 @@ public void setConsumerGroup(String consumerGroup) { public boolean addGroupConsumerSession(Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(consumerGroup, - EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { + || !StringUtils.equalsIgnoreCase(consumerGroup, + EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { logger.error("addGroupConsumerSession param error,session:{}", session); return false; } @@ -297,11 +308,11 @@ public boolean addGroupConsumerSession(Session session) { r = groupConsumerSessions.add(session); if (r) { logger.info("addGroupConsumerSession success, group:{} client:{}", consumerGroup, - session.getClient()); + session.getClient()); } } catch (Exception e) { logger.error("addGroupConsumerSession error! group:{} client:{}", consumerGroup, - session.getClient(), e); + session.getClient(), e); } finally { this.groupLock.writeLock().unlock(); } @@ -310,8 +321,8 @@ public boolean addGroupConsumerSession(Session session) { public boolean addGroupProducerSession(Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(producerGroup, - EventMeshUtil.buildClientGroup(session.getClient().getProducerGroup()))) { + || !StringUtils.equalsIgnoreCase(producerGroup, + EventMeshUtil.buildClientGroup(session.getClient().getProducerGroup()))) { logger.error("addGroupProducerSession param error,session:{}", session); return false; } @@ -322,11 +333,11 @@ public boolean addGroupProducerSession(Session session) { r = groupProducerSessions.add(session); if (r) { logger.info("addGroupProducerSession success, group:{} client:{}", producerGroup, - session.getClient()); + session.getClient()); } } catch (Exception e) { logger.error("addGroupProducerSession error! group:{} client:{}", producerGroup, - session.getClient(), e); + session.getClient(), e); } finally { this.groupLock.writeLock().unlock(); } @@ -335,8 +346,8 @@ public boolean addGroupProducerSession(Session session) { public boolean removeGroupConsumerSession(Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(consumerGroup, - EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { + || !StringUtils.equalsIgnoreCase(consumerGroup, + EventMeshUtil.buildClientGroup(session.getClient().getConsumerGroup()))) { logger.error("removeGroupConsumerSession param error,session:{}", session); return false; } @@ -347,11 +358,11 @@ public boolean removeGroupConsumerSession(Session session) { r = groupConsumerSessions.remove(session); if (r) { logger.info("removeGroupConsumerSession success, group:{} client:{}", consumerGroup, - session.getClient()); + session.getClient()); } } catch (Exception e) { logger.error("removeGroupConsumerSession error! group:{} client:{}", consumerGroup, - session.getClient(), e); + session.getClient(), e); } finally { this.groupLock.writeLock().unlock(); } @@ -360,8 +371,8 @@ public boolean removeGroupConsumerSession(Session session) { public boolean removeGroupProducerSession(Session session) { if (session == null - || !StringUtils.equalsIgnoreCase(producerGroup, - EventMeshUtil.buildClientGroup(session.getClient().getProducerGroup()))) { + || !StringUtils.equalsIgnoreCase(producerGroup, + EventMeshUtil.buildClientGroup(session.getClient().getProducerGroup()))) { logger.error("removeGroupProducerSession param error,session:{}", session); return false; } @@ -372,11 +383,11 @@ public boolean removeGroupProducerSession(Session session) { r = groupProducerSessions.remove(session); if (r) { logger.info("removeGroupProducerSession success, group:{} client:{}", producerGroup, - session.getClient()); + session.getClient()); } } catch (Exception e) { logger.error("removeGroupProducerSession error! group:{} client:{}", producerGroup, - session.getClient(), e); + session.getClient(), e); } finally { this.groupLock.writeLock().unlock(); } @@ -394,7 +405,7 @@ public synchronized void initClientGroupPersistentConsumer() throws Exception { keyValue.put("consumerGroup", consumerGroup); keyValue.put("eventMeshIDC", eventMeshTCPConfiguration.eventMeshIDC); keyValue.put("instanceName", EventMeshUtil - .buildMeshTcpClientID(sysId, "SUB", eventMeshTCPConfiguration.eventMeshCluster)); + .buildMeshTcpClientID(sysId, "SUB", eventMeshTCPConfiguration.eventMeshCluster)); persistentMsgConsumer.init(keyValue); @@ -421,7 +432,7 @@ public synchronized void initClientGroupBroadcastConsumer() throws Exception { keyValue.put("consumerGroup", consumerGroup); keyValue.put("eventMeshIDC", eventMeshTCPConfiguration.eventMeshIDC); keyValue.put("instanceName", EventMeshUtil - .buildMeshTcpClientID(sysId, "SUB", eventMeshTCPConfiguration.eventMeshCluster)); + .buildMeshTcpClientID(sysId, "SUB", eventMeshTCPConfiguration.eventMeshCluster)); broadCastMsgConsumer.init(keyValue); inited4Broadcast.compareAndSet(false, true); @@ -447,18 +458,18 @@ public void consume(CloudEvent event, AsyncConsumeContext context) { eventMeshTcpMonitor.getMq2EventMeshMsgNum().incrementAndGet(); event = CloudEventBuilder.from(event) .withExtension(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, - String.valueOf(System.currentTimeMillis())) + String.valueOf(System.currentTimeMillis())) .withExtension(EventMeshConstants.REQ_RECEIVE_EVENTMESH_IP, eventMeshTCPConfiguration.eventMeshServerIp).build(); String topic = event.getSubject(); -// message.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION); -// message.getSystemProperties().put(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, -// String.valueOf(System.currentTimeMillis())); -// message.getSystemProperties().put(EventMeshConstants.REQ_RECEIVE_EVENTMESH_IP, -// eventMeshTCPConfiguration.eventMeshServerIp); + // message.getSystemProperties(Constants.PROPERTY_MESSAGE_DESTINATION); + //message.getSystemProperties().put(EventMeshConstants.REQ_MQ2EVENTMESH_TIMESTAMP, + // String.valueOf(System.currentTimeMillis())); + //message.getSystemProperties().put(EventMeshConstants.REQ_RECEIVE_EVENTMESH_IP, + // eventMeshTCPConfiguration.eventMeshServerIp); EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = - (EventMeshAsyncConsumeContext) context; + (EventMeshAsyncConsumeContext) context; if (CollectionUtils.isEmpty(groupConsumerSessions)) { logger.warn("found no session to downstream broadcast msg"); eventMeshAsyncConsumeContext.commit(EventMeshAction.CommitMessage); @@ -468,17 +479,17 @@ public void consume(CloudEvent event, AsyncConsumeContext context) { Iterator sessionsItr = groupConsumerSessions.iterator(); DownStreamMsgContext downStreamMsgContext = - new DownStreamMsgContext(event, null, broadCastMsgConsumer, - eventMeshAsyncConsumeContext.getAbstractContext(), false, - subscriptionItem); + new DownStreamMsgContext(event, null, broadCastMsgConsumer, + eventMeshAsyncConsumeContext.getAbstractContext(), false, + subscriptionItem); while (sessionsItr.hasNext()) { Session session = sessionsItr.next(); if (!session.isAvailable(topic)) { logger - .warn("downstream broadcast msg,session is not available,client:{}", - session.getClient()); + .warn("downstream broadcast msg,session is not available,client:{}", + session.getClient()); continue; } @@ -486,15 +497,15 @@ public void consume(CloudEvent event, AsyncConsumeContext context) { //downstream broadcast msg asynchronously eventMeshTCPServer.getBroadcastMsgDownstreamExecutorService() - .submit(new Runnable() { - @Override - public void run() { - //msg put in eventmesh,waiting client ack - session.getPusher() - .unAckMsg(downStreamMsgContext.seq, downStreamMsgContext); - session.downstreamMsg(downStreamMsgContext); - } - }); + .submit(new Runnable() { + @Override + public void run() { + //msg put in eventmesh,waiting client ack + session.getPusher() + .unAckMsg(downStreamMsgContext.seq, downStreamMsgContext); + session.downstreamMsg(downStreamMsgContext); + } + }); } eventMeshAsyncConsumeContext.commit(EventMeshAction.ManualAck); @@ -514,9 +525,9 @@ public void consume(CloudEvent event, AsyncConsumeContext context) { String topic = event.getSubject(); EventMeshAsyncConsumeContext eventMeshAsyncConsumeContext = - (EventMeshAsyncConsumeContext) context; + (EventMeshAsyncConsumeContext) context; Session session = downstreamDispatchStrategy - .select(consumerGroup, topic, groupConsumerSessions); + .select(consumerGroup, topic, groupConsumerSessions); String bizSeqNo = EventMeshUtil.getMessageBizSeq(event); if (session == null) { try { @@ -532,19 +543,19 @@ public void consume(CloudEvent event, AsyncConsumeContext context) { } logger.error( - "found no session to downstream msg,groupName:{}, topic:{}, " - + "bizSeqNo:{}, sendBackTimes:{}, sendBackFromEventMeshIp:{}", - consumerGroup, topic, bizSeqNo, sendBackTimes, - sendBackFromEventMeshIp); + "found no session to downstream msg,groupName:{}, topic:{}, " + + "bizSeqNo:{}, sendBackTimes:{}, sendBackFromEventMeshIp:{}", + consumerGroup, topic, bizSeqNo, sendBackTimes, + sendBackFromEventMeshIp); if (sendBackTimes >= eventMeshTCPServer - .getEventMeshTCPConfiguration().eventMeshTcpSendBackMaxTimes) { + .getEventMeshTCPConfiguration().eventMeshTcpSendBackMaxTimes) { logger.error( - "sendBack to broker over max times:{}, groupName:{}, topic:{}, " - + "bizSeqNo:{}", eventMeshTCPServer - .getEventMeshTCPConfiguration() - .eventMeshTcpSendBackMaxTimes, - consumerGroup, topic, bizSeqNo); + "sendBack to broker over max times:{}, groupName:{}, topic:{}, " + + "bizSeqNo:{}", eventMeshTCPServer + .getEventMeshTCPConfiguration() + .eventMeshTcpSendBackMaxTimes, + consumerGroup, topic, bizSeqNo); } else { sendBackTimes++; event = CloudEventBuilder.from(event) @@ -563,9 +574,9 @@ public void consume(CloudEvent event, AsyncConsumeContext context) { } DownStreamMsgContext downStreamMsgContext = - new DownStreamMsgContext(event, session, persistentMsgConsumer, - eventMeshAsyncConsumeContext.getAbstractContext(), false, - subscriptionItem); + new DownStreamMsgContext(event, session, persistentMsgConsumer, + eventMeshAsyncConsumeContext.getAbstractContext(), false, + subscriptionItem); //msg put in eventmesh,waiting client ack session.getPusher().unAckMsg(downStreamMsgContext.seq, downStreamMsgContext); session.downstreamMsg(downStreamMsgContext); @@ -642,7 +653,7 @@ public DownstreamDispatchStrategy getDownstreamDispatchStrategy() { } public void setDownstreamDispatchStrategy( - DownstreamDispatchStrategy downstreamDispatchStrategy) { + DownstreamDispatchStrategy downstreamDispatchStrategy) { this.downstreamDispatchStrategy = downstreamDispatchStrategy; } @@ -653,12 +664,12 @@ public String getSysId() { private String pushMsgToEventMesh(CloudEvent msg, String ip, int port) throws Exception { StringBuilder targetUrl = new StringBuilder(); targetUrl.append("http://").append(ip).append(":").append(port) - .append("/eventMesh/msg/push"); + .append("/eventMesh/msg/push"); HttpTinyClient.HttpResult result = null; try { logger.info("pushMsgToEventMesh,targetUrl:{},msg:{}", targetUrl.toString(), - msg); + msg); List paramValues = new ArrayList(); paramValues.add("msg"); paramValues.add(JsonUtils.serialize(msg)); @@ -666,23 +677,23 @@ private String pushMsgToEventMesh(CloudEvent msg, String ip, int port) throws Ex paramValues.add(consumerGroup); result = HttpTinyClient.httpPost( - targetUrl.toString(), - null, - paramValues, - "UTF-8", - 3000); + targetUrl.toString(), + null, + paramValues, + "UTF-8", + 3000); } catch (Exception e) { logger.error("httpPost " + targetUrl + " is fail,", e); //throw new RuntimeException("httpPost " + targetUrl + " is fail," , e); throw e; } - if (200 == result.code && result.content != null) { - return result.content; + if (200 == result.getCode() && result.getContent() != null) { + return result.getContent(); } else { throw new Exception("httpPost targetUrl[" + targetUrl - + "] is not OK when getContentThroughHttp, httpResult: " + result + "."); + + "] is not OK when getContentThroughHttp, httpResult: " + result + "."); } } @@ -698,22 +709,22 @@ private void sendMsgBackToBroker(CloudEvent event, String bizSeqNo) throws Excep long startTime = System.currentTimeMillis(); long taskExcuteTime = startTime; send(new UpStreamMsgContext(null, event, null, startTime, taskExcuteTime), - new SendCallback() { - @Override - public void onSuccess(SendResult sendResult) { - logger.info( - "consumerGroup:{} consume fail, sendMessageBack success, bizSeqno:{}, " - + "topic:{}", consumerGroup, bizSeqNo, topic); - } + new SendCallback() { + @Override + public void onSuccess(SendResult sendResult) { + logger.info( + "consumerGroup:{} consume fail, sendMessageBack success, bizSeqno:{}, " + + "topic:{}", consumerGroup, bizSeqNo, topic); + } - @Override - public void onException(OnExceptionContext context) { - logger.warn( - "consumerGroup:{} consume fail, sendMessageBack fail, bizSeqno:{}," - + " topic:{}", consumerGroup, bizSeqNo, topic); - } + @Override + public void onException(OnExceptionContext context) { + logger.warn( + "consumerGroup:{} consume fail, sendMessageBack fail, bizSeqno:{}," + + " topic:{}", consumerGroup, bizSeqNo, topic); + } - }); + }); eventMeshTcpMonitor.getEventMesh2mqMsgNum().incrementAndGet(); } catch (Exception e) { logger.warn("try send msg back to broker failed"); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientSessionGroupMapping.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientSessionGroupMapping.java index ce73948e27..548d7e5b22 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientSessionGroupMapping.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/ClientSessionGroupMapping.java @@ -58,10 +58,10 @@ public class ClientSessionGroupMapping { private ConcurrentHashMap sessionTable = new ConcurrentHashMap<>(); private ConcurrentHashMap clientGroupMap = - new ConcurrentHashMap(); + new ConcurrentHashMap(); private ConcurrentHashMap lockMap = - new ConcurrentHashMap(); + new ConcurrentHashMap(); private EventMeshTCPServer eventMeshTCPServer; @@ -126,7 +126,7 @@ public synchronized void closeSession(ChannelHandlerContext ctx) throws Exceptio @Override public void operationComplete(ChannelFuture future) throws Exception { logger.info("close the connection to remote address[{}] result: {}", remoteAddress, - future.isSuccess()); + future.isSuccess()); } }); sessionLogger.info("session|close|succeed|address={}|msg={}", addr, "no session was found"); @@ -172,7 +172,7 @@ private void closeSession(Session session) throws Exception { @Override public void operationComplete(ChannelFuture future) throws Exception { logger.info("close the connection to remote address[{}] result: {}", remoteAddress, - future.isSuccess()); + future.isSuccess()); } }); } @@ -183,7 +183,7 @@ private ClientGroupWrapper constructClientGroupWrapper(String sysId, String prod EventMeshTCPServer eventMeshTCPServer, DownstreamDispatchStrategy downstreamDispatchStrategy) { return new ClientGroupWrapper(sysId, producerGroup, consumerGroup, eventMeshTCPServer, - downstreamDispatchStrategy); + downstreamDispatchStrategy); } private void initClientGroupWrapper(UserAgent user, Session session) throws Exception { @@ -196,7 +196,7 @@ private void initClientGroupWrapper(UserAgent user, Session session) throws Exce synchronized (lockMap.get(user.getSubsystem())) { if (!clientGroupMap.containsKey(user.getSubsystem())) { ClientGroupWrapper cgw = constructClientGroupWrapper(user.getSubsystem(), user.getProducerGroup(), - user.getConsumerGroup(), eventMeshTCPServer, new FreePriorityDispatchStrategy()); + user.getConsumerGroup(), eventMeshTCPServer, new FreePriorityDispatchStrategy()); clientGroupMap.put(user.getSubsystem(), cgw); logger.info("create new ClientGroupWrapper, subsystem:{}", user.getSubsystem()); } @@ -302,23 +302,23 @@ private void handleUnackMsgsInSession(Session session) { DownStreamMsgContext downStreamMsgContext = entry.getValue(); if (SubscriptionMode.BROADCASTING.equals(downStreamMsgContext.subscriptionItem.getMode())) { logger.warn("exist broadcast msg unack when closeSession,seq:{},bizSeq:{},client:{}", - downStreamMsgContext.seq, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.event), - session.getClient()); + downStreamMsgContext.seq, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.event), + session.getClient()); continue; } Session reChooseSession = session.getClientGroupWrapper().get().getDownstreamDispatchStrategy() - .select(session.getClientGroupWrapper().get().getConsumerGroup(), - downStreamMsgContext.event.getSubject(), - Objects.requireNonNull(session.getClientGroupWrapper().get()).groupConsumerSessions); + .select(session.getClientGroupWrapper().get().getConsumerGroup(), + downStreamMsgContext.event.getSubject(), + Objects.requireNonNull(session.getClientGroupWrapper().get()).groupConsumerSessions); if (reChooseSession != null) { downStreamMsgContext.session = reChooseSession; reChooseSession.getPusher().unAckMsg(downStreamMsgContext.seq, downStreamMsgContext); reChooseSession.downstreamMsg(downStreamMsgContext); logger.info("rePush msg form unAckMsgs,seq:{},rePushClient:{}", entry.getKey(), - downStreamMsgContext.session.getClient()); + downStreamMsgContext.session.getClient()); } else { logger.warn("select session fail in handleUnackMsgsInSession,seq:{},topic:{}", entry.getKey(), - downStreamMsgContext.event.getSubject()); + downStreamMsgContext.event.getSubject()); } } } @@ -326,15 +326,15 @@ private void handleUnackMsgsInSession(Session session) { private void cleanClientGroupWrapperCommon(Session session) throws Exception { logger.info("GroupConsumerSessions size:{}", - session.getClientGroupWrapper().get().getGroupConsumerSessions().size()); + session.getClientGroupWrapper().get().getGroupConsumerSessions().size()); if (session.getClientGroupWrapper().get().getGroupConsumerSessions().size() == 0) { shutdownClientGroupConsumer(session); } logger.info("GroupProducerSessions size:{}", - session.getClientGroupWrapper().get().getGroupProducerSessions().size()); + session.getClientGroupWrapper().get().getGroupProducerSessions().size()); if ((session.getClientGroupWrapper().get().getGroupConsumerSessions().size() == 0) - && (session.getClientGroupWrapper().get().getGroupProducerSessions().size() == 0)) { + && (session.getClientGroupWrapper().get().getGroupProducerSessions().size() == 0)) { shutdownClientGroupProducer(session); clientGroupMap.remove(session.getClientGroupWrapper().get().getSysId()); @@ -361,50 +361,52 @@ private void shutdownClientGroupProducer(Session session) throws Exception { } private void initSessionCleaner() { - eventMeshTCPServer.getScheduler().scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - Iterator sessionIterator = sessionTable.values().iterator(); - while (sessionIterator.hasNext()) { - Session tmp = sessionIterator.next(); - if (System.currentTimeMillis() - tmp.getLastHeartbeatTime() - > eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSessionExpiredInMills) { - try { - logger.warn("clean expired session,client:{}", tmp.getClient()); - closeSession(tmp.getContext()); - } catch (Exception e) { - logger.error("say goodbye to session error! {}", tmp, e); - } - } - } - } - }, 1000, eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSessionExpiredInMills, - TimeUnit.MILLISECONDS); + eventMeshTCPServer.getScheduler().scheduleAtFixedRate( + new Runnable() { + @Override + public void run() { + Iterator sessionIterator = sessionTable.values().iterator(); + while (sessionIterator.hasNext()) { + Session tmp = sessionIterator.next(); + if (System.currentTimeMillis() - tmp.getLastHeartbeatTime() + > eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSessionExpiredInMills) { + try { + logger.warn("clean expired session,client:{}", tmp.getClient()); + closeSession(tmp.getContext()); + } catch (Exception e) { + logger.error("say goodbye to session error! {}", tmp, e); + } + } + } + } + }, 1000, eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpSessionExpiredInMills, + TimeUnit.MILLISECONDS); } private void initDownStreamMsgContextCleaner() { - eventMeshTCPServer.getScheduler().scheduleAtFixedRate(new Runnable() { - @Override - public void run() { - - //scan non-broadcast msg - Iterator sessionIterator = sessionTable.values().iterator(); - while (sessionIterator.hasNext()) { - Session tmp = sessionIterator.next(); - for (Map.Entry entry : tmp.getPusher().getUnAckMsg().entrySet()) { - String seqKey = entry.getKey(); - DownStreamMsgContext downStreamMsgContext = entry.getValue(); - if (!downStreamMsgContext.isExpire()) { - continue; + eventMeshTCPServer.getScheduler().scheduleAtFixedRate( + new Runnable() { + @Override + public void run() { + + //scan non-broadcast msg + Iterator sessionIterator = sessionTable.values().iterator(); + while (sessionIterator.hasNext()) { + Session tmp = sessionIterator.next(); + for (Map.Entry entry : tmp.getPusher().getUnAckMsg().entrySet()) { + String seqKey = entry.getKey(); + DownStreamMsgContext downStreamMsgContext = entry.getValue(); + if (!downStreamMsgContext.isExpire()) { + continue; + } + downStreamMsgContext.ackMsg(); + tmp.getPusher().getUnAckMsg().remove(seqKey); + logger.warn("remove expire downStreamMsgContext, session:{}, topic:{}, seq:{}", tmp, + downStreamMsgContext.event.getSubject(), seqKey); + } } - downStreamMsgContext.ackMsg(); - tmp.getPusher().getUnAckMsg().remove(seqKey); - logger.warn("remove expire downStreamMsgContext, session:{}, topic:{}, seq:{}", tmp, - downStreamMsgContext.event.getSubject(), seqKey); } - } - } - }, 1000, 5 * 1000, TimeUnit.MILLISECONDS); + }, 1000, 5 * 1000, TimeUnit.MILLISECONDS); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/DownstreamDispatchStrategy.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/DownstreamDispatchStrategy.java index fe0e589620..9259c51de8 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/DownstreamDispatchStrategy.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/DownstreamDispatchStrategy.java @@ -18,10 +18,13 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.group.dispatch; -import java.util.Set; - import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import java.util.Set; + +/** + * DownstreamDispatchStrategy + */ public interface DownstreamDispatchStrategy { /** * select a SESSION diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/FreePriorityDispatchStrategy.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/FreePriorityDispatchStrategy.java index 4e9e4d5936..623dbb07d9 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/FreePriorityDispatchStrategy.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/group/dispatch/FreePriorityDispatchStrategy.java @@ -17,14 +17,16 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.group.dispatch; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; + import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +50,8 @@ public Session select(String group, String topic, Set groupConsumerSess } if (session.isIsolated()) { isolatedSessions.add(session); - logger.info("session is not available because session is isolated,isolateTime:{},client:{}",session.getIsolateTime(), session.getClient()); + logger.info("session is not available because session is isolated,isolateTime:{},client:{}", + session.getIsolateTime(), session.getClient()); continue; } filtered.add(session); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventMeshRebalanceService.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventMeshRebalanceService.java index 516afa3ae6..560cf40e24 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventMeshRebalanceService.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventMeshRebalanceService.java @@ -14,19 +14,21 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.core.protocol.tcp.client.rebalance; import org.apache.eventmesh.common.ThreadPoolFactory; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.util.EventMeshThreadFactoryImpl; import org.apache.eventmesh.runtime.util.EventMeshUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class EventMeshRebalanceService { protected final Logger logger = LoggerFactory.getLogger(EventMeshRebalanceService.class); @@ -44,8 +46,8 @@ public EventMeshRebalanceService(EventMeshTCPServer eventMeshTCPServer, EventMes this.rebalanceIntervalMills = eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshTcpRebalanceIntervalInMills; } - public void init(){ - this.serviceRebalanceScheduler = ThreadPoolFactory.createScheduledExecutor(5, new EventMeshThreadFactoryImpl("proxy-rebalance-sch",true)); + public void init() { + this.serviceRebalanceScheduler = ThreadPoolFactory.createScheduledExecutor(5, new EventMeshThreadFactoryImpl("proxy-rebalance-sch", true)); logger.info("rebalance service inited......"); } @@ -61,12 +63,12 @@ public void start() throws Exception { logger.info("rebalance service started......"); } - public void shutdown(){ + public void shutdown() { this.serviceRebalanceScheduler.shutdown(); logger.info("rebalance service shutdown......"); } - public void printRebalanceThreadPoolState(){ + public void printRebalanceThreadPoolState() { EventMeshUtil.printState((ThreadPoolExecutor) serviceRebalanceScheduler); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventMeshRebalanceStrategy.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventMeshRebalanceStrategy.java index 2bc32d1655..b14e602a82 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventMeshRebalanceStrategy.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventMeshRebalanceStrategy.java @@ -14,8 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.core.protocol.tcp.client.rebalance; +/** + * EventMeshRebalanceStrategy + */ public interface EventMeshRebalanceStrategy { void doRebalance() throws Exception; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventmeshRebalanceImpl.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventmeshRebalanceImpl.java index 2929705542..4c11b0b43b 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventmeshRebalanceImpl.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/rebalance/EventmeshRebalanceImpl.java @@ -14,10 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.core.protocol.tcp.client.rebalance; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -25,28 +24,37 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendImpl; import org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendStrategy; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; - public class EventmeshRebalanceImpl implements EventMeshRebalanceStrategy { protected final Logger logger = LoggerFactory.getLogger(EventmeshRebalanceImpl.class); private EventMeshTCPServer eventMeshTCPServer; - public EventmeshRebalanceImpl(EventMeshTCPServer eventMeshTCPServer){ + public EventmeshRebalanceImpl(EventMeshTCPServer eventMeshTCPServer) { this.eventMeshTCPServer = eventMeshTCPServer; } @Override public void doRebalance() throws Exception { long startTime = System.currentTimeMillis(); - logger.info("doRebalance start===========startTime:{}",startTime); + logger.info("doRebalance start===========startTime:{}", startTime); Set groupSet = eventMeshTCPServer.getClientSessionGroupMapping().getClientGroupMap().keySet(); - if(CollectionUtils.isEmpty(groupSet)){ + if (CollectionUtils.isEmpty(groupSet)) { logger.warn("doRebalance failed,eventmesh has no group, please check eventmeshData"); return; } @@ -54,41 +62,42 @@ public void doRebalance() throws Exception { final String cluster = eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshCluster; //get eventmesh of local idc Map localEventMeshMap = queryLocalEventMeshMap(cluster); - if(localEventMeshMap == null || localEventMeshMap.size() == 0){ + if (localEventMeshMap == null || localEventMeshMap.size() == 0) { return; } - for(String group : groupSet){ + for (String group : groupSet) { doRebalanceByGroup(cluster, group, EventMeshConstants.PURPOSE_SUB, localEventMeshMap); doRebalanceByGroup(cluster, group, EventMeshConstants.PURPOSE_PUB, localEventMeshMap); } logger.info("doRebalance end===========startTime:{}, cost:{}", startTime, System.currentTimeMillis() - startTime); } - private Map queryLocalEventMeshMap(String cluster){ + private Map queryLocalEventMeshMap(String cluster) { Map localEventMeshMap = null; List eventMeshDataInfoList = null; - try{ + try { eventMeshDataInfoList = eventMeshTCPServer.getRegistry().findEventMeshInfoByCluster(cluster); - if(eventMeshDataInfoList == null || CollectionUtils.isEmpty(eventMeshDataInfoList)){ + if (eventMeshDataInfoList == null || CollectionUtils.isEmpty(eventMeshDataInfoList)) { logger.warn("doRebalance failed,query eventmesh instances is null from registry,cluster:{}", cluster); return null; } localEventMeshMap = new HashMap<>(); String localIdc = eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshIDC; - for(EventMeshDataInfo eventMeshDataInfo : eventMeshDataInfoList){ + for (EventMeshDataInfo eventMeshDataInfo : eventMeshDataInfoList) { String idc = eventMeshDataInfo.getEventMeshName().split("-")[0]; - if(StringUtils.isNotBlank(idc) && StringUtils.equals(idc, localIdc)){ + if (StringUtils.isNotBlank(idc) && StringUtils.equals(idc, localIdc)) { localEventMeshMap.put(eventMeshDataInfo.getEventMeshName(), eventMeshDataInfo.getEndpoint()); } } - if(0 == localEventMeshMap.size()){ - logger.warn("doRebalance failed,query eventmesh instances of localIDC is null from registry,localIDC:{},cluster:{}", localIdc,cluster); + if (0 == localEventMeshMap.size()) { + logger.warn("doRebalance failed,query eventmesh instances of localIDC is null from registry,localIDC:{},cluster:{}", + localIdc, cluster); return null; } - }catch (Exception e){ + } catch (Exception e) { logger.warn("doRebalance failed,findEventMeshInfoByCluster failed,cluster:{},errMsg:{}", cluster, e); return null; } @@ -96,63 +105,71 @@ private Map queryLocalEventMeshMap(String cluster){ return localEventMeshMap; } - private void doRebalanceByGroup(String cluster, String group, String purpose, Map eventMeshMap) throws Exception{ + private void doRebalanceByGroup(String cluster, String group, String purpose, Map eventMeshMap) throws Exception { logger.info("doRebalanceByGroup start, cluster:{}, group:{}, purpose:{}", cluster, group, purpose); //query distribute data of loacl idc - Map clientDistributionMap = queryLocalEventMeshDistributeData(cluster, group, purpose, eventMeshMap); - if(clientDistributionMap == null || clientDistributionMap.size() == 0){ + Map clientDistributionMap = queryLocalEventMeshDistributeData(cluster, group, purpose, + eventMeshMap); + if (clientDistributionMap == null || clientDistributionMap.size() == 0) { return; } - doRebalanceRedirect(eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshName, group, purpose, eventMeshMap, clientDistributionMap); + doRebalanceRedirect(eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshName, group, purpose, + eventMeshMap, clientDistributionMap); logger.info("doRebalanceByGroup end, cluster:{}, group:{}, purpose:{}", cluster, group, purpose); - + } - private void doRebalanceRedirect(String currEventMeshName, String group, String purpose, Map eventMeshMap, Map clientDistributionMap)throws Exception{ - if(clientDistributionMap == null || clientDistributionMap.size() == 0){ + private void doRebalanceRedirect(String currEventMeshName, String group, String purpose, Map eventMeshMap, + Map clientDistributionMap) throws Exception { + if (clientDistributionMap == null || clientDistributionMap.size() == 0) { return; } //caculate client num need to redirect in currEventMesh int judge = caculateRedirectNum(currEventMeshName, group, purpose, clientDistributionMap); - if(judge > 0) { + if (judge > 0) { //select redirect target eventmesh lisg - List eventMeshRecommendResult = selectRedirectEventMesh(group, eventMeshMap, clientDistributionMap, judge, currEventMeshName); - if(eventMeshRecommendResult == null || eventMeshRecommendResult.size() != judge){ - logger.warn("doRebalance failed,recommendEventMeshNum is not consistent,recommendResult:{},judge:{}", eventMeshRecommendResult, judge); + List eventMeshRecommendResult = selectRedirectEventMesh(group, eventMeshMap, clientDistributionMap, + judge, currEventMeshName); + if (eventMeshRecommendResult == null || eventMeshRecommendResult.size() != judge) { + logger.warn("doRebalance failed,recommendEventMeshNum is not consistent,recommendResult:{},judge:{}", + eventMeshRecommendResult, judge); return; } //do redirect doRedirect(group, purpose, judge, eventMeshRecommendResult); - }else{ + } else { logger.info("rebalance condition not satisfy,group:{}, purpose:{},judge:{}", group, purpose, judge); } } - private void doRedirect(String group, String purpose, int judge, List eventMeshRecommendResult) throws Exception{ + private void doRedirect(String group, String purpose, int judge, List eventMeshRecommendResult) throws Exception { logger.info("doRebalance redirect start---------------------group:{},judge:{}", group, judge); Set sessionSet = null; - if(EventMeshConstants.PURPOSE_SUB.equals(purpose)) { + if (EventMeshConstants.PURPOSE_SUB.equals(purpose)) { sessionSet = eventMeshTCPServer.getClientSessionGroupMapping().getClientGroupMap().get(group).getGroupConsumerSessions(); - }else if(EventMeshConstants.PURPOSE_PUB.equals(purpose)){ + } else if (EventMeshConstants.PURPOSE_PUB.equals(purpose)) { sessionSet = eventMeshTCPServer.getClientSessionGroupMapping().getClientGroupMap().get(group).getGroupProducerSessions(); - }else{ - logger.warn("doRebalance failed,param is illegal, group:{}, purpose:{}",group, purpose); + } else { + logger.warn("doRebalance failed,param is illegal, group:{}, purpose:{}", group, purpose); return; } List sessionList = new ArrayList<>(sessionSet); Collections.shuffle(new ArrayList<>(sessionList)); - for(int i= 0; i ev } logger.info("doRebalance redirect end---------------------group:{}", group); } - - private List selectRedirectEventMesh(String group, Map eventMeshMap, Map clientDistributionMap, int judge, String evenMeshName)throws Exception{ + + private List selectRedirectEventMesh(String group, Map eventMeshMap, + Map clientDistributionMap, int judge, + String evenMeshName) throws Exception { EventMeshRecommendStrategy eventMeshRecommendStrategy = new EventMeshRecommendImpl(eventMeshTCPServer); - return eventMeshRecommendStrategy.calculateRedirectRecommendEventMesh(eventMeshMap, clientDistributionMap, group, judge, evenMeshName); + return eventMeshRecommendStrategy.calculateRedirectRecommendEventMesh(eventMeshMap, clientDistributionMap, + group, judge, evenMeshName); } - public int caculateRedirectNum(String eventMeshName, String group, String purpose, Map clientDistributionMap) throws Exception{ + public int caculateRedirectNum(String eventMeshName, String group, String purpose, + Map clientDistributionMap) throws Exception { int sum = 0; - for(Integer item : clientDistributionMap.values()){ + for (Integer item : clientDistributionMap.values()) { sum += item.intValue(); } int currentNum = 0; - if(clientDistributionMap.get(eventMeshName) != null){ + if (clientDistributionMap.get(eventMeshName) != null) { currentNum = clientDistributionMap.get(eventMeshName); } int avgNum = sum / clientDistributionMap.size(); @@ -183,64 +204,75 @@ public int caculateRedirectNum(String eventMeshName, String group, String purpos List eventMeshList = new ArrayList<>(clientDistributionMap.keySet()); Collections.sort(eventMeshList); int index = -1; - for(int i=0; i < Math.min(modNum, eventMeshList.size()); i++){ - if(StringUtils.equals(eventMeshName, eventMeshList.get(i))){ + for (int i = 0; i < Math.min(modNum, eventMeshList.size()); i++) { + if (StringUtils.equals(eventMeshName, eventMeshList.get(i))) { index = i; break; } } int rebalanceResult = 0; - if(avgNum == 0){ + if (avgNum == 0) { rebalanceResult = 1; - }else { + } else { rebalanceResult = (modNum != 0 && index < modNum && index >= 0) ? avgNum + 1 : avgNum; } - logger.info("rebalance caculateRedirectNum,group:{}, purpose:{},sum:{},avgNum:{}," + - "modNum:{}, index:{}, currentNum:{}, rebalanceResult:{}", group, purpose, sum, + logger.info("rebalance caculateRedirectNum,group:{}, purpose:{},sum:{},avgNum:{}," + + + "modNum:{}, index:{}, currentNum:{}, rebalanceResult:{}", group, purpose, sum, avgNum, modNum, index, currentNum, rebalanceResult); return currentNum - rebalanceResult; } - private Map queryLocalEventMeshDistributeData(String cluster, String group, String purpose, Map eventMeshMap){ + private Map queryLocalEventMeshDistributeData(String cluster, String group, String purpose, + Map eventMeshMap) { Map localEventMeshDistributeData = null; Map> eventMeshClientDistributionDataMap = null; - try{ - eventMeshClientDistributionDataMap = eventMeshTCPServer.getRegistry().findEventMeshClientDistributionData(cluster, group, purpose); + try { + eventMeshClientDistributionDataMap = eventMeshTCPServer.getRegistry().findEventMeshClientDistributionData( + cluster, group, purpose); - if(eventMeshClientDistributionDataMap == null || eventMeshClientDistributionDataMap.size() == 0){ - logger.warn("doRebalance failed,found no distribute data in regitry, cluster:{}, group:{}, purpose:{}", cluster, group, purpose); + if (eventMeshClientDistributionDataMap == null || eventMeshClientDistributionDataMap.size() == 0) { + logger.warn("doRebalance failed,found no distribute data in regitry, cluster:{}, group:{}, purpose:{}", + cluster, group, purpose); return null; } localEventMeshDistributeData = new HashMap<>(); String localIdc = eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshIDC; - for(Map.Entry> entry : eventMeshClientDistributionDataMap.entrySet()){ + for (Map.Entry> entry : eventMeshClientDistributionDataMap.entrySet()) { String idc = entry.getKey().split("-")[0]; - if(StringUtils.isNotBlank(idc) && StringUtils.equals(idc, localIdc)){ + if (StringUtils.isNotBlank(idc) && StringUtils.equals(idc, localIdc)) { localEventMeshDistributeData.put(entry.getKey(), entry.getValue().get(purpose)); } } - if(0 == localEventMeshDistributeData.size()){ - logger.warn("doRebalance failed,found no distribute data of localIDC in regitry,cluster:{},group:{}, purpose:{},localIDC:{}", cluster, group, purpose, localIdc); + if (0 == localEventMeshDistributeData.size()) { + logger.warn("doRebalance failed,found no distribute data of localIDC in regitry,cluster:{},group:{}, purpose:{},localIDC:{}", + cluster, group, purpose, localIdc); return null; } - logger.info("before revert clientDistributionMap:{}, group:{}, purpose:{}", localEventMeshDistributeData, group, purpose); - for(String eventMeshName : localEventMeshDistributeData.keySet()){ - if(!eventMeshMap.keySet().contains(eventMeshName)){ - logger.warn("doRebalance failed,exist eventMesh not register but exist in distributionMap,cluster:{},grpup:{},purpose:{},eventMeshName:{}", cluster, group, purpose, eventMeshName); + logger.info("before revert clientDistributionMap:{}, group:{}, purpose:{}", localEventMeshDistributeData, + group, purpose); + for (String eventMeshName : localEventMeshDistributeData.keySet()) { + if (!eventMeshMap.keySet().contains(eventMeshName)) { + logger.warn( + "doRebalance failed,exist eventMesh not register but exist in " + + "distributionMap,cluster:{},grpup:{},purpose:{},eventMeshName:{}", + cluster, group, purpose, eventMeshName); return null; } } - for(String eventMesh : eventMeshMap.keySet()){ - if(!localEventMeshDistributeData.keySet().contains(eventMesh)){ + for (String eventMesh : eventMeshMap.keySet()) { + if (!localEventMeshDistributeData.keySet().contains(eventMesh)) { localEventMeshDistributeData.put(eventMesh, 0); } } - logger.info("after revert clientDistributionMap:{}, group:{}, purpose:{}", localEventMeshDistributeData, group, purpose); - }catch (Exception e){ - logger.warn("doRebalance failed,cluster:{},group:{},purpose:{},findProxyClientDistributionData failed, errMsg:{}", cluster, group, purpose, e); + logger.info("after revert clientDistributionMap:{}, group:{}, purpose:{}", localEventMeshDistributeData, + group, purpose); + } catch (Exception e) { + logger.warn("doRebalance failed,cluster:{},group:{},purpose:{},findProxyClientDistributionData failed, errMsg:{}", + cluster, group, purpose, e); return null; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/recommend/EventMeshRecommendImpl.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/recommend/EventMeshRecommendImpl.java index 4b5091f413..290e3d4ffb 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/recommend/EventMeshRecommendImpl.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/recommend/EventMeshRecommendImpl.java @@ -14,19 +14,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.collections4.MapUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.api.registry.dto.EventMeshDataInfo; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.util.ValueComparator; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.MapUtils; +import org.apache.commons.lang3.StringUtils; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.*; - public class EventMeshRecommendImpl implements EventMeshRecommendStrategy { protected final Logger logger = LoggerFactory.getLogger(EventMeshRecommendImpl.class); @@ -40,63 +47,66 @@ public EventMeshRecommendImpl(EventMeshTCPServer eventMeshTCPServer) { @Override public String calculateRecommendEventMesh(String group, String purpose) throws Exception { List eventMeshDataInfoList = null; - if(StringUtils.isBlank(group) || StringUtils.isBlank(purpose)){ + if (StringUtils.isBlank(group) || StringUtils.isBlank(purpose)) { logger.warn("EventMeshRecommend failed,params illegal,group:{},purpose:{}", group, purpose); return null; } final String cluster = eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshCluster; - try{ + try { eventMeshDataInfoList = eventMeshTCPServer.getRegistry().findEventMeshInfoByCluster(cluster); - }catch (Exception e){ - logger.warn("EventMeshRecommend failed, findEventMeshInfoByCluster failed, cluster:{}, group:{}, purpose:{}, errMsg:{}", cluster, group , purpose, e); + } catch (Exception e) { + logger.warn("EventMeshRecommend failed, findEventMeshInfoByCluster failed, cluster:{}, group:{}, purpose:{}, errMsg:{}", + cluster, group, purpose, e); return null; } - if(eventMeshDataInfoList == null || CollectionUtils.isEmpty(eventMeshDataInfoList)){ - logger.warn("EventMeshRecommend failed,not find eventMesh instances from registry,cluster:{},group:{},purpose:{}", cluster, group, purpose); + if (eventMeshDataInfoList == null || CollectionUtils.isEmpty(eventMeshDataInfoList)) { + logger.warn("EventMeshRecommend failed,not find eventMesh instances from registry,cluster:{},group:{},purpose:{}", + cluster, group, purpose); return null; } Map localEventMeshMap = new HashMap<>(); Map remoteEventMeshMap = new HashMap<>(); String localIdc = eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshIDC; - for(EventMeshDataInfo eventMeshDataInfo : eventMeshDataInfoList){ + for (EventMeshDataInfo eventMeshDataInfo : eventMeshDataInfoList) { String idc = eventMeshDataInfo.getEventMeshName().split("-")[0]; - if(StringUtils.isNotBlank(idc)){ - if(StringUtils.equals(idc, localIdc)){ + if (StringUtils.isNotBlank(idc)) { + if (StringUtils.equals(idc, localIdc)) { localEventMeshMap.put(eventMeshDataInfo.getEventMeshName(), eventMeshDataInfo.getEndpoint()); - }else{ + } else { remoteEventMeshMap.put(eventMeshDataInfo.getEventMeshName(), eventMeshDataInfo.getEndpoint()); } - }else{ + } else { logger.error("EventMeshName may be illegal,idc is null,eventMeshName:{}", eventMeshDataInfo.getEventMeshName()); } } - if(localEventMeshMap.size() ==0 && remoteEventMeshMap.size()==0){ + if (localEventMeshMap.size() == 0 && remoteEventMeshMap.size() == 0) { logger.warn("EventMeshRecommend failed,find no legal eventMesh instances from registry,localIDC:{}", localIdc); return null; } - if(localEventMeshMap.size() > 0){ + if (localEventMeshMap.size() > 0) { //recommend eventmesh of local idc - return recommendProxyByDistributeData(cluster,group,purpose,localEventMeshMap,true); - }else if(remoteEventMeshMap.size() > 0){ + return recommendProxyByDistributeData(cluster, group, purpose, localEventMeshMap, true); + } else if (remoteEventMeshMap.size() > 0) { //recommend eventmesh of other idc - return recommendProxyByDistributeData(cluster,group,purpose,remoteEventMeshMap,false); - }else { + return recommendProxyByDistributeData(cluster, group, purpose, remoteEventMeshMap, false); + } else { logger.error("localEventMeshMap or remoteEventMeshMap size error"); return null; } } @Override - public List calculateRedirectRecommendEventMesh(Map eventMeshMap, Map clientDistributeMap, String group, int recommendProxyNum, String eventMeshName) throws Exception { - if(recommendProxyNum < 1){ + public List calculateRedirectRecommendEventMesh(Map eventMeshMap, + Map clientDistributeMap, String group, + int recommendProxyNum, String eventMeshName) throws Exception { + if (recommendProxyNum < 1) { return null; } - logger.info("eventMeshMap:{},clientDistributionMap:{},group:{},recommendNum:{},currEventMeshName:{}", eventMeshMap,clientDistributeMap,group,recommendProxyNum, eventMeshName); - List recommendProxyList = null; - + logger.info("eventMeshMap:{},clientDistributionMap:{},group:{},recommendNum:{},currEventMeshName:{}", + eventMeshMap, clientDistributeMap, group, recommendProxyNum, eventMeshName); //find eventmesh with least client List> list = new ArrayList<>(); ValueComparator vc = new ValueComparator(); @@ -106,71 +116,80 @@ public List calculateRedirectRecommendEventMesh(Map even Collections.sort(list, vc); logger.info("clientDistributionMap after sort:{}", list); - recommendProxyList = new ArrayList<>(recommendProxyNum); - while(recommendProxyList.size() < recommendProxyNum){ + List recommendProxyList = new ArrayList<>(recommendProxyNum); + while (recommendProxyList.size() < recommendProxyNum) { Map.Entry minProxyItem = list.get(0); int currProxyNum = clientDistributeMap.get(eventMeshName); recommendProxyList.add(eventMeshMap.get(minProxyItem.getKey())); - clientDistributeMap.put(minProxyItem.getKey(),minProxyItem.getValue() + 1); - clientDistributeMap.put(eventMeshName,currProxyNum - 1); + clientDistributeMap.put(minProxyItem.getKey(), minProxyItem.getValue() + 1); + clientDistributeMap.put(eventMeshName, currProxyNum - 1); Collections.sort(list, vc); logger.info("clientDistributionMap after sort:{}", list); } - logger.info("choose proxys with min instance num, group:{}, recommendProxyNum:{}, recommendProxyList:{}", group, recommendProxyNum, recommendProxyList); + logger.info("choose proxys with min instance num, group:{}, recommendProxyNum:{}, recommendProxyList:{}", + group, recommendProxyNum, recommendProxyList); return recommendProxyList; } - private String recommendProxyByDistributeData(String cluster, String group, String purpose, Map eventMeshMap, boolean caculateLocal){ - logger.info("eventMeshMap:{},cluster:{},group:{},purpose:{},caculateLocal:{}", eventMeshMap,cluster,group,purpose,caculateLocal); + private String recommendProxyByDistributeData(String cluster, String group, String purpose, + Map eventMeshMap, boolean caculateLocal) { + logger.info("eventMeshMap:{},cluster:{},group:{},purpose:{},caculateLocal:{}", eventMeshMap, cluster, + group, purpose, caculateLocal); String recommendProxyAddr = null; List tmpProxyAddrList = null; Map> eventMeshClientDistributionDataMap = null; - try{ - eventMeshClientDistributionDataMap = eventMeshTCPServer.getRegistry().findEventMeshClientDistributionData(cluster, group, purpose); - }catch (Exception e){ - logger.warn("EventMeshRecommend failed,findEventMeshClientDistributionData failed,cluster:{},group:{},purpose:{}, errMsg:{}",cluster,group,purpose, e); + try { + eventMeshClientDistributionDataMap = eventMeshTCPServer.getRegistry().findEventMeshClientDistributionData( + cluster, group, purpose); + } catch (Exception e) { + logger.warn("EventMeshRecommend failed,findEventMeshClientDistributionData failed," + + "cluster:{},group:{},purpose:{}, errMsg:{}", cluster, group, purpose, e); } - if(eventMeshClientDistributionDataMap == null || MapUtils.isEmpty(eventMeshClientDistributionDataMap)) { + if (eventMeshClientDistributionDataMap == null || MapUtils.isEmpty(eventMeshClientDistributionDataMap)) { tmpProxyAddrList = new ArrayList<>(eventMeshMap.values()); Collections.shuffle(tmpProxyAddrList); recommendProxyAddr = tmpProxyAddrList.get(0); - logger.info("No distribute data in registry,cluster:{}, group:{},purpose:{}, recommendProxyAddr:{}", cluster, group, purpose, recommendProxyAddr); + logger.info("No distribute data in registry,cluster:{}, group:{},purpose:{}, recommendProxyAddr:{}", + cluster, group, purpose, recommendProxyAddr); return recommendProxyAddr; } Map localClientDistributionMap = new HashMap<>(); Map remoteClientDistributionMap = new HashMap<>(); - for(Map.Entry> entry : eventMeshClientDistributionDataMap.entrySet()){ + for (Map.Entry> entry : eventMeshClientDistributionDataMap.entrySet()) { String idc = entry.getKey().split("-")[0]; - if(StringUtils.isNotBlank(idc)) { + if (StringUtils.isNotBlank(idc)) { if (StringUtils.equals(idc, eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshIDC)) { localClientDistributionMap.put(entry.getKey(), entry.getValue().get(purpose)); } else { remoteClientDistributionMap.put(entry.getKey(), entry.getValue().get(purpose)); } - }else { - logger.error("eventMeshName may be illegal,idc is null,eventMeshName:{}",entry.getKey()); + } else { + logger.error("eventMeshName may be illegal,idc is null,eventMeshName:{}", entry.getKey()); } } - recommendProxyAddr = recommendProxy(eventMeshMap, (caculateLocal == true) ? localClientDistributionMap : remoteClientDistributionMap, group); - logger.info("eventMeshMap:{},group:{},purpose:{},caculateLocal:{},recommendProxyAddr:{}",eventMeshMap,group,purpose,caculateLocal,recommendProxyAddr); + recommendProxyAddr = recommendProxy(eventMeshMap, (caculateLocal == true) ? localClientDistributionMap + : remoteClientDistributionMap, group); + + logger.info("eventMeshMap:{},group:{},purpose:{},caculateLocal:{},recommendProxyAddr:{}", eventMeshMap, + group, purpose, caculateLocal, recommendProxyAddr); return recommendProxyAddr; } - private String recommendProxy(Map eventMeshMap,Map clientDistributionMap,String group){ - logger.info("eventMeshMap:{},clientDistributionMap:{},group:{}", eventMeshMap,clientDistributionMap,group); + private String recommendProxy(Map eventMeshMap, Map clientDistributionMap, String group) { + logger.info("eventMeshMap:{},clientDistributionMap:{},group:{}", eventMeshMap, clientDistributionMap, group); String recommendProxy = null; - for(String proxyName : clientDistributionMap.keySet()){ - if(!eventMeshMap.keySet().contains(proxyName)){ + for (String proxyName : clientDistributionMap.keySet()) { + if (!eventMeshMap.keySet().contains(proxyName)) { logger.warn("exist proxy not register but exist in distributionMap,proxy:{}", proxyName); return null; } } - for(String proxy : eventMeshMap.keySet()){ - if(!clientDistributionMap.keySet().contains(proxy)){ + for (String proxy : eventMeshMap.keySet()) { + if (!clientDistributionMap.keySet().contains(proxy)) { clientDistributionMap.put(proxy, 0); } } @@ -181,10 +200,10 @@ private String recommendProxy(Map eventMeshMap,Map entry : clientDistributionMap.entrySet()) { list.add(entry); } - if(list.size() == 0){ + if (list.size() == 0) { logger.error("no legal distribute data,check eventMeshMap and distributeData, group:{}", group); return null; - }else{ + } else { Collections.sort(list, vc); logger.info("clientDistributionMap after sort:{}", list); recommendProxy = eventMeshMap.get(list.get(0).getKey()); @@ -192,7 +211,8 @@ private String recommendProxy(Map eventMeshMap,Map calculate(Map proxyMap,Map clientDistributionMap,String group, int recommendProxyNum){ + private List calculate(Map proxyMap, Map clientDistributionMap, + String group, int recommendProxyNum) { return null; } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/recommend/EventMeshRecommendStrategy.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/recommend/EventMeshRecommendStrategy.java index f17a513fe2..515cf3bc83 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/recommend/EventMeshRecommendStrategy.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/recommend/EventMeshRecommendStrategy.java @@ -14,13 +14,19 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend; import java.util.List; import java.util.Map; +/** + * EventMeshRecommendStrategy + */ public interface EventMeshRecommendStrategy { String calculateRecommendEventMesh(String group, String purpose) throws Exception; - List calculateRedirectRecommendEventMesh(Map eventMeshMap, Map clientDistributeMap, String group, int recommendNum, String eventMeshName) throws Exception; + List calculateRedirectRecommendEventMesh(Map eventMeshMap, + Map clientDistributeMap, String group, + int recommendNum, String eventMeshName) throws Exception; } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java index e241bb2ab3..c1a4dc92a4 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/Session.java @@ -19,22 +19,12 @@ import static org.apache.eventmesh.common.protocol.tcp.Command.LISTEN_RESPONSE; -import java.lang.ref.WeakReference; -import java.net.InetSocketAddress; -import java.util.List; -import java.util.concurrent.locks.ReentrantLock; - -import io.cloudevents.CloudEvent; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.api.SendCallback; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.SubscriptionItem; -import org.apache.eventmesh.common.protocol.tcp.*; +import org.apache.eventmesh.common.protocol.tcp.Header; +import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.configuration.EventMeshTCPConfiguration; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.group.ClientGroupWrapper; @@ -44,9 +34,22 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.send.SessionSender; import org.apache.eventmesh.runtime.util.RemotingHelper; import org.apache.eventmesh.runtime.util.Utils; + +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.lang.ref.WeakReference; +import java.net.InetSocketAddress; +import java.util.List; +import java.util.concurrent.locks.ReentrantLock; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; + public class Session { protected final Logger messageLogger = LoggerFactory.getLogger("message"); @@ -227,15 +230,24 @@ public void operationComplete(ChannelFuture future) throws Exception { @Override public String toString() { - return "Session{" + - "sysId=" + clientGroupWrapper.get().getSysId() + - ",remoteAddr=" + RemotingHelper.parseSocketAddressAddr(remoteAddress) + - ",client=" + client + - ",sessionState=" + sessionState + - ",sessionContext=" + sessionContext + - ",pusher=" + pusher + - ",sender=" + sender + - ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + + return "Session{" + + + "sysId=" + clientGroupWrapper.get().getSysId() + + + ",remoteAddr=" + RemotingHelper.parseSocketAddressAddr(remoteAddress) + + + ",client=" + client + + + ",sessionState=" + sessionState + + + ",sessionContext=" + sessionContext + + + ",pusher=" + pusher + + + ",sender=" + sender + + + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + + ",lastHeartbeatTime=" + DateFormatUtils.format(lastHeartbeatTime, EventMeshConstants.DATE_FORMAT) + '}'; } @@ -319,17 +331,17 @@ public boolean isAvailable(String topic) { } if (!sessionContext.subscribeTopics.containsKey(topic)) { - logger.warn("session is not available because session has not subscribe topic:{},client:{}", topic,client); + logger.warn("session is not available because session has not subscribe topic:{},client:{}", topic, client); return false; } return true; } -// @Override -// public int hashCode() { -// int code = 37 + (client != null ? client.hashCode() : 0) + (context != null ? context.hashCode() : 0) -// + (sessionState != null ? sessionState.hashCode() : 0); -// return code; -// } + //@Override + //public int hashCode() { + // int code = 37 + (client != null ? client.hashCode() : 0) + (context != null ? context.hashCode() : 0) + // + (sessionState != null ? sessionState.hashCode() : 0); + // return code; + //} } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/SessionContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/SessionContext.java index e8f851baec..802b6e1c0e 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/SessionContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/SessionContext.java @@ -17,12 +17,13 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.session; -import java.util.concurrent.ConcurrentHashMap; - -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.concurrent.ConcurrentHashMap; + public class SessionContext { private Session session; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/ClientAckContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/ClientAckContext.java index 3b1e0dbbed..608655bb1d 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/ClientAckContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/ClientAckContext.java @@ -17,20 +17,22 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push; -import java.util.List; - -import io.cloudevents.CloudEvent; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.api.AbstractContext; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.plugin.MQConsumerWrapper; import org.apache.eventmesh.runtime.util.EventMeshUtil; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; + +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.cloudevents.CloudEvent; + public class ClientAckContext { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -54,7 +56,7 @@ public ClientAckContext(String seq, AbstractContext context, List ev this.consumer = consumer; this.createTime = System.currentTimeMillis(); String ttlStr = events.get(0).getExtension(EventMeshConstants.PROPERTY_MESSAGE_TTL).toString(); - long ttl = StringUtils.isNumeric(ttlStr)? Long.parseLong(ttlStr) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; + long ttl = StringUtils.isNumeric(ttlStr) ? Long.parseLong(ttlStr) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; this.expireTime = System.currentTimeMillis() + ttl; } @@ -109,22 +111,27 @@ public MQConsumerWrapper getConsumer() { public void ackMsg() { if (consumer != null && context != null && events != null) { consumer.updateOffset(events, context); -// ConsumeMessageService consumeMessageService = consumer..getDefaultMQPushConsumerImpl().getConsumeMessageService(); -// ((ConsumeMessageConcurrentlyService)consumeMessageService).updateOffset(msgs, context); + //ConsumeMessageService consumeMessageService = consumer..getDefaultMQPushConsumerImpl().getConsumeMessageService(); + //((ConsumeMessageConcurrentlyService)consumeMessageService).updateOffset(msgs, context); logger.info("ackMsg topic:{}, bizSeq:{}", events.get(0).getSubject(), EventMeshUtil.getMessageBizSeq(events.get(0))); } else { - logger.warn("ackMsg failed,consumer is null:{}, context is null:{} , msgs is null:{}", consumer == null, context == null, events == null); + logger.warn("ackMsg failed,consumer is null:{}, context is null:{} , msgs is null:{}", + consumer == null, context == null, events == null); } } @Override public String toString() { - return "ClientAckContext{" + - ",seq=" + seq + -// TODO ",consumer=" + consumer.getDefaultMQPushConsumer().getMessageModel() + -// ",consumerGroup=" + consumer.getDefaultMQPushConsumer().getConsumerGroup() + - ",topic=" + (CollectionUtils.size(events) > 0 ? events.get(0).getSubject() : null) + - ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + + return "ClientAckContext{" + + + ",seq=" + seq + + + //TODO ",consumer=" + consumer.getDefaultMQPushConsumer().getMessageModel() + + // ",consumerGroup=" + consumer.getDefaultMQPushConsumer().getConsumerGroup() + + ",topic=" + (CollectionUtils.size(events) > 0 ? events.get(0).getSubject() : null) + + + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + + ",expireTime=" + DateFormatUtils.format(expireTime, EventMeshConstants.DATE_FORMAT) + '}'; } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/DownStreamMsgContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/DownStreamMsgContext.java index cb6b7d845e..f4244e767a 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/DownStreamMsgContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/DownStreamMsgContext.java @@ -17,11 +17,7 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push; -import io.cloudevents.CloudEvent; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.api.AbstractContext; -import org.apache.eventmesh.common.Constants; import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.runtime.constants.EventMeshConstants; @@ -30,11 +26,18 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.retry.RetryContext; import org.apache.eventmesh.runtime.util.EventMeshUtil; import org.apache.eventmesh.runtime.util.ServerGlobal; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; + import java.util.ArrayList; import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.cloudevents.CloudEvent; + public class DownStreamMsgContext extends RetryContext { private final Logger logger = LoggerFactory.getLogger(this.getClass()); @@ -55,7 +58,9 @@ public class DownStreamMsgContext extends RetryContext { public boolean msgFromOtherEventMesh; - public DownStreamMsgContext(CloudEvent event, Session session, MQConsumerWrapper consumer, AbstractContext consumeConcurrentlyContext, boolean msgFromOtherEventMesh, SubscriptionItem subscriptionItem) { + public DownStreamMsgContext(CloudEvent event, Session session, MQConsumerWrapper consumer, + AbstractContext consumeConcurrentlyContext, boolean msgFromOtherEventMesh, + SubscriptionItem subscriptionItem) { this.seq = String.valueOf(ServerGlobal.getInstance().getMsgCounter().incrementAndGet()); this.event = event; this.session = session; @@ -65,8 +70,9 @@ public DownStreamMsgContext(CloudEvent event, Session session, MQConsumerWrapper this.createTime = System.currentTimeMillis(); this.subscriptionItem = subscriptionItem; String ttlStr = (String) event.getExtension("TTL"); -// String ttlStr = msgExt.getUserProperties("TTL"); - long ttl = StringUtils.isNumeric(ttlStr) ? Long.parseLong(ttlStr) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; + //String ttlStr = msgExt.getUserProperties("TTL"); + long ttl = StringUtils.isNumeric(ttlStr) ? Long.parseLong(ttlStr) : + EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; this.expireTime = System.currentTimeMillis() + ttl; this.msgFromOtherEventMesh = msgFromOtherEventMesh; } @@ -80,34 +86,47 @@ public void ackMsg() { List events = new ArrayList(); events.add(event); consumer.updateOffset(events, consumeConcurrentlyContext); -// ConsumeMessageService consumeMessageService = consumer.getDefaultMQPushConsumer().getDefaultMQPushConsumerImpl().getConsumeMessageService(); -// ((ConsumeMessageConcurrentlyService)consumeMessageService).updateOffset(msgs, consumeConcurrentlyContext); + //ConsumeMessageService consumeMessageService = + // consumer.getDefaultMQPushConsumer().getDefaultMQPushConsumerImpl().getConsumeMessageService(); + //((ConsumeMessageConcurrentlyService)consumeMessageService).updateOffset(msgs, consumeConcurrentlyContext); logger.info("ackMsg seq:{}, topic:{}, bizSeq:{}", seq, events.get(0).getSubject(), events.get(0).getExtension(EventMeshConstants.PROPERTY_MESSAGE_KEYS)); } else { - logger.warn("ackMsg seq:{} failed,consumer is null:{}, context is null:{} , msgs is null:{}", seq, consumer == null, consumeConcurrentlyContext == null, event == null); + logger.warn("ackMsg seq:{} failed,consumer is null:{}, context is null:{} , msgs is null:{}", seq, + consumer == null, consumeConcurrentlyContext == null, event == null); } } @Override public String toString() { - return "DownStreamMsgContext{" + - ",seq=" + seq + - ",client=" + (session == null ? null : session.getClient()) + - ",retryTimes=" + retryTimes + - ",consumer=" + consumer + -// todo ",consumerGroup=" + consumer.getClass().getConsumerGroup() + - ",topic=" + event.getSubject() + - ",subscriptionItem=" + subscriptionItem + - ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + - ",executeTime=" + DateFormatUtils.format(executeTime, EventMeshConstants.DATE_FORMAT) + - ",lastPushTime=" + DateFormatUtils.format(lastPushTime, EventMeshConstants.DATE_FORMAT) + '}'; + return "DownStreamMsgContext{" + + + ",seq=" + seq + + + ",client=" + (session == null ? null : session.getClient()) + + + ",retryTimes=" + retryTimes + + + ",consumer=" + consumer + + + // todo ",consumerGroup=" + consumer.getClass().getConsumerGroup() + + ",topic=" + event.getSubject() + + + ",subscriptionItem=" + subscriptionItem + + + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + + + ",executeTime=" + DateFormatUtils.format(executeTime, EventMeshConstants.DATE_FORMAT) + + + ",lastPushTime=" + DateFormatUtils.format(lastPushTime, EventMeshConstants.DATE_FORMAT) + + '}'; } @Override public void retry() { try { - logger.info("retry downStream msg start,seq:{},retryTimes:{},bizSeq:{}", this.seq, this.retryTimes, EventMeshUtil.getMessageBizSeq(this.event)); + logger.info("retry downStream msg start,seq:{},retryTimes:{},bizSeq:{}", this.seq, this.retryTimes, + EventMeshUtil.getMessageBizSeq(this.event)); if (isRetryMsgTimeout(this)) { return; @@ -119,18 +138,20 @@ public void retry() { String topic = this.event.getSubject(); if (!SubscriptionMode.BROADCASTING.equals(this.subscriptionItem.getMode())) { rechoosen = this.session.getClientGroupWrapper() - .get().getDownstreamDispatchStrategy().select(this.session.getClientGroupWrapper().get().getSysId() - , topic, this.session.getClientGroupWrapper().get().getGroupConsumerSessions()); + .get().getDownstreamDispatchStrategy().select(this.session.getClientGroupWrapper().get().getSysId(), + topic, this.session.getClientGroupWrapper().get().getGroupConsumerSessions()); } else { rechoosen = this.session; } if (rechoosen == null) { - logger.warn("retry, found no session to downstream msg,seq:{}, retryTimes:{}, bizSeq:{}", this.seq, this.retryTimes, EventMeshUtil.getMessageBizSeq(this.event)); + logger.warn("retry, found no session to downstream msg,seq:{}, retryTimes:{}, bizSeq:{}", this.seq, + this.retryTimes, EventMeshUtil.getMessageBizSeq(this.event)); } else { this.session = rechoosen; rechoosen.downstreamMsg(this); - logger.info("retry downStream msg end,seq:{},retryTimes:{},bizSeq:{}", this.seq, this.retryTimes, EventMeshUtil.getMessageBizSeq(this.event)); + logger.info("retry downStream msg end,seq:{},retryTimes:{},bizSeq:{}", this.seq, this.retryTimes, + EventMeshUtil.getMessageBizSeq(this.event)); } } catch (Exception e) { logger.error("retry-dispatcher error!", e); @@ -140,7 +161,8 @@ public void retry() { private boolean isRetryMsgTimeout(DownStreamMsgContext downStreamMsgContext) { boolean flag = false; String ttlStr = (String) downStreamMsgContext.event.getExtension(EventMeshConstants.PROPERTY_MESSAGE_TTL); - long ttl = StringUtils.isNumeric(ttlStr) ? Long.parseLong(ttlStr) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS;; + long ttl = StringUtils.isNumeric(ttlStr) ? Long.parseLong(ttlStr) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; + ; String storeTimeStr = (String) downStreamMsgContext.event.getExtension(EventMeshConstants.STORE_TIME); long storeTimestamp = StringUtils.isNumeric(storeTimeStr) ? Long.parseLong(storeTimeStr) : 0; @@ -148,10 +170,13 @@ private boolean isRetryMsgTimeout(DownStreamMsgContext downStreamMsgContext) { long brokerCost = StringUtils.isNumeric(leaveTimeStr) ? Long.parseLong(leaveTimeStr) - storeTimestamp : 0; String arriveTimeStr = (String) downStreamMsgContext.event.getExtension(EventMeshConstants.ARRIVE_TIME); - long accessCost = StringUtils.isNumeric(arriveTimeStr) ? System.currentTimeMillis() - Long.parseLong(arriveTimeStr) : 0; + long accessCost = StringUtils.isNumeric(arriveTimeStr) ? System.currentTimeMillis() - Long.parseLong(arriveTimeStr) + : 0; + double elapseTime = brokerCost + accessCost; if (elapseTime >= ttl) { - logger.warn("discard the retry because timeout, seq:{}, retryTimes:{}, bizSeq:{}", downStreamMsgContext.seq, downStreamMsgContext.retryTimes, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.event)); + logger.warn("discard the retry because timeout, seq:{}, retryTimes:{}, bizSeq:{}", downStreamMsgContext.seq, + downStreamMsgContext.retryTimes, EventMeshUtil.getMessageBizSeq(downStreamMsgContext.event)); flag = true; eventMeshAckMsg(downStreamMsgContext); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/PushContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/PushContext.java index d236e5b72c..7b721467f3 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/PushContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/PushContext.java @@ -17,11 +17,14 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicLong; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; + import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.time.DateFormatUtils; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; + +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicLong; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -67,10 +70,14 @@ public ConcurrentHashMap getUnAckMsg() { @Override public String toString() { - return "PushContext{" + - "deliveredMsgsCount=" + deliveredMsgsCount.longValue() + - ",deliverFailCount=" + deliverFailMsgsCount.longValue() + - ",unAckMsg=" + CollectionUtils.size(unAckMsg) + + return "PushContext{" + + + "deliveredMsgsCount=" + deliveredMsgsCount.longValue() + + + ",deliverFailCount=" + deliverFailMsgsCount.longValue() + + + ",unAckMsg=" + CollectionUtils.size(unAckMsg) + + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + '}'; } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/SessionPusher.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/SessionPusher.java index ef339f0999..55ac95fd17 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/SessionPusher.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/push/SessionPusher.java @@ -17,27 +17,33 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push; -import io.cloudevents.core.builder.CloudEventBuilder; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import org.apache.commons.collections4.CollectionUtils; import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.SubscriptionMode; -import org.apache.eventmesh.common.protocol.tcp.*; +import org.apache.eventmesh.common.protocol.SubscriptionType; +import org.apache.eventmesh.common.protocol.tcp.Command; +import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; +import org.apache.eventmesh.common.protocol.tcp.Header; +import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.protocol.api.ProtocolAdaptor; import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.EventMeshUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.collections4.CollectionUtils; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicLong; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.cloudevents.core.builder.CloudEventBuilder; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; + public class SessionPusher { private final Logger messageLogger = LoggerFactory.getLogger("message"); @@ -58,9 +64,12 @@ public SessionPusher(Session session) { @Override public String toString() { - return "SessionPusher{" + - "deliveredMsgsCount=" + deliveredMsgsCount.longValue() + - ",deliverFailCount=" + deliverFailMsgsCount.longValue() + + return "SessionPusher{" + + + "deliveredMsgsCount=" + deliveredMsgsCount.longValue() + + + ",deliverFailCount=" + deliverFailMsgsCount.longValue() + + ",unAckMsg=" + CollectionUtils.size(downStreamMap) + '}'; } @@ -83,7 +92,8 @@ public void push(final DownStreamMsgContext downStreamMsgContext) { downStreamMsgContext.event = CloudEventBuilder.from(downStreamMsgContext.event) .withExtension(EventMeshConstants.REQ_EVENTMESH2C_TIMESTAMP, String.valueOf(System.currentTimeMillis())) .build(); -// downStreamMsgContext.event.getSystemProperties().put(EventMeshConstants.REQ_EVENTMESH2C_TIMESTAMP, String.valueOf(System.currentTimeMillis())); + //downStreamMsgContext.event.getSystemProperties().put(EventMeshConstants.REQ_EVENTMESH2C_TIMESTAMP, + //String.valueOf(System.currentTimeMillis())); EventMeshMessage body = null; int retCode = 0; String retMsg = null; @@ -104,11 +114,13 @@ public void push(final DownStreamMsgContext downStreamMsgContext) { @Override public void operationComplete(ChannelFuture future) throws Exception { if (!future.isSuccess()) { - logger.error("downstreamMsg fail,seq:{}, retryTimes:{}, event:{}", downStreamMsgContext.seq, downStreamMsgContext.retryTimes, downStreamMsgContext.event); + logger.error("downstreamMsg fail,seq:{}, retryTimes:{}, event:{}", downStreamMsgContext.seq, + downStreamMsgContext.retryTimes, downStreamMsgContext.event); deliverFailMsgsCount.incrementAndGet(); //how long to isolate client when push fail - long isolateTime = System.currentTimeMillis() + session.getEventMeshTCPConfiguration().eventMeshTcpPushFailIsolateTimeInMills; + long isolateTime = System.currentTimeMillis() + + session.getEventMeshTCPConfiguration().eventMeshTcpPushFailIsolateTimeInMills; session.setIsolateTime(isolateTime); logger.warn("isolate client:{},isolateTime:{}", session.getClient(), isolateTime); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/retry/EventMeshTcpRetryer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/retry/EventMeshTcpRetryer.java index ba8f96cd4b..d7939d8f57 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/retry/EventMeshTcpRetryer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/retry/EventMeshTcpRetryer.java @@ -22,14 +22,15 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push.DownStreamMsgContext; import org.apache.eventmesh.runtime.util.EventMeshThreadFactoryImpl; import org.apache.eventmesh.runtime.util.EventMeshUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.DelayQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class EventMeshTcpRetryer { public static Logger logger = LoggerFactory.getLogger(EventMeshTcpRetryer.class); @@ -122,6 +123,6 @@ public int getRetrySize() { } public void printRetryThreadPoolState() { -// ThreadPoolHelper.printState(pool); + //ThreadPoolHelper.printState(pool); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/retry/RetryContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/retry/RetryContext.java index 373f3ed357..9a5359ee01 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/retry/RetryContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/retry/RetryContext.java @@ -54,5 +54,5 @@ public long getDelay(TimeUnit unit) { return unit.convert(this.executeTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS); } - abstract public void retry(); + public abstract void retry(); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/send/SessionSender.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/send/SessionSender.java index 3401088721..f4615f251c 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/send/SessionSender.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/send/SessionSender.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.session.send; -import io.cloudevents.core.builder.CloudEventBuilder; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.api.RequestReplyCallback; import org.apache.eventmesh.api.SendCallback; import org.apache.eventmesh.common.Constants; @@ -31,17 +28,21 @@ import org.apache.eventmesh.protocol.api.ProtocolPluginFactory; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; -import org.apache.eventmesh.runtime.util.EventMeshUtil; import org.apache.eventmesh.runtime.util.Utils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.time.DateFormatUtils; import java.util.Objects; import java.util.concurrent.Semaphore; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.cloudevents.CloudEvent; +import io.cloudevents.core.builder.CloudEventBuilder; public class SessionSender { @@ -60,9 +61,12 @@ public class SessionSender { @Override public String toString() { - return "SessionSender{upstreamBuff=" + upstreamBuff.availablePermits() + - ",upMsgs=" + upMsgs.longValue() + - ",failMsgCount=" + failMsgCount.longValue() + + return "SessionSender{upstreamBuff=" + upstreamBuff.availablePermits() + + + ",upMsgs=" + upMsgs.longValue() + + + ",failMsgCount=" + failMsgCount.longValue() + + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + '}'; } @@ -86,27 +90,33 @@ public EventMeshTcpSendResult send(Header header, CloudEvent event, SendCallback long ttl = EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; if (Command.REQUEST_TO_SERVER == cmd) { if (event.getExtension(EventMeshConstants.PROPERTY_MESSAGE_TTL) != null) { - ttl = Long.parseLong((String) Objects.requireNonNull(event.getExtension(EventMeshConstants.PROPERTY_MESSAGE_TTL))); + ttl = Long.parseLong((String) Objects.requireNonNull( + event.getExtension(EventMeshConstants.PROPERTY_MESSAGE_TTL))); } -// long ttl = msg.getSystemProperties(EventMeshConstants.PROPERTY_MESSAGE_TTL) != null ? Long.parseLong(msg.getSystemProperties(EventMeshConstants.PROPERTY_MESSAGE_TTL)) : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; + //long ttl = msg.getSystemProperties(EventMeshConstants.PROPERTY_MESSAGE_TTL) != null ? + // Long.parseLong(msg.getSystemProperties(EventMeshConstants.PROPERTY_MESSAGE_TTL)) + // : EventMeshConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS; upStreamMsgContext = new UpStreamMsgContext(session, event, header, startTime, taskExecuteTime); - session.getClientGroupWrapper().get().request(upStreamMsgContext, initSyncRRCallback(header, startTime, taskExecuteTime), ttl); + session.getClientGroupWrapper().get().request(upStreamMsgContext, initSyncRRCallback(header, + startTime, taskExecuteTime), ttl); upstreamBuff.release(); } else if (Command.RESPONSE_TO_SERVER == cmd) { - String cluster = (String)event.getExtension(EventMeshConstants.PROPERTY_MESSAGE_CLUSTER); -// String cluster = msg.getUserProperties(EventMeshConstants.PROPERTY_MESSAGE_CLUSTER); + String cluster = (String) event.getExtension(EventMeshConstants.PROPERTY_MESSAGE_CLUSTER); + //String cluster = msg.getUserProperties(EventMeshConstants.PROPERTY_MESSAGE_CLUSTER); if (!StringUtils.isEmpty(cluster)) { String replyTopic = EventMeshConstants.RR_REPLY_TOPIC; replyTopic = cluster + "-" + replyTopic; event = CloudEventBuilder.from(event).withSubject(replyTopic).build(); -// msg.getSystemProperties().put(Constants.PROPERTY_MESSAGE_DESTINATION, replyTopic); -// event(replyTopic); + //msg.getSystemProperties().put(Constants.PROPERTY_MESSAGE_DESTINATION, replyTopic); + //event(replyTopic); } -// //for rocketmq support -// MessageAccessor.putProperty(msg, MessageConst.PROPERTY_MESSAGE_TYPE, MixAll.REPLY_MESSAGE_FLAG); -// MessageAccessor.putProperty(msg, MessageConst.PROPERTY_CORRELATION_ID, msg.getProperty(DeFiBusConstant.PROPERTY_RR_REQUEST_ID)); -// MessageAccessor.putProperty(msg, MessageConst.PROPERTY_MESSAGE_REPLY_TO_CLIENT, msg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_REPLY_TO)); + ////for rocketmq support + //MessageAccessor.putProperty(msg, MessageConst.PROPERTY_MESSAGE_TYPE, MixAll.REPLY_MESSAGE_FLAG); + //MessageAccessor.putProperty(msg, MessageConst.PROPERTY_CORRELATION_ID, + // msg.getProperty(DeFiBusConstant.PROPERTY_RR_REQUEST_ID)); + //MessageAccessor.putProperty(msg, MessageConst.PROPERTY_MESSAGE_REPLY_TO_CLIENT, + // msg.getProperty(DeFiBusConstant.PROPERTY_MESSAGE_REPLY_TO)); upStreamMsgContext = new UpStreamMsgContext(session, event, header, startTime, taskExecuteTime); session.getClientGroupWrapper().get().reply(upStreamMsgContext); @@ -138,12 +148,12 @@ private RequestReplyCallback initSyncRRCallback(Header header, long startTime, l public void onSuccess(CloudEvent event) { String seq = header.getSeq(); // TODO: How to assign values here -// if (msg instanceof MessageExt) { -// msg.putUserProperty(EventMeshConstants.BORN_TIMESTAMP, String.valueOf(((MessageExt) msg) -// .getBornTimestamp())); -// msg.putUserProperty(EventMeshConstants.STORE_TIMESTAMP, String.valueOf(((MessageExt) msg) -// .getStoreTimestamp())); -// } + //if (msg instanceof MessageExt) { + // msg.putUserProperty(EventMeshConstants.BORN_TIMESTAMP, String.valueOf(((MessageExt) msg) + // .getBornTimestamp())); + // msg.putUserProperty(EventMeshConstants.STORE_TIMESTAMP, String.valueOf(((MessageExt) msg) + // .getStoreTimestamp())); + //} event = CloudEventBuilder.from(event) .withExtension(EventMeshConstants.RSP_MQ2EVENTMESH_TIMESTAMP, String.valueOf(System.currentTimeMillis())) .withExtension(EventMeshConstants.RSP_RECEIVE_EVENTMESH_IP, session.getEventMeshTCPConfiguration().eventMeshServerIp) @@ -158,17 +168,17 @@ public void onSuccess(CloudEvent event) { return; } event = CloudEventBuilder.from(event) - .withExtension(EventMeshConstants.RSP_EVENTMESH2C_TIMESTAMP, String.valueOf(System.currentTimeMillis())) - .build(); + .withExtension(EventMeshConstants.RSP_EVENTMESH2C_TIMESTAMP, String.valueOf(System.currentTimeMillis())) + .build(); String protocolType = Objects.requireNonNull(event.getExtension(Constants.PROTOCOL_TYPE)).toString(); ProtocolAdaptor protocolAdaptor = ProtocolPluginFactory.getProtocolAdaptor(protocolType); Package pkg = new Package(); -// msg.getSystemProperties().put(EventMeshConstants.RSP_EVENTMESH2C_TIMESTAMP, String.valueOf(System.currentTimeMillis())); + //msg.getSystemProperties().put(EventMeshConstants.RSP_EVENTMESH2C_TIMESTAMP, String.valueOf(System.currentTimeMillis())); try { -// pkg.setBody(EventMeshUtil.encodeMessage(msg)); + //pkg.setBody(EventMeshUtil.encodeMessage(msg)); pkg = (Package) protocolAdaptor.fromCloudEvent(event); pkg.setHeader(new Header(cmd, OPStatus.SUCCESS.getCode(), null, seq)); pkg.getHeader().putProperty(Constants.PROTOCOL_TYPE, protocolType); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/send/UpStreamMsgContext.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/send/UpStreamMsgContext.java index 6a72423ccd..2950f2f749 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/send/UpStreamMsgContext.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/session/send/UpStreamMsgContext.java @@ -76,28 +76,28 @@ public long getCreateTime() { @Override public String toString() { return "UpStreamMsgContext{seq=" + seq - + ",topic=" + event.getSubject() - + ",client=" + session.getClient() - + ",retryTimes=" + retryTimes - + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + "}" - + ",executeTime=" + DateFormatUtils.format(executeTime, EventMeshConstants.DATE_FORMAT); + + ",topic=" + event.getSubject() + + ",client=" + session.getClient() + + ",retryTimes=" + retryTimes + + ",createTime=" + DateFormatUtils.format(createTime, EventMeshConstants.DATE_FORMAT) + "}" + + ",executeTime=" + DateFormatUtils.format(executeTime, EventMeshConstants.DATE_FORMAT); } @Override public void retry() { logger.info("retry upStream msg start,seq:{},retryTimes:{},bizSeq:{}", this.seq, this.retryTimes, - EventMeshUtil.getMessageBizSeq(this.event)); + EventMeshUtil.getMessageBizSeq(this.event)); try { Command replyCmd = getReplyCmd(header.getCmd()); long sendTime = System.currentTimeMillis(); EventMeshTcpSendResult sendStatus = session.upstreamMsg(header, event, - createSendCallback(replyCmd, taskExecuteTime, event), startTime, taskExecuteTime); + createSendCallback(replyCmd, taskExecuteTime, event), startTime, taskExecuteTime); if (StringUtils.equals(EventMeshTcpSendStatus.SUCCESS.name(), sendStatus.getSendStatus().name())) { logger.info("pkg|eventMesh2mq|cmd={}|event={}|user={}|wait={}ms|cost={}ms", header.getCmd(), event, - session.getClient(), taskExecuteTime - startTime, sendTime - startTime); + session.getClient(), taskExecuteTime - startTime, sendTime - startTime); } else { throw new Exception(sendStatus.getDetail()); } @@ -115,9 +115,9 @@ protected SendCallback createSendCallback(Command replyCmd, long taskExecuteTime public void onSuccess(SendResult sendResult) { session.getSender().getUpstreamBuff().release(); logger.info("upstreamMsg message success|user={}|callback cost={}", session.getClient(), - String.valueOf(System.currentTimeMillis() - createTime)); + String.valueOf(System.currentTimeMillis() - createTime)); if (replyCmd.equals(Command.BROADCAST_MESSAGE_TO_SERVER_ACK) || replyCmd.equals(Command - .ASYNC_MESSAGE_TO_SERVER_ACK)) { + .ASYNC_MESSAGE_TO_SERVER_ACK)) { msg.setHeader(new Header(replyCmd, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), seq)); msg.setBody(event); Utils.writeAndFlush(msg, startTime, taskExecuteTime, session.getContext(), session); @@ -130,14 +130,13 @@ public void onException(OnExceptionContext context) { // retry UpStreamMsgContext upStreamMsgContext = new UpStreamMsgContext( - session, event, header, startTime, taskExecuteTime); + session, event, header, startTime, taskExecuteTime); upStreamMsgContext.delay(10000); session.getClientGroupWrapper().get().getEventMeshTcpRetryer().pushRetry(upStreamMsgContext); session.getSender().failMsgCount.incrementAndGet(); logger.error("upstreamMsg mq message error|user={}|callback cost={}, errMsg={}", session.getClient(), - String.valueOf - (System.currentTimeMillis() - createTime), new Exception(context.getException())); + String.valueOf(System.currentTimeMillis() - createTime), new Exception(context.getException())); msg.setHeader(new Header(replyCmd, OPStatus.FAIL.getCode(), context.getException().toString(), seq)); msg.setBody(event); Utils.writeAndFlush(msg, startTime, taskExecuteTime, session.getContext(), session); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/AbstractTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/AbstractTask.java index 64e0eefb5b..560ccf4be6 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/AbstractTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/AbstractTask.java @@ -17,17 +17,19 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.task; -import io.netty.channel.ChannelHandlerContext; - import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public abstract class AbstractTask implements Runnable { protected final Logger logger = LoggerFactory.getLogger(this.getClass()); + protected Package pkg; protected ChannelHandlerContext ctx; protected Session session; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/GoodbyeTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/GoodbyeTask.java index ed24ef242e..0eeabf2dcd 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/GoodbyeTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/GoodbyeTask.java @@ -44,13 +44,13 @@ public void run() { logger.info("client|address={}| has reject ", session.getContext().channel().remoteAddress()); } else { msg.setHeader( - new Header(CLIENT_GOODBYE_RESPONSE, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), - pkg.getHeader().getSeq())); + new Header(CLIENT_GOODBYE_RESPONSE, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), + pkg.getHeader().getSeq())); } } catch (Exception e) { logger.error("GoodbyeTask failed|user={}|errMsg={}", session.getClient(), e); msg.setHeader(new Header(CLIENT_GOODBYE_RESPONSE, OPStatus.FAIL.getCode(), e.getStackTrace().toString(), pkg - .getHeader().getSeq())); + .getHeader().getSeq())); } finally { this.eventMeshTCPServer.getScheduler().submit(new Runnable() { @Override @@ -61,6 +61,6 @@ public void run() { //session.write2Client(msg); } EventMeshTcp2Client - .closeSessionIfTimeout(this.eventMeshTCPServer, session, eventMeshTCPServer.getClientSessionGroupMapping()); + .closeSessionIfTimeout(this.eventMeshTCPServer, session, eventMeshTCPServer.getClientSessionGroupMapping()); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HeartBeatTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HeartBeatTask.java index 9e16ef2cf9..099b34638b 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HeartBeatTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HeartBeatTask.java @@ -20,8 +20,6 @@ import static org.apache.eventmesh.common.protocol.tcp.Command.HEARTBEAT_REQUEST; import static org.apache.eventmesh.common.protocol.tcp.Command.HEARTBEAT_RESPONSE; -import io.netty.channel.ChannelHandlerContext; - import org.apache.eventmesh.common.protocol.tcp.Header; import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; @@ -30,6 +28,8 @@ import org.apache.eventmesh.runtime.util.RemotingHelper; import org.apache.eventmesh.runtime.util.Utils; +import io.netty.channel.ChannelHandlerContext; + public class HeartBeatTask extends AbstractTask { public HeartBeatTask(Package pkg, ChannelHandlerContext ctx, long startTime, EventMeshTCPServer eventMeshTCPServer) { @@ -42,7 +42,7 @@ public void run() { Package res = new Package(); try { //do acl check in heartbeat - if(eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerSecurityEnable){ + if (eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerSecurityEnable) { String remoteAddr = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); Acl.doAclCheckInTcpHeartbeat(remoteAddr, session.getClient(), HEARTBEAT_REQUEST.value()); } @@ -53,8 +53,8 @@ public void run() { res.setHeader(new Header(HEARTBEAT_RESPONSE, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), pkg.getHeader().getSeq())); } catch (Exception e) { logger.error("HeartBeatTask failed|user={}|errMsg={}", session.getClient(), e); - res.setHeader(new Header(HEARTBEAT_RESPONSE, OPStatus.FAIL.getCode(), "exception while " + - "heartbeating", pkg.getHeader().getSeq())); + res.setHeader(new Header(HEARTBEAT_RESPONSE, OPStatus.FAIL.getCode(), "exception while " + + "heartbeating", pkg.getHeader().getSeq())); } finally { Utils.writeAndFlush(res, startTime, taskExecuteTime, session.getContext(), session); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HelloTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HelloTask.java index 10e8f1ad41..4d2533591a 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HelloTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/HelloTask.java @@ -20,11 +20,6 @@ import static org.apache.eventmesh.common.protocol.tcp.Command.HELLO_REQUEST; import static org.apache.eventmesh.common.protocol.tcp.Command.HELLO_RESPONSE; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelFutureListener; -import io.netty.channel.ChannelHandlerContext; - -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.common.protocol.tcp.Header; import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; @@ -36,9 +31,16 @@ import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; import org.apache.eventmesh.runtime.util.RemotingHelper; import org.apache.eventmesh.runtime.util.Utils; + +import org.apache.commons.lang3.StringUtils; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelFutureListener; +import io.netty.channel.ChannelHandlerContext; + public class HelloTask extends AbstractTask { private final Logger messageLogger = LoggerFactory.getLogger("message"); @@ -99,15 +101,17 @@ private void validateUserAgent(UserAgent user) throws Exception { throw new Exception("client version cannot be null"); } -// if (user.getUsername() == null) { -// throw new Exception("client EventMeshUser cannot be null"); -// } -// -// if (user.getPassword() == null) { -// throw new Exception("client EventMeshPasswd cannot be null"); -// } + //if (user.getUsername() == null) { + // throw new Exception("client EventMeshUser cannot be null"); + //} + // + //if (user.getPassword() == null) { + // throw new Exception("client EventMeshPasswd cannot be null"); + //} + + if (!(StringUtils.equals(EventMeshConstants.PURPOSE_PUB, user.getPurpose()) || StringUtils.equals( + EventMeshConstants.PURPOSE_SUB, user.getPurpose()))) { - if (!(StringUtils.equals(EventMeshConstants.PURPOSE_PUB, user.getPurpose()) || StringUtils.equals(EventMeshConstants.PURPOSE_SUB, user.getPurpose()))) { throw new Exception("client purpose config is error"); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/ListenTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/ListenTask.java index 4ce653a403..7d26fe6680 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/ListenTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/ListenTask.java @@ -19,13 +19,13 @@ import static org.apache.eventmesh.common.protocol.tcp.Command.LISTEN_RESPONSE; -import io.netty.channel.ChannelHandlerContext; - import org.apache.eventmesh.common.protocol.tcp.Header; import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import io.netty.channel.ChannelHandlerContext; + public class ListenTask extends AbstractTask { public ListenTask(Package pkg, ChannelHandlerContext ctx, long startTime, EventMeshTCPServer eventMeshTCPServer) { @@ -46,8 +46,8 @@ public void run() { Integer status = OPStatus.FAIL.getCode(); header = new Header(LISTEN_RESPONSE, status, e.toString(), pkg.getHeader().getSeq()); } finally { -// res.setHeader(header); -// writeAndFlush(res, startTime, session.getContext(), session); + //res.setHeader(header); + //writeAndFlush(res, startTime, session.getContext(), session); //session.write2Client(res); //check to avoid send repeatedly diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageAckTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageAckTask.java index f5e670e2b4..a01615babc 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageAckTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageAckTask.java @@ -17,16 +17,16 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.task; -import io.netty.channel.ChannelHandlerContext; - import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push.ClientAckContext; import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.push.DownStreamMsgContext; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public class MessageAckTask extends AbstractTask { private final Logger messageLogger = LoggerFactory.getLogger("message"); @@ -46,12 +46,14 @@ public void run() { return; } DownStreamMsgContext downStreamMsgContext = session.getPusher().getUnAckMsg().get(seq); - if (downStreamMsgContext != null) {// ack non-broadcast msg + // ack non-broadcast msg + if (downStreamMsgContext != null) { downStreamMsgContext.ackMsg(); session.getPusher().getUnAckMsg().remove(seq); - }else { - if(!cmd.equals(Command.RESPONSE_TO_CLIENT_ACK)) { - logger.warn("MessageAckTask, seq:{}, downStreamMsgContext not in downStreamMap,client:{}", seq, session.getClient()); + } else { + if (!cmd.equals(Command.RESPONSE_TO_CLIENT_ACK)) { + logger.warn("MessageAckTask, seq:{}, downStreamMsgContext not in downStreamMap,client:{}", + seq, session.getClient()); } } messageLogger.info("pkg|c2eventMesh|cmd={}|seq=[{}]|user={}|wait={}ms|cost={}ms", cmd, seq, session.getClient(), diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageTransferTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageTransferTask.java index c5d5d1abd4..442d539a66 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageTransferTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/MessageTransferTask.java @@ -56,7 +56,7 @@ public class MessageTransferTask extends AbstractTask { private final Logger messageLogger = LoggerFactory.getLogger("message"); - private final int TRY_PERMIT_TIME_OUT = 5; + private static final int TRY_PERMIT_TIME_OUT = 5; public MessageTransferTask(Package pkg, ChannelHandlerContext ctx, long startTime, EventMeshTCPServer eventMeshTCPServer) { @@ -73,10 +73,10 @@ public void run() { protocolType = (String) pkg.getHeader().getProperty(Constants.PROTOCOL_TYPE); } ProtocolAdaptor protocolAdaptor = - ProtocolPluginFactory.getProtocolAdaptor(protocolType); + ProtocolPluginFactory.getProtocolAdaptor(protocolType); Package msg = new Package(); -// EventMeshMessage eventMeshMessage = (EventMeshMessage) pkg.getBody(); + //EventMeshMessage eventMeshMessage = (EventMeshMessage) pkg.getBody(); int retCode = 0; EventMeshTcpSendResult sendStatus; CloudEvent event = null; @@ -98,39 +98,39 @@ public void run() { event = addTimestamp(event, cmd, sendTime); sendStatus = session - .upstreamMsg(pkg.getHeader(), event, createSendCallback(replyCmd, taskExecuteTime, event), - startTime, taskExecuteTime); + .upstreamMsg(pkg.getHeader(), event, createSendCallback(replyCmd, taskExecuteTime, event), + startTime, taskExecuteTime); if (StringUtils.equals(EventMeshTcpSendStatus.SUCCESS.name(), sendStatus.getSendStatus().name())) { messageLogger.info("pkg|eventMesh2mq|cmd={}|Msg={}|user={}|wait={}ms|cost={}ms", cmd, event, - session.getClient(), taskExecuteTime - startTime, sendTime - startTime); + session.getClient(), taskExecuteTime - startTime, sendTime - startTime); } else { throw new Exception(sendStatus.getDetail()); } } } else { msg.setHeader(new Header(replyCmd, OPStatus.FAIL.getCode(), "Tps overload, global flow control", - pkg.getHeader().getSeq())); + pkg.getHeader().getSeq())); ctx.writeAndFlush(msg).addListener( - new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) throws Exception { - Utils.logSucceedMessageFlow(msg, session.getClient(), startTime, taskExecuteTime); + new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture future) throws Exception { + Utils.logSucceedMessageFlow(msg, session.getClient(), startTime, taskExecuteTime); + } } - } ); logger.warn("======Tps overload, global flow control, rate:{}! PLEASE CHECK!========", - eventMeshTCPServer.getRateLimiter().getRate()); + eventMeshTCPServer.getRateLimiter().getRate()); return; } } catch (Exception e) { logger - .error("MessageTransferTask failed|cmd={}|event={}|user={}|errMsg={}", cmd, event, session.getClient(), - e); + .error("MessageTransferTask failed|cmd={}|event={}|user={}|errMsg={}", cmd, event, session.getClient(), + e); if (!cmd.equals(RESPONSE_TO_SERVER)) { msg.setHeader( - new Header(replyCmd, OPStatus.FAIL.getCode(), e.getStackTrace().toString(), pkg.getHeader() - .getSeq())); + new Header(replyCmd, OPStatus.FAIL.getCode(), e.getStackTrace().toString(), pkg.getHeader() + .getSeq())); Utils.writeAndFlush(msg, startTime, taskExecuteTime, session.getContext(), session); } } @@ -139,18 +139,18 @@ public void operationComplete(ChannelFuture future) throws Exception { private CloudEvent addTimestamp(CloudEvent event, Command cmd, long sendTime) { if (cmd.equals(RESPONSE_TO_SERVER)) { event = CloudEventBuilder.from(event) - .withExtension(EventMeshConstants.RSP_C2EVENTMESH_TIMESTAMP, String.valueOf(startTime)) - .withExtension(EventMeshConstants.RSP_EVENTMESH2MQ_TIMESTAMP, String.valueOf(sendTime)) - .withExtension(EventMeshConstants.RSP_SEND_EVENTMESH_IP, - eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerIp) - .build(); + .withExtension(EventMeshConstants.RSP_C2EVENTMESH_TIMESTAMP, String.valueOf(startTime)) + .withExtension(EventMeshConstants.RSP_EVENTMESH2MQ_TIMESTAMP, String.valueOf(sendTime)) + .withExtension(EventMeshConstants.RSP_SEND_EVENTMESH_IP, + eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerIp) + .build(); } else { event = CloudEventBuilder.from(event) - .withExtension(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, String.valueOf(startTime)) - .withExtension(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, String.valueOf(sendTime)) - .withExtension(EventMeshConstants.REQ_SEND_EVENTMESH_IP, - eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerIp) - .build(); + .withExtension(EventMeshConstants.REQ_C2EVENTMESH_TIMESTAMP, String.valueOf(startTime)) + .withExtension(EventMeshConstants.REQ_EVENTMESH2MQ_TIMESTAMP, String.valueOf(sendTime)) + .withExtension(EventMeshConstants.REQ_SEND_EVENTMESH_IP, + eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerIp) + .build(); } return event; } @@ -177,11 +177,11 @@ protected SendCallback createSendCallback(Command replyCmd, long taskExecuteTime public void onSuccess(SendResult sendResult) { session.getSender().getUpstreamBuff().release(); messageLogger.info("upstreamMsg message success|user={}|callback cost={}", session.getClient(), - String.valueOf(System.currentTimeMillis() - createTime)); + String.valueOf(System.currentTimeMillis() - createTime)); if (replyCmd.equals(Command.BROADCAST_MESSAGE_TO_SERVER_ACK) || replyCmd.equals(Command - .ASYNC_MESSAGE_TO_SERVER_ACK)) { + .ASYNC_MESSAGE_TO_SERVER_ACK)) { msg.setHeader(new Header(replyCmd, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), - pkg.getHeader().getSeq())); + pkg.getHeader().getSeq())); msg.setBody(event); Utils.writeAndFlush(msg, startTime, taskExecuteTime, session.getContext(), session); } @@ -193,16 +193,16 @@ public void onException(OnExceptionContext context) { // retry UpStreamMsgContext upStreamMsgContext = new UpStreamMsgContext( - session, event, pkg.getHeader(), startTime, taskExecuteTime); + session, event, pkg.getHeader(), startTime, taskExecuteTime); upStreamMsgContext.delay(10000); session.getClientGroupWrapper().get().getEventMeshTcpRetryer().pushRetry(upStreamMsgContext); session.getSender().failMsgCount.incrementAndGet(); messageLogger - .error("upstreamMsg mq message error|user={}|callback cost={}, errMsg={}", session.getClient(), - (System.currentTimeMillis() - createTime), new Exception(context.getException())); + .error("upstreamMsg mq message error|user={}|callback cost={}, errMsg={}", session.getClient(), + (System.currentTimeMillis() - createTime), new Exception(context.getException())); msg.setHeader(new Header(replyCmd, OPStatus.FAIL.getCode(), context.getException().toString(), - pkg.getHeader().getSeq())); + pkg.getHeader().getSeq())); msg.setBody(event); Utils.writeAndFlush(msg, startTime, taskExecuteTime, session.getContext(), session); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/RecommendTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/RecommendTask.java index ca626a87ed..da595bacf2 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/RecommendTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/RecommendTask.java @@ -14,21 +14,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.core.protocol.tcp.client.task; -import io.netty.channel.ChannelHandlerContext; -import org.apache.commons.lang3.StringUtils; -import org.apache.eventmesh.common.protocol.tcp.*; +import static org.apache.eventmesh.common.protocol.tcp.Command.RECOMMEND_RESPONSE; +import static org.apache.eventmesh.runtime.util.Utils.writeAndFlush; + +import org.apache.eventmesh.common.protocol.tcp.Header; +import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.constants.EventMeshConstants; import org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendImpl; import org.apache.eventmesh.runtime.core.protocol.tcp.client.recommend.EventMeshRecommendStrategy; + +import org.apache.commons.lang3.StringUtils; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import static org.apache.eventmesh.common.protocol.tcp.Command.RECOMMEND_RESPONSE; -import static org.apache.eventmesh.runtime.util.Utils.writeAndFlush; +import io.netty.channel.ChannelHandlerContext; public class RecommendTask extends AbstractTask { @@ -43,12 +49,12 @@ public void run() { long taskExecuteTime = System.currentTimeMillis(); Package res = new Package(); try { - if(!eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerRegistryEnable) { + if (!eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerRegistryEnable) { throw new Exception("registry enable config is false, not support"); } UserAgent user = (UserAgent) pkg.getBody(); validateUserAgent(user); - String group = getGroupOfClient(user); + String group = getGroupOfClient(user); EventMeshRecommendStrategy eventMeshRecommendStrategy = new EventMeshRecommendImpl(eventMeshTCPServer); String eventMeshRecommendResult = eventMeshRecommendStrategy.calculateRecommendEventMesh(group, user.getPurpose()); res.setHeader(new Header(RECOMMEND_RESPONSE, OPStatus.SUCCESS.getCode(), OPStatus.SUCCESS.getDesc(), pkg.getHeader().getSeq())); @@ -81,20 +87,21 @@ private void validateUserAgent(UserAgent user) throws Exception { throw new Exception("client wemqPasswd cannot be null"); } - if (!(StringUtils.equals(EventMeshConstants.PURPOSE_PUB, user.getPurpose()) || StringUtils.equals(EventMeshConstants.PURPOSE_SUB, user.getPurpose()))) { + if (!(StringUtils.equals(EventMeshConstants.PURPOSE_PUB, user.getPurpose()) || StringUtils.equals( + EventMeshConstants.PURPOSE_SUB, user.getPurpose()))) { throw new Exception("client purpose config is error"); } } - private String getGroupOfClient(UserAgent userAgent){ - if(userAgent == null){ + private String getGroupOfClient(UserAgent userAgent) { + if (userAgent == null) { return null; } - if(EventMeshConstants.PURPOSE_PUB.equals(userAgent.getPurpose())){ + if (EventMeshConstants.PURPOSE_PUB.equals(userAgent.getPurpose())) { return userAgent.getProducerGroup(); - }else if(EventMeshConstants.PURPOSE_SUB.equals(userAgent.getPurpose())){ + } else if (EventMeshConstants.PURPOSE_SUB.equals(userAgent.getPurpose())) { return userAgent.getConsumerGroup(); - }else{ + } else { return null; } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/SubscribeTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/SubscribeTask.java index c48a881e89..852636c37d 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/SubscribeTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/SubscribeTask.java @@ -17,22 +17,25 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.task; -import java.util.ArrayList; -import java.util.List; - -import io.netty.channel.ChannelHandlerContext; - -import org.apache.eventmesh.common.protocol.tcp.Subscription; import org.apache.eventmesh.common.protocol.SubscriptionItem; -import org.apache.eventmesh.common.protocol.tcp.*; +import org.apache.eventmesh.common.protocol.tcp.Command; +import org.apache.eventmesh.common.protocol.tcp.Header; +import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.tcp.Subscription; import org.apache.eventmesh.runtime.acl.Acl; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.util.RemotingHelper; import org.apache.eventmesh.runtime.util.Utils; + +import java.util.ArrayList; +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public class SubscribeTask extends AbstractTask { private final Logger messageLogger = LoggerFactory.getLogger("message"); @@ -56,7 +59,7 @@ public void run() { SubscriptionItem item = subscriptionInfo.getTopicList().get(i); //do acl check for receive msg - if(eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerSecurityEnable){ + if (eventMeshTCPServer.getEventMeshTCPConfiguration().eventMeshServerSecurityEnable) { String remoteAddr = RemotingHelper.parseChannelRemoteAddr(ctx.channel()); Acl.doAclCheckInTcpReceive(remoteAddr, session.getClient(), item.getTopic(), Command.SUBSCRIBE_REQUEST.value()); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/UnSubscribeTask.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/UnSubscribeTask.java index c35245adad..15e3f70326 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/UnSubscribeTask.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/core/protocol/tcp/client/task/UnSubscribeTask.java @@ -17,13 +17,6 @@ package org.apache.eventmesh.runtime.core.protocol.tcp.client.task; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -import io.netty.channel.ChannelHandlerContext; - -import org.apache.commons.collections4.MapUtils; import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.Header; @@ -31,9 +24,18 @@ import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; import org.apache.eventmesh.runtime.util.Utils; + +import org.apache.commons.collections4.MapUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public class UnSubscribeTask extends AbstractTask { private final Logger messageLogger = LoggerFactory.getLogger("message"); @@ -61,7 +63,8 @@ public void run() { .getSeq())); } catch (Exception e) { messageLogger.error("UnSubscribeTask failed|user={}|errMsg={}", session.getClient(), e); - msg.setHeader(new Header(Command.UNSUBSCRIBE_RESPONSE, OPStatus.FAIL.getCode(), "exception while " + + msg.setHeader(new Header(Command.UNSUBSCRIBE_RESPONSE, OPStatus.FAIL.getCode(), "exception while " + + "unSubscribing", pkg.getHeader().getSeq())); } finally { Utils.writeAndFlush(msg, startTime, taskExecuteTime, session.getContext(), session); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/domain/NonStandardKeys.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/domain/NonStandardKeys.java index 779b3dccef..a82c71e4ae 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/domain/NonStandardKeys.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/domain/NonStandardKeys.java @@ -14,8 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.domain; +/** + * NonStandardKeys + */ public interface NonStandardKeys { String CONSUMER_GROUP = "rmq.consumer.group"; String PRODUCER_GROUP = "rmq.producer.group"; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/domain/RocketMQConstants.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/domain/RocketMQConstants.java index a8f08533df..95fb1aee07 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/domain/RocketMQConstants.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/domain/RocketMQConstants.java @@ -14,8 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + + package org.apache.eventmesh.runtime.domain; +/** + * RocketMQConstants + */ public interface RocketMQConstants { /** diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/GroupMetrics.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/GroupMetrics.java index 75f3d5d939..85ded0bcbd 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/GroupMetrics.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/GroupMetrics.java @@ -17,10 +17,10 @@ package org.apache.eventmesh.runtime.metrics.http; -import com.codahale.metrics.MetricRegistry; - import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; +import com.codahale.metrics.MetricRegistry; + public class GroupMetrics { private EventMeshHTTPServer eventMeshHTTPServer; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/HTTPMetricsServer.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/HTTPMetricsServer.java index d49167f88c..4659dbfa70 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/HTTPMetricsServer.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/HTTPMetricsServer.java @@ -17,19 +17,20 @@ package org.apache.eventmesh.runtime.metrics.http; +import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; +import org.apache.eventmesh.runtime.metrics.opentelemetry.OpenTelemetryHTTPMetricsExporter; + import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import com.codahale.metrics.MetricRegistry; - -import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; -import org.apache.eventmesh.runtime.metrics.opentelemetry.OpenTelemetryHTTPMetricsExporter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.codahale.metrics.MetricRegistry; + public class HTTPMetricsServer { private EventMeshHTTPServer eventMeshHTTPServer; @@ -60,7 +61,7 @@ public void init() throws Exception { groupMetrics = new GroupMetrics(this.eventMeshHTTPServer, this.metricRegistry); healthMetrics = new HealthMetrics(this.eventMeshHTTPServer, this.metricRegistry); - openTelemetryHTTPMetricsExporter = new OpenTelemetryHTTPMetricsExporter(this,this.eventMeshHTTPServer.getEventMeshHttpConfiguration()); + openTelemetryHTTPMetricsExporter = new OpenTelemetryHTTPMetricsExporter(this, this.eventMeshHTTPServer.getEventMeshHttpConfiguration()); logger.info("HTTPMetricsServer inited......"); } @@ -170,19 +171,19 @@ private void logPrintServerMetrics() { summaryMetrics.send2MQStatInfoClear(); } - public int getBatchMsgQ(){ + public int getBatchMsgQ() { return eventMeshHTTPServer.getBatchMsgExecutor().getQueue().size(); } - public int getSendMsgQ(){ + public int getSendMsgQ() { return eventMeshHTTPServer.getSendMsgExecutor().getQueue().size(); } - public int getPushMsgQ(){ + public int getPushMsgQ() { return eventMeshHTTPServer.getPushMsgExecutor().getQueue().size(); } - public int getHttpRetryQ(){ + public int getHttpRetryQ() { return eventMeshHTTPServer.getHttpRetryer().size(); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/HealthMetrics.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/HealthMetrics.java index 6e59fb6369..7451d99885 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/HealthMetrics.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/HealthMetrics.java @@ -17,12 +17,13 @@ package org.apache.eventmesh.runtime.metrics.http; -import com.codahale.metrics.MetricRegistry; - import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.codahale.metrics.MetricRegistry; + public class HealthMetrics { private EventMeshHTTPServer eventMeshHTTPServer; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/SummaryMetrics.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/SummaryMetrics.java index a0e2223a44..3bf4fe9095 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/SummaryMetrics.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/SummaryMetrics.java @@ -17,17 +17,18 @@ package org.apache.eventmesh.runtime.metrics.http; +import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; + import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.concurrent.atomic.AtomicLong; -import com.codahale.metrics.MetricRegistry; - -import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.codahale.metrics.MetricRegistry; + public class SummaryMetrics { public Logger logger = LoggerFactory.getLogger("httpMonitor"); @@ -58,9 +59,10 @@ private float avg(LinkedList linkedList) { return sum / linkedList.size(); } - //////////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_HTTP = "{\"maxHTTPTPS\":\"%.1f\",\"avgHTTPTPS\":\"%.1f\"," + //EVENTMESH tps related to accepting external http requests - "\"maxHTTPCOST\":\"%s\",\"avgHTTPCOST\":\"%.1f\",\"avgHTTPBodyDecodeCost\":\"%.1f\", \"httpDiscard\":\"%s\"}"; + public static final String EVENTMESH_MONITOR_FORMAT_HTTP = "{\"maxHTTPTPS\":\"%.1f\",\"avgHTTPTPS\":\"%.1f\"," + //EVENTMESH tps related to accepting external http requests + + "\"maxHTTPCOST\":\"%s\",\"avgHTTPCOST\":\"%.1f\",\"avgHTTPBodyDecodeCost\":\"%.1f\", " + + "\"httpDiscard\":\"%s\"}"; private float wholeCost = 0f; @@ -76,7 +78,7 @@ private float avg(LinkedList linkedList) { private LinkedList httpRequestTPSSnapshots = new LinkedList(); public float avgHTTPCost() { - float cost = (wholeRequestNum.longValue() == 0l) ? 0f : wholeCost / wholeRequestNum.longValue(); + float cost = (wholeRequestNum.longValue() == 0L) ? 0f : wholeCost / wholeRequestNum.longValue(); return cost; } @@ -125,10 +127,10 @@ public void recordHTTPReqResTimeCost(long cost) { } public void httpStatInfoClear() { - wholeRequestNum.set(0l); + wholeRequestNum.set(0L); wholeCost = 0f; - maxCost.set(0l); - httpDecodeNum.set(0l); + maxCost.set(0L); + httpDecodeNum.set(0L); httpDecodeTimeCost = 0f; } @@ -142,14 +144,14 @@ public void recordDecodeTimeCost(long cost) { } public float avgHTTPBodyDecodeCost() { - float cost = (httpDecodeNum.longValue() == 0l) ? 0f : httpDecodeTimeCost / httpDecodeNum.longValue(); + float cost = (httpDecodeNum.longValue() == 0L) ? 0f : httpDecodeTimeCost / httpDecodeNum.longValue(); return cost; } ////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_BATCHSENDMSG = "{\"maxBatchSendMsgTPS\":\"%.1f\",\"avgBatchSendMsgTPS\":\"%.1f\"," + - " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.2f\", \"discard\":\"%s\"}"; + public static final String EVENTMESH_MONITOR_FORMAT_BATCHSENDMSG = "{\"maxBatchSendMsgTPS\":\"%.1f\",\"avgBatchSendMsgTPS\":\"%.1f\"," + + " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.2f\", \"discard\":\"%s\"}"; private AtomicLong sendBatchMsgNumPerSecond = new AtomicLong(0); @@ -203,12 +205,12 @@ public long getSendBatchMsgFailNumSum() { } public float getSendBatchMsgFailRate() { - return (sendBatchMsgNumSum.longValue() == 0l) ? 0f : sendBatchMsgFailNumSum.floatValue() / sendBatchMsgNumSum.longValue(); + return (sendBatchMsgNumSum.longValue() == 0L) ? 0f : sendBatchMsgFailNumSum.floatValue() / sendBatchMsgNumSum.longValue(); } public void cleanSendBatchStat() { - sendBatchMsgNumSum.set(0l); - sendBatchMsgFailNumSum.set(0l); + sendBatchMsgNumSum.set(0L); + sendBatchMsgFailNumSum.set(0L); } public long getSendBatchMsgDiscardNumSum() { @@ -216,8 +218,8 @@ public long getSendBatchMsgDiscardNumSum() { } ////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_SENDMSG = "{\"maxSendMsgTPS\":\"%.1f\",\"avgSendMsgTPS\":\"%.1f\"," + - " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.2f\", \"replyMsg\":\"%s\", \"replyFail\":\"%s\"}"; + public static final String EVENTMESH_MONITOR_FORMAT_SENDMSG = "{\"maxSendMsgTPS\":\"%.1f\",\"avgSendMsgTPS\":\"%.1f\"," + + " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.2f\", \"replyMsg\":\"%s\", \"replyFail\":\"%s\"}"; private AtomicLong sendMsgNumSum = new AtomicLong(0); @@ -280,7 +282,7 @@ public long getSendMsgFailNumSum() { } public float getSendMsgFailRate() { - return (sendMsgNumSum.longValue() == 0l) ? 0f : sendMsgFailNumSum.floatValue() / sendMsgNumSum.longValue(); + return (sendMsgNumSum.longValue() == 0L) ? 0f : sendMsgFailNumSum.floatValue() / sendMsgNumSum.longValue(); } public void recordSendMsgFailed() { @@ -288,15 +290,15 @@ public void recordSendMsgFailed() { } public void cleanSendMsgStat() { - sendMsgNumSum.set(0l); - replyMsgNumSum.set(0l); - sendMsgFailNumSum.set(0l); - replyMsgFailNumSum.set(0l); + sendMsgNumSum.set(0L); + replyMsgNumSum.set(0L); + sendMsgFailNumSum.set(0L); + replyMsgFailNumSum.set(0L); } //////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_PUSHMSG = "{\"maxPushMsgTPS\":\"%.1f\",\"avgPushMsgTPS\":\"%.1f\"," + - " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.1f\", \"maxClientLatency\":\"%.1f\", \"avgClientLatency\":\"%.1f\"}"; + public static final String EVENTMESH_MONITOR_FORMAT_PUSHMSG = "{\"maxPushMsgTPS\":\"%.1f\",\"avgPushMsgTPS\":\"%.1f\"," + + " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.1f\", \"maxClientLatency\":\"%.1f\", \"avgClientLatency\":\"%.1f\"}"; private float wholePushCost = 0f; @@ -330,7 +332,7 @@ public void recordHTTPPushTimeCost(long cost) { } public float avgHTTPPushLatency() { - return (wholePushRequestNum.longValue() == 0l) ? 0f : wholePushCost / wholePushRequestNum.longValue(); + return (wholePushRequestNum.longValue() == 0L) ? 0f : wholePushCost / wholePushRequestNum.longValue(); } public float maxHTTPPushLatency() { @@ -361,7 +363,7 @@ public long getHttpPushFailNumSum() { } public float getHttpPushMsgFailRate() { - return (httpPushMsgNumSum.longValue() == 0l) ? 0f : httpPushFailNumSum.floatValue() / httpPushMsgNumSum.longValue(); + return (httpPushMsgNumSum.longValue() == 0L) ? 0f : httpPushFailNumSum.floatValue() / httpPushMsgNumSum.longValue(); } public void recordHttpPushMsgFailed() { @@ -369,19 +371,20 @@ public void recordHttpPushMsgFailed() { } public void cleanHttpPushMsgStat() { - httpPushFailNumSum.set(0l); - httpPushMsgNumSum.set(0l); - wholeRequestNum.set(0l); + httpPushFailNumSum.set(0L); + httpPushMsgNumSum.set(0L); + wholeRequestNum.set(0L); wholeCost = 0f; - maxCost.set(0l); + maxCost.set(0L); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_BLOCKQ = "{\"batchMsgQ\":\"%s\",\"sendMsgQ\":\"%s\"," + - "\"pushMsgQ\":\"%s\",\"httpRetryQ\":\"%s\"}"; + public static final String EVENTMESH_MONITOR_FORMAT_BLOCKQ = "{\"batchMsgQ\":\"%s\",\"sendMsgQ\":\"%s\"," + + "\"pushMsgQ\":\"%s\",\"httpRetryQ\":\"%s\"}"; /////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_MQ_CLIENT = "{\"batchAvgSend2MQCost\":\"%.1f\", \"avgSend2MQCost\":\"%.1f\", \"avgReply2MQCost\":\"%.1f\"}"; + public static final String EVENTMESH_MONITOR_FORMAT_MQ_CLIENT = "{\"batchAvgSend2MQCost\":\"%.1f\", " + + "\"avgSend2MQCost\":\"%.1f\", \"avgReply2MQCost\":\"%.1f\"}"; private float batchSend2MQWholeCost = 0f; @@ -427,10 +430,10 @@ public float avgReplyMsgCost() { public void send2MQStatInfoClear() { batchSend2MQWholeCost = 0f; - batchSend2MQNum.set(0l); + batchSend2MQNum.set(0L); send2MQWholeCost = 0f; - send2MQNum.set(0l); + send2MQNum.set(0L); reply2MQWholeCost = 0f; - reply2MQNum.set(0l); + reply2MQNum.set(0L); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/TcpSummaryMetrics.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/TcpSummaryMetrics.java index ce5944d46c..579c71bf85 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/TcpSummaryMetrics.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/TcpSummaryMetrics.java @@ -17,17 +17,18 @@ package org.apache.eventmesh.runtime.metrics.http; +import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; + import java.util.Collections; import java.util.Iterator; import java.util.LinkedList; import java.util.concurrent.atomic.AtomicLong; -import com.codahale.metrics.MetricRegistry; - -import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.codahale.metrics.MetricRegistry; + public class TcpSummaryMetrics { public Logger logger = LoggerFactory.getLogger("httpMonitor"); @@ -58,7 +59,8 @@ private float avg(LinkedList linkedList) { } //////////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_HTTP = "%15s : {\"maxHTTPTPS\":\"%.1f\",\"avgHTTPTPS\":\"%.1f\"," + //EVENTMESH tps related to accepting external http requests + public static final String EVENTMESH_MONITOR_FORMAT_HTTP = "%15s : {\"maxHTTPTPS\":\"%.1f\",\"avgHTTPTPS\":\"%.1f\"," + + //EVENTMESH tps related to accepting external http requests "\"maxHTTPCOST\":\"%s\",\"avgHTTPCOST\":\"%.1f\",\"avgHTTPBodyDecodeCost\":\"%.1f\"}"; private float wholeCost = 0f; @@ -72,7 +74,7 @@ private float avg(LinkedList linkedList) { private LinkedList httpRequestTPSSnapshots = new LinkedList(); public float avgHTTPCost() { - float cost = (wholeRequestNum.longValue() == 0l) ? 0f : wholeCost / wholeRequestNum.longValue(); + float cost = (wholeRequestNum.longValue() == 0L) ? 0f : wholeCost / wholeRequestNum.longValue(); return cost; } @@ -113,10 +115,10 @@ public void recordHTTPReqResTimeCost(long cost) { } public void httpStatInfoClear() { - wholeRequestNum.set(0l); + wholeRequestNum.set(0L); wholeCost = 0f; - maxCost.set(0l); - httpDecodeNum.set(0l); + maxCost.set(0L); + httpDecodeNum.set(0L); httpDecodeTimeCost = 0f; } @@ -130,13 +132,14 @@ public void recordDecodeTimeCost(long cost) { } public float avgHTTPBodyDecodeCost() { - float cost = (httpDecodeNum.longValue() == 0l) ? 0f : httpDecodeTimeCost / httpDecodeNum.longValue(); + float cost = (httpDecodeNum.longValue() == 0L) ? 0f : httpDecodeTimeCost / httpDecodeNum.longValue(); return cost; } ////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_BATCHSENDMSG = "%15s : {\"maxBatchSendMsgTPS\":\"%.1f\",\"avgBatchSendMsgTPS\":\"%.1f\"," + + public static final String EVENTMESH_MONITOR_FORMAT_BATCHSENDMSG = "%15s : {\"maxBatchSendMsgTPS\":\"%.1f\",\"avgBatchSendMsgTPS\":\"%.1f\"," + + " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.2f\", \"discard\":\"%s\"}"; private AtomicLong sendBatchMsgNumPerSecond = new AtomicLong(0); @@ -190,12 +193,12 @@ public long getSendBatchMsgFailNumSum() { } public float getSendBatchMsgFailRate() { - return (sendBatchMsgNumSum.longValue() == 0l) ? 0f : sendBatchMsgFailNumSum.floatValue() / sendBatchMsgNumSum.longValue(); + return (sendBatchMsgNumSum.longValue() == 0L) ? 0f : sendBatchMsgFailNumSum.floatValue() / sendBatchMsgNumSum.longValue(); } public void cleanSendBatchStat() { - sendBatchMsgNumSum.set(0l); - sendBatchMsgFailNumSum.set(0l); + sendBatchMsgNumSum.set(0L); + sendBatchMsgFailNumSum.set(0L); } public long getSendBatchMsgDiscardNumSum() { @@ -203,7 +206,8 @@ public long getSendBatchMsgDiscardNumSum() { } ////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_SENDMSG = "%15s : {\"maxSendMsgTPS\":\"%.1f\",\"avgSendMsgTPS\":\"%.1f\"," + + public static final String EVENTMESH_MONITOR_FORMAT_SENDMSG = "%15s : {\"maxSendMsgTPS\":\"%.1f\",\"avgSendMsgTPS\":\"%.1f\"," + + " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.2f\", \"discard\":\"%s\"}"; private AtomicLong sendMsgNumSum = new AtomicLong(0); @@ -249,7 +253,7 @@ public long getSendMsgFailNumSum() { } public float getSendMsgFailRate() { - return (sendMsgNumSum.longValue() == 0l) ? 0f : sendMsgFailNumSum.floatValue() / sendMsgNumSum.longValue(); + return (sendMsgNumSum.longValue() == 0L) ? 0f : sendMsgFailNumSum.floatValue() / sendMsgNumSum.longValue(); } public void recordSendMsgFailed() { @@ -261,8 +265,8 @@ public void recordSendMsgDiscard() { } public void cleanSendMsgStat() { - sendMsgNumSum.set(0l); - sendMsgFailNumSum.set(0l); + sendMsgNumSum.set(0L); + sendMsgFailNumSum.set(0L); } public long getSendMsgDiscardNumSum() { @@ -270,8 +274,10 @@ public long getSendMsgDiscardNumSum() { } //////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_PUSHMSG = "%15s : {\"maxPushMsgTPS\":\"%.1f\",\"avgPushMsgTPS\":\"%.1f\"," + - " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.1f\", \"maxClientLatency\":\"%.1f\", \"avgClientLatency\":\"%.1f\"}"; + public static final String EVENTMESH_MONITOR_FORMAT_PUSHMSG = "%15s : {\"maxPushMsgTPS\":\"%.1f\",\"avgPushMsgTPS\":\"%.1f\"," + + + " \"sum\":\"%s\", \"sumFail\":\"%s\", \"sumFailRate\":\"%.1f\", " + + "\"maxClientLatency\":\"%.1f\", \"avgClientLatency\":\"%.1f\"}"; private float wholePushCost = 0f; @@ -305,7 +311,7 @@ public void recordHTTPPushTimeCost(long cost) { } public float avgHTTPPushLatency() { - return (wholePushRequestNum.longValue() == 0l) ? 0f : wholePushCost / wholePushRequestNum.longValue(); + return (wholePushRequestNum.longValue() == 0L) ? 0f : wholePushCost / wholePushRequestNum.longValue(); } public float maxHTTPPushLatency() { @@ -336,7 +342,7 @@ public long getHttpPushFailNumSum() { } public float getHttpPushMsgFailRate() { - return (httpPushMsgNumSum.longValue() == 0l) ? 0f : httpPushFailNumSum.floatValue() / httpPushMsgNumSum.longValue(); + return (httpPushMsgNumSum.longValue() == 0L) ? 0f : httpPushFailNumSum.floatValue() / httpPushMsgNumSum.longValue(); } public void recordHttpPushMsgFailed() { @@ -344,19 +350,21 @@ public void recordHttpPushMsgFailed() { } public void cleanHttpPushMsgStat() { - httpPushFailNumSum.set(0l); - httpPushMsgNumSum.set(0l); - wholeRequestNum.set(0l); + httpPushFailNumSum.set(0L); + httpPushMsgNumSum.set(0L); + wholeRequestNum.set(0L); wholeCost = 0f; - maxCost.set(0l); + maxCost.set(0L); } /////////////////////////////////////////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_BLOCKQ = "%15s : {\"batchMsgQ\":\"%s\",\"sendMsgQ\":\"%s\"," + + public static final String EVENTMESH_MONITOR_FORMAT_BLOCKQ = "%15s : {\"batchMsgQ\":\"%s\",\"sendMsgQ\":\"%s\"," + + "\"pushMsgQ\":\"%s\",\"consumeRetryQ\":\"%s\"}"; /////////////////////////////////////////////////////////////////////////// - public static final String EVENTMESH_MONITOR_FORMAT_MQ_CLIENT = "%15s : {\"batchAvgSend2MQCost\":\"%.1f\", \"avgSend2MQCost\":\"%.1f\"}"; + public static final String EVENTMESH_MONITOR_FORMAT_MQ_CLIENT = "%15s : {\"batchAvgSend2MQCost\":\"%.1f\", " + + "\"avgSend2MQCost\":\"%.1f\"}"; private float batchSend2MQWholeCost = 0f; @@ -388,8 +396,8 @@ public float avgSendMsgCost() { public void send2MQStatInfoClear() { batchSend2MQWholeCost = 0f; - batchSend2MQNum.set(0l); + batchSend2MQNum.set(0L); send2MQWholeCost = 0f; - send2MQNum.set(0l); + send2MQNum.set(0L); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/TopicMetrics.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/TopicMetrics.java index 6a0afabdc9..06f97cada3 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/TopicMetrics.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/http/TopicMetrics.java @@ -17,10 +17,10 @@ package org.apache.eventmesh.runtime.metrics.http; -import com.codahale.metrics.MetricRegistry; - import org.apache.eventmesh.runtime.boot.EventMeshHTTPServer; +import com.codahale.metrics.MetricRegistry; + public class TopicMetrics { private EventMeshHTTPServer eventMeshHTTPServer; diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryHTTPMetricsExporter.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryHTTPMetricsExporter.java index b3805d2b9d..65d1357963 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryHTTPMetricsExporter.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryHTTPMetricsExporter.java @@ -17,13 +17,14 @@ package org.apache.eventmesh.runtime.metrics.opentelemetry; -import io.opentelemetry.api.metrics.GlobalMeterProvider; -import io.opentelemetry.api.metrics.Meter; -import io.opentelemetry.api.metrics.common.Labels; import org.apache.eventmesh.runtime.configuration.EventMeshHTTPConfiguration; import org.apache.eventmesh.runtime.metrics.http.HTTPMetricsServer; import org.apache.eventmesh.runtime.metrics.http.SummaryMetrics; +import io.opentelemetry.api.metrics.GlobalMeterProvider; +import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.api.metrics.common.Labels; + public class OpenTelemetryHTTPMetricsExporter { private final SummaryMetrics summaryMetrics; @@ -43,7 +44,7 @@ public void start() { .doubleValueObserverBuilder("eventmesh.http.request.tps.max") .setDescription("max TPS of HTTP.") .setUnit("HTTP") - .setUpdater(result -> result.observe(summaryMetrics.maxHTTPTPS(),Labels.empty())) + .setUpdater(result -> result.observe(summaryMetrics.maxHTTPTPS(), Labels.empty())) .build(); //avgHTTPTPS @@ -51,7 +52,7 @@ public void start() { .doubleValueObserverBuilder("eventmesh.http.request.tps.avg") .setDescription("avg TPS of HTTP.") .setUnit("HTTP") - .setUpdater(result -> result.observe(summaryMetrics.avgHTTPTPS(),Labels.empty())) + .setUpdater(result -> result.observe(summaryMetrics.avgHTTPTPS(), Labels.empty())) .build(); //maxHTTPCost @@ -303,7 +304,7 @@ public void start() { .build(); } - public void shutdown(){ + public void shutdown() { OpenTelemetryPrometheusExporter.shutdown(); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryPrometheusExporter.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryPrometheusExporter.java index 730adc9259..f3ca627932 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryPrometheusExporter.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryPrometheusExporter.java @@ -17,13 +17,16 @@ package org.apache.eventmesh.runtime.metrics.opentelemetry; -import io.opentelemetry.exporter.prometheus.PrometheusCollector; -import io.opentelemetry.sdk.metrics.SdkMeterProvider; -import io.prometheus.client.exporter.HTTPServer; import org.apache.eventmesh.common.config.CommonConfiguration; + +import java.io.IOException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.io.IOException; + +import io.opentelemetry.exporter.prometheus.PrometheusCollector; +import io.opentelemetry.sdk.metrics.SdkMeterProvider; +import io.prometheus.client.exporter.HTTPServer; public class OpenTelemetryPrometheusExporter { @@ -36,8 +39,8 @@ public class OpenTelemetryPrometheusExporter { * * @param configuration configuration. */ - public synchronized static void initialize(CommonConfiguration configuration) { - if (server != null){ + public static synchronized void initialize(CommonConfiguration configuration) { + if (server != null) { return; } PrometheusCollector.builder().setMetricProducer( @@ -45,7 +48,7 @@ public synchronized static void initialize(CommonConfiguration configuration) { int port = configuration.eventMeshPrometheusPort; try { //Use the daemon thread to start an HTTP server to serve the default Prometheus registry. - server = new HTTPServer(port,true); + server = new HTTPServer(port, true); } catch (IOException e) { logger.error("failed to start prometheus server, port: {} due to {}", port, e.getMessage()); } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryTCPMetricsExporter.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryTCPMetricsExporter.java index c75896236f..5b4f6ce69b 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryTCPMetricsExporter.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/opentelemetry/OpenTelemetryTCPMetricsExporter.java @@ -17,90 +17,86 @@ package org.apache.eventmesh.runtime.metrics.opentelemetry; -import io.opentelemetry.api.metrics.GlobalMeterProvider; -import io.opentelemetry.api.metrics.Meter; -import io.opentelemetry.api.metrics.common.Labels; import org.apache.eventmesh.runtime.configuration.EventMeshTCPConfiguration; import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcpConnectionHandler; import org.apache.eventmesh.runtime.metrics.tcp.EventMeshTcpMonitor; +import io.opentelemetry.api.metrics.GlobalMeterProvider; +import io.opentelemetry.api.metrics.Meter; +import io.opentelemetry.api.metrics.common.Labels; + public class OpenTelemetryTCPMetricsExporter { private final EventMeshTcpMonitor eventMeshTcpMonitor; - public OpenTelemetryTCPMetricsExporter(EventMeshTcpMonitor eventMeshTcpMonitor , EventMeshTCPConfiguration eventMeshTCPConfiguration){ + public OpenTelemetryTCPMetricsExporter(EventMeshTcpMonitor eventMeshTcpMonitor, + EventMeshTCPConfiguration eventMeshTCPConfiguration) { OpenTelemetryPrometheusExporter.initialize(eventMeshTCPConfiguration); this.eventMeshTcpMonitor = eventMeshTcpMonitor; } - public void start(){ + public void start() { Meter meter = GlobalMeterProvider.getMeter("apache-eventmesh"); //retryQueueSize - meter - .doubleValueObserverBuilder("eventmesh.tcp.retry.queue.size") + meter.doubleValueObserverBuilder("eventmesh.tcp.retry.queue.size") .setDescription("get size of retry queue.") .setUnit("TCP") - .setUpdater(result -> result.observe(eventMeshTcpMonitor.getEventMeshTCPServer().getEventMeshTcpRetryer().getRetrySize(), Labels.empty())) + .setUpdater(result -> result.observe( + eventMeshTcpMonitor.getEventMeshTCPServer() + .getEventMeshTcpRetryer().getRetrySize(), Labels.empty())) .build(); //client2eventMeshTPS - meter - .doubleValueObserverBuilder("eventmesh.tcp.server.tps") + meter.doubleValueObserverBuilder("eventmesh.tcp.server.tps") .setDescription("get tps of client to eventMesh.") .setUnit("TCP") .setUpdater(result -> result.observe(eventMeshTcpMonitor.getClient2eventMeshTPS(), Labels.empty())) .build(); //eventMesh2mqTPS - meter - .doubleValueObserverBuilder("eventmesh.tcp.mq.provider.tps") + meter.doubleValueObserverBuilder("eventmesh.tcp.mq.provider.tps") .setDescription("get tps of eventMesh to mq.") .setUnit("TCP") .setUpdater(result -> result.observe(eventMeshTcpMonitor.getEventMesh2mqTPS(), Labels.empty())) .build(); //mq2eventMeshTPS - meter - .doubleValueObserverBuilder("eventmesh.tcp.mq.consumer.tps") + meter.doubleValueObserverBuilder("eventmesh.tcp.mq.consumer.tps") .setDescription("get tps of mq to eventMesh.") .setUnit("TCP") .setUpdater(result -> result.observe(eventMeshTcpMonitor.getMq2eventMeshTPS(), Labels.empty())) .build(); //eventMesh2clientTPS - meter - .doubleValueObserverBuilder("eventmesh.tcp.client.tps") + meter.doubleValueObserverBuilder("eventmesh.tcp.client.tps") .setDescription("get tps of eventMesh to client.") .setUnit("TCP") .setUpdater(result -> result.observe(eventMeshTcpMonitor.getEventMesh2clientTPS(), Labels.empty())) .build(); //allTPS - meter - .doubleValueObserverBuilder("eventmesh.tcp.all.tps") + meter.doubleValueObserverBuilder("eventmesh.tcp.all.tps") .setDescription("get all TPS.") .setUnit("TCP") .setUpdater(result -> result.observe(eventMeshTcpMonitor.getAllTPS(), Labels.empty())) .build(); //EventMeshTcpConnectionHandler.connections - meter - .doubleValueObserverBuilder("eventmesh.tcp.connection.num") + meter.doubleValueObserverBuilder("eventmesh.tcp.connection.num") .setDescription("EventMeshTcpConnectionHandler.connections.") .setUnit("TCP") .setUpdater(result -> result.observe(EventMeshTcpConnectionHandler.connections.doubleValue(), Labels.empty())) .build(); //subTopicNum - meter - .doubleValueObserverBuilder("eventmesh.tcp.sub.topic.num") + meter.doubleValueObserverBuilder("eventmesh.tcp.sub.topic.num") .setDescription("get sub topic num.") .setUnit("TCP") .setUpdater(result -> result.observe(eventMeshTcpMonitor.getSubTopicNum(), Labels.empty())) .build(); } - public void shutdown(){ + public void shutdown() { OpenTelemetryPrometheusExporter.shutdown(); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/tcp/EventMeshTcpMonitor.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/tcp/EventMeshTcpMonitor.java index 2a2cbdca7c..c94e604b1e 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/tcp/EventMeshTcpMonitor.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/metrics/tcp/EventMeshTcpMonitor.java @@ -17,6 +17,13 @@ package org.apache.eventmesh.runtime.metrics.tcp; +import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcpConnectionHandler; +import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; +import org.apache.eventmesh.runtime.metrics.MonitorMetricConstants; +import org.apache.eventmesh.runtime.metrics.opentelemetry.OpenTelemetryTCPMetricsExporter; + import java.net.InetSocketAddress; import java.util.HashSet; import java.util.Iterator; @@ -27,12 +34,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.EventMeshTcpConnectionHandler; -import org.apache.eventmesh.runtime.core.protocol.tcp.client.session.Session; -import org.apache.eventmesh.runtime.metrics.MonitorMetricConstants; -import org.apache.eventmesh.runtime.metrics.opentelemetry.OpenTelemetryTCPMetricsExporter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -83,7 +84,7 @@ public void init() throws Exception { this.eventMesh2mqMsgNum = new AtomicInteger(0); this.mq2eventMeshMsgNum = new AtomicInteger(0); this.eventMesh2clientMsgNum = new AtomicInteger(0); - this.metricsExporter = new OpenTelemetryTCPMetricsExporter(this,eventMeshTCPServer.getEventMeshTCPConfiguration()); + this.metricsExporter = new OpenTelemetryTCPMetricsExporter(this, eventMeshTCPServer.getEventMeshTCPConfiguration()); logger.info("EventMeshTcpMonitor inited......"); } @@ -130,26 +131,35 @@ public void run() { } subTopicNum = topicSet.size(); - appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.CLIENT_2_EVENTMESH_TPS, client2eventMeshTPS)); - appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.EVENTMESH_2_MQ_TPS, eventMesh2mqTPS)); - appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.MQ_2_EVENTMESH_TPS, mq2eventMeshTPS)); - appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.EVENTMESH_2_CLIENT_TPS, eventMesh2clientTPS)); - appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.ALL_TPS, allTPS)); - appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.CONNECTION, EventMeshTcpConnectionHandler.connections)); - appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.SUB_TOPIC_NUM, subTopicNum)); + appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, + EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.CLIENT_2_EVENTMESH_TPS, client2eventMeshTPS)); + appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, + EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.EVENTMESH_2_MQ_TPS, eventMesh2mqTPS)); + appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, + EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.MQ_2_EVENTMESH_TPS, mq2eventMeshTPS)); + appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, + EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.EVENTMESH_2_CLIENT_TPS, eventMesh2clientTPS)); + appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, + EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.ALL_TPS, allTPS)); + appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, + EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.CONNECTION, + EventMeshTcpConnectionHandler.connections)); + appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, + EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.SUB_TOPIC_NUM, subTopicNum)); } }), delay, period, TimeUnit.MILLISECONDS); monitorThreadPoolTask = eventMeshTCPServer.getScheduler().scheduleAtFixedRate(new Runnable() { @Override public void run() { -// ThreadPoolHelper.printThreadPoolState(); + //ThreadPoolHelper.printThreadPoolState(); eventMeshTCPServer.getEventMeshRebalanceService().printRebalanceThreadPoolState(); eventMeshTCPServer.getEventMeshTcpRetryer().printRetryThreadPoolState(); //monitor retry queue size int retrySize = eventMeshTCPServer.getEventMeshTcpRetryer().getRetrySize(); - appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.RETRY_QUEUE_SIZE, retrySize)); + appLogger.info(String.format(MonitorMetricConstants.EVENTMESH_MONITOR_FORMAT_COMMON, + EventMeshConstants.PROTOCOL_TCP, MonitorMetricConstants.RETRY_QUEUE_SIZE, retrySize)); } }, 10, PRINT_THREADPOOLSTATE_INTERVAL, TimeUnit.SECONDS); logger.info("EventMeshTcpMonitor started......"); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/registry/Registry.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/registry/Registry.java index c8fe7ad8f4..2a8d6999cf 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/registry/Registry.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/registry/Registry.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.runtime.registry; import org.apache.eventmesh.api.registry.RegistryService; @@ -21,12 +22,13 @@ import org.apache.eventmesh.api.registry.dto.EventMeshRegisterInfo; import org.apache.eventmesh.api.registry.dto.EventMeshUnRegisterInfo; import org.apache.eventmesh.spi.EventMeshExtensionFactory; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.util.List; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class Registry { private static final Logger logger = LoggerFactory.getLogger(Registry.class); private static RegistryService registryService; @@ -40,27 +42,27 @@ public void init(String registryPluginType) throws Exception { registryService.init(); } - public void start() throws Exception{ + public void start() throws Exception { registryService.start(); } - public void shutdown() throws Exception{ + public void shutdown() throws Exception { registryService.shutdown(); } - public List findEventMeshInfoByCluster(String clusterName) throws Exception{ + public List findEventMeshInfoByCluster(String clusterName) throws Exception { return registryService.findEventMeshInfoByCluster(clusterName); } - public Map> findEventMeshClientDistributionData(String clusterName, String group, String purpose) throws Exception{ + public Map> findEventMeshClientDistributionData(String clusterName, String group, String purpose) throws Exception { return registryService.findEventMeshClientDistributionData(clusterName, group, purpose); } - public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws Exception{ + public boolean register(EventMeshRegisterInfo eventMeshRegisterInfo) throws Exception { return registryService.register(eventMeshRegisterInfo); } - public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throws Exception{ + public boolean unRegister(EventMeshUnRegisterInfo eventMeshUnRegisterInfo) throws Exception { return registryService.unRegister(eventMeshUnRegisterInfo); } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java index 22400f7c3d..3e3c066ab4 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/EventMeshUtil.java @@ -17,44 +17,43 @@ package org.apache.eventmesh.runtime.util; +import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; +import org.apache.eventmesh.common.utils.RandomStringUtils; +import org.apache.eventmesh.common.utils.ThreadUtils; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import org.apache.eventmesh.runtime.constants.EventMeshVersion; + +import org.apache.commons.lang3.StringUtils; + import java.net.Inet6Address; import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.UnknownHostException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.TimeZone; import java.util.concurrent.ThreadPoolExecutor; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.cloudevents.CloudEvent; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import io.cloudevents.CloudEvent; - -import org.apache.commons.lang3.StringUtils; -import org.apache.eventmesh.common.Constants; -import org.apache.eventmesh.common.utils.RandomStringUtils; -import org.apache.eventmesh.common.utils.ThreadUtils; -import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; -import org.apache.eventmesh.common.protocol.tcp.UserAgent; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; -import org.apache.eventmesh.runtime.constants.EventMeshVersion; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class EventMeshUtil { - public static Logger logger = LoggerFactory.getLogger(EventMeshUtil.class); + private static final Logger logger = LoggerFactory.getLogger(EventMeshUtil.class); - private final static Logger tcpLogger = LoggerFactory.getLogger("tcpMonitor"); + private static final Logger tcpLogger = LoggerFactory.getLogger("tcpMonitor"); public static String buildPushMsgSeqNo() { return StringUtils.rightPad(String.valueOf(System.currentTimeMillis()), 6) + RandomStringUtils.generateNum(4); @@ -155,86 +154,86 @@ public static Map getEventProp(CloudEvent event) { return prop; } -// public static org.apache.rocketmq.common.message.Message decodeMessage(AccessMessage accessMessage) { -// org.apache.rocketmq.common.message.Message msg = new org.apache.rocketmq.common.message.Message(); -// msg.setTopic(accessMessage.getTopic()); -// msg.setBody(accessMessage.getBody().getBytes()); -// msg.getProperty("init"); -// for (Map.Entry property : accessMessage.getProperties().entrySet()) { -// msg.getProperties().put(property.getKey(), property.getValue()); -// } -// return msg; -// } - -// public static Message decodeMessage(EventMeshMessage eventMeshMessage) { -// Message omsMsg = new Message(); -// omsMsg.setBody(eventMeshMessage.getBody().getBytes()); -// omsMsg.setTopic(eventMeshMessage.getTopic()); -// Properties systemProperties = new Properties(); -// Properties userProperties = new Properties(); -// -// final Set> entries = eventMeshMessage.getProperties().entrySet(); -// -// for (final Map.Entry entry : entries) { -// if (isOMSHeader(entry.getKey())) { -// systemProperties.put(entry.getKey(), entry.getValue()); -// } else { -// userProperties.put(entry.getKey(), entry.getValue()); -// } -// } -// -// systemProperties.put(Constants.PROPERTY_MESSAGE_DESTINATION, eventMeshMessage.getTopic()); -// omsMsg.setSystemProperties(systemProperties); -// omsMsg.setUserProperties(userProperties); -// return omsMsg; -// } - -// public static AccessMessage encodeMessage(org.apache.rocketmq.common.message.Message msg) throws Exception { -// AccessMessage accessMessage = new AccessMessage(); -// accessMessage.setBody(new String(msg.getBody(), "UTF-8")); -// accessMessage.setTopic(msg.getTopic()); -// for (Map.Entry property : msg.getProperties().entrySet()) { -// accessMessage.getProperties().put(property.getKey(), property.getValue()); -// } -// return accessMessage; -// } - -// public static EventMeshMessage encodeMessage(Message omsMessage) throws Exception { -// -// EventMeshMessage eventMeshMessage = new EventMeshMessage(); -// eventMeshMessage.setBody(new String(omsMessage.getBody(), StandardCharsets.UTF_8)); -// -// Properties sysHeaders = omsMessage.getSystemProperties(); -// Properties userHeaders = omsMessage.getUserProperties(); -// -// //All destinations in RocketMQ use Topic -// eventMeshMessage.setTopic(sysHeaders.getProperty(Constants.PROPERTY_MESSAGE_DESTINATION)); -// -// if (sysHeaders.containsKey("START_TIME")) { -// long deliverTime; -// if (StringUtils.isBlank(sysHeaders.getProperty("START_TIME"))) { -// deliverTime = 0; -// } else { -// deliverTime = Long.parseLong(sysHeaders.getProperty("START_TIME")); -// } -// -// if (deliverTime > 0) { -//// rmqMessage.putUserProperty(RocketMQConstants.START_DELIVER_TIME, String.valueOf(deliverTime)); -// eventMeshMessage.getProperties().put("START_TIME", String.valueOf(deliverTime)); -// } -// } -// -// for (String key : userHeaders.stringPropertyNames()) { -// eventMeshMessage.getProperties().put(key, userHeaders.getProperty(key)); -// } -// -// //System headers has a high priority -// for (String key : sysHeaders.stringPropertyNames()) { -// eventMeshMessage.getProperties().put(key, sysHeaders.getProperty(key)); -// } -// -// return eventMeshMessage; -// } + //public static org.apache.rocketmq.common.message.Message decodeMessage(AccessMessage accessMessage) { + // org.apache.rocketmq.common.message.Message msg = new org.apache.rocketmq.common.message.Message(); + // msg.setTopic(accessMessage.getTopic()); + // msg.setBody(accessMessage.getBody().getBytes()); + // msg.getProperty("init"); + // for (Map.Entry property : accessMessage.getProperties().entrySet()) { + // msg.getProperties().put(property.getKey(), property.getValue()); + // } + // return msg; + //} + + //public static Message decodeMessage(EventMeshMessage eventMeshMessage) { + // Message omsMsg = new Message(); + // omsMsg.setBody(eventMeshMessage.getBody().getBytes()); + // omsMsg.setTopic(eventMeshMessage.getTopic()); + // Properties systemProperties = new Properties(); + // Properties userProperties = new Properties(); + // + // final Set> entries = eventMeshMessage.getProperties().entrySet(); + // + // for (final Map.Entry entry : entries) { + // if (isOMSHeader(entry.getKey())) { + // systemProperties.put(entry.getKey(), entry.getValue()); + // } else { + // userProperties.put(entry.getKey(), entry.getValue()); + // } + // } + // + // systemProperties.put(Constants.PROPERTY_MESSAGE_DESTINATION, eventMeshMessage.getTopic()); + // omsMsg.setSystemProperties(systemProperties); + // omsMsg.setUserProperties(userProperties); + // return omsMsg; + //} + // + //public static AccessMessage encodeMessage(org.apache.rocketmq.common.message.Message msg) throws Exception { + // AccessMessage accessMessage = new AccessMessage(); + // accessMessage.setBody(new String(msg.getBody(), "UTF-8")); + // accessMessage.setTopic(msg.getTopic()); + // for (Map.Entry property : msg.getProperties().entrySet()) { + // accessMessage.getProperties().put(property.getKey(), property.getValue()); + // } + // return accessMessage; + //} + + //public static EventMeshMessage encodeMessage(Message omsMessage) throws Exception { + // + // EventMeshMessage eventMeshMessage = new EventMeshMessage(); + // eventMeshMessage.setBody(new String(omsMessage.getBody(), StandardCharsets.UTF_8)); + // + // Properties sysHeaders = omsMessage.getSystemProperties(); + // Properties userHeaders = omsMessage.getUserProperties(); + // + // //All destinations in RocketMQ use Topic + // eventMeshMessage.setTopic(sysHeaders.getProperty(Constants.PROPERTY_MESSAGE_DESTINATION)); + // + // if (sysHeaders.containsKey("START_TIME")) { + // long deliverTime; + // if (StringUtils.isBlank(sysHeaders.getProperty("START_TIME"))) { + // deliverTime = 0; + // } else { + // deliverTime = Long.parseLong(sysHeaders.getProperty("START_TIME")); + // } + // + // if (deliverTime > 0) { + // // rmqMessage.putUserProperty(RocketMQConstants.START_DELIVER_TIME, String.valueOf(deliverTime)); + // eventMeshMessage.getProperties().put("START_TIME", String.valueOf(deliverTime)); + // } + // } + // + // for (String key : userHeaders.stringPropertyNames()) { + // eventMeshMessage.getProperties().put(key, userHeaders.getProperty(key)); + // } + // + // //System headers has a high priority + // for (String key : sysHeaders.stringPropertyNames()) { + // eventMeshMessage.getProperties().put(key, sysHeaders.getProperty(key)); + // } + // + // return eventMeshMessage; + //} public static String getLocalAddr() { //priority of networkInterface when generating client ip @@ -254,10 +253,9 @@ public static String getLocalAddr() { continue; } else if (preferNetworkInterface == null) { preferNetworkInterface = networkInterface; - } - //get the networkInterface that has higher priority - else if (preferList.indexOf(networkInterface.getName()) + } else if (preferList.indexOf(networkInterface.getName()) > preferList.indexOf(preferNetworkInterface.getName())) { + //get the networkInterface that has higher priority preferNetworkInterface = networkInterface; } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpTinyClient.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpTinyClient.java index f3a930ca0b..c118471abf 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpTinyClient.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/HttpTinyClient.java @@ -17,6 +17,8 @@ package org.apache.eventmesh.runtime.util; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; + import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.HttpURLConnection; @@ -25,11 +27,9 @@ import java.util.Iterator; import java.util.List; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; - public class HttpTinyClient { - static public HttpResult httpGet(String url, List headers, List paramValues, + public static HttpResult httpGet(String url, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException { String encodedContent = encodingParams(paramValues, encoding); url += (null == encodedContent) ? "" : ("?" + encodedContent); @@ -59,7 +59,7 @@ static public HttpResult httpGet(String url, List headers, List } } - static private String encodingParams(List paramValues, String encoding) + private static String encodingParams(List paramValues, String encoding) throws UnsupportedEncodingException { StringBuilder sb = new StringBuilder(); if (null == paramValues) { @@ -76,13 +76,13 @@ static private String encodingParams(List paramValues, String encoding) return sb.toString(); } - static private void setHeaders(HttpURLConnection conn, List headers, String encoding) { + private static void setHeaders(HttpURLConnection conn, List headers, String encoding) { if (null != headers) { for (Iterator iter = headers.iterator(); iter.hasNext(); ) { conn.addRequestProperty(iter.next(), iter.next()); } } -// conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION)); + //conn.addRequestProperty("Client-Version", MQVersion.getVersionDesc(MQVersion.CURRENT_VERSION)); conn.addRequestProperty("Content-Type", "application/x-www-form-urlencoded;charset=" + encoding); String ts = String.valueOf(System.currentTimeMillis()); @@ -92,7 +92,7 @@ static private void setHeaders(HttpURLConnection conn, List headers, Str /** * @return the http response of given http post request */ - static public HttpResult httpPost(String url, List headers, List paramValues, + public static HttpResult httpPost(String url, List headers, List paramValues, String encoding, long readTimeoutMs) throws IOException { String encodedContent = encodingParams(paramValues, encoding); @@ -124,13 +124,21 @@ static public HttpResult httpPost(String url, List headers, List } } - static public class HttpResult { - final public int code; - final public String content; + public static class HttpResult { + private final int code; + private final String content; public HttpResult(int code, String content) { this.code = code; this.content = content; } + + public int getCode() { + return code; + } + + public String getContent() { + return content; + } } } diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/IOTinyUtils.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/IOTinyUtils.java index 7ce4d154aa..5aa3153747 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/IOTinyUtils.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/IOTinyUtils.java @@ -17,6 +17,8 @@ package org.apache.eventmesh.runtime.util; +import org.apache.eventmesh.runtime.constants.EventMeshConstants; + import java.io.BufferedReader; import java.io.CharArrayWriter; import java.io.File; @@ -32,22 +34,20 @@ import java.util.ArrayList; import java.util.List; -import org.apache.eventmesh.runtime.constants.EventMeshConstants; - public class IOTinyUtils { - static public String toString(InputStream input, String encoding) throws IOException { - return (null == encoding) ? toString(new InputStreamReader(input, EventMeshConstants.DEFAULT_CHARSET)) : toString(new InputStreamReader( - input, encoding)); + public static String toString(InputStream input, String encoding) throws IOException { + return (null == encoding) ? toString(new InputStreamReader(input, EventMeshConstants.DEFAULT_CHARSET)) + : toString(new InputStreamReader(input, encoding)); } - static public String toString(Reader reader) throws IOException { + public static String toString(Reader reader) throws IOException { CharArrayWriter sw = new CharArrayWriter(); copy(reader, sw); return sw.toString(); } - static public long copy(Reader input, Writer output) throws IOException { + public static long copy(Reader input, Writer output) throws IOException { char[] buffer = new char[1 << 12]; long count = 0; for (int n = 0; (n = input.read(buffer)) >= 0; ) { @@ -57,7 +57,7 @@ static public long copy(Reader input, Writer output) throws IOException { return count; } - static public List readLines(Reader input) throws IOException { + public static List readLines(Reader input) throws IOException { BufferedReader reader = toBufferedReader(input); List list = new ArrayList(); String line; @@ -72,11 +72,11 @@ static public List readLines(Reader input) throws IOException { return list; } - static private BufferedReader toBufferedReader(Reader reader) { + private static BufferedReader toBufferedReader(Reader reader) { return reader instanceof BufferedReader ? (BufferedReader) reader : new BufferedReader(reader); } - static public void copyFile(String source, String target) throws IOException { + public static void copyFile(String source, String target) throws IOException { File sf = new File(source); if (!sf.exists()) { throw new IllegalArgumentException("source file does not exist."); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/NetUtils.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/NetUtils.java index a2563bce3b..3a1cc8787b 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/NetUtils.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/NetUtils.java @@ -17,9 +17,6 @@ package org.apache.eventmesh.runtime.util; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.io.UnsupportedEncodingException; import java.net.InetSocketAddress; import java.net.URLDecoder; @@ -28,6 +25,9 @@ import java.util.List; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class NetUtils { private static final Logger logger = LoggerFactory.getLogger(NetUtils.class); diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/RemotingHelper.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/RemotingHelper.java index 0266a924dd..6bbff738f0 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/RemotingHelper.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/RemotingHelper.java @@ -16,16 +16,17 @@ * specific language governing permissions and limitations * under the License. */ + package org.apache.eventmesh.runtime.util; import java.net.InetSocketAddress; import java.net.SocketAddress; -import io.netty.channel.Channel; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.Channel; + public class RemotingHelper { public static final String DEFAULT_CHARSET = "UTF-8"; @@ -55,97 +56,97 @@ public static SocketAddress string2SocketAddress(final String addr) { return isa; } -// public static RemotingCommand invokeSync(final String addr, final RemotingCommand request, -// final long timeoutMillis) throws InterruptedException, RemotingConnectException, -// RemotingSendRequestException, RemotingTimeoutException { -// long beginTime = System.currentTimeMillis(); -// SocketAddress socketAddress = RemotingUtil.string2SocketAddress(addr); -// SocketChannel socketChannel = RemotingUtil.connect(socketAddress); -// if (socketChannel != null) { -// boolean sendRequestOK = false; -// -// try { -// -// socketChannel.configureBlocking(true); -// -// //bugfix http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4614802 -// socketChannel.socket().setSoTimeout((int) timeoutMillis); -// -// ByteBuffer byteBufferRequest = request.encode(); -// while (byteBufferRequest.hasRemaining()) { -// int length = socketChannel.write(byteBufferRequest); -// if (length > 0) { -// if (byteBufferRequest.hasRemaining()) { -// if ((System.currentTimeMillis() - beginTime) > timeoutMillis) { -// -// throw new RemotingSendRequestException(addr); -// } -// } -// } else { -// throw new RemotingSendRequestException(addr); -// } -// -// Thread.sleep(1); -// } -// -// sendRequestOK = true; -// -// ByteBuffer byteBufferSize = ByteBuffer.allocate(4); -// while (byteBufferSize.hasRemaining()) { -// int length = socketChannel.read(byteBufferSize); -// if (length > 0) { -// if (byteBufferSize.hasRemaining()) { -// if ((System.currentTimeMillis() - beginTime) > timeoutMillis) { -// -// throw new RemotingTimeoutException(addr, timeoutMillis); -// } -// } -// } else { -// throw new RemotingTimeoutException(addr, timeoutMillis); -// } -// -// Thread.sleep(1); -// } -// -// int size = byteBufferSize.getInt(0); -// ByteBuffer byteBufferBody = ByteBuffer.allocate(size); -// while (byteBufferBody.hasRemaining()) { -// int length = socketChannel.read(byteBufferBody); -// if (length > 0) { -// if (byteBufferBody.hasRemaining()) { -// if ((System.currentTimeMillis() - beginTime) > timeoutMillis) { -// -// throw new RemotingTimeoutException(addr, timeoutMillis); -// } -// } -// } else { -// throw new RemotingTimeoutException(addr, timeoutMillis); -// } -// -// Thread.sleep(1); -// } -// -// byteBufferBody.flip(); -// return RemotingCommand.decode(byteBufferBody); -// } catch (IOException e) { -// log.error("invokeSync failure", e); -// -// if (sendRequestOK) { -// throw new RemotingTimeoutException(addr, timeoutMillis); -// } else { -// throw new RemotingSendRequestException(addr); -// } -// } finally { -// try { -// socketChannel.close(); -// } catch (IOException e) { -// e.printStackTrace(); -// } -// } -// } else { -// throw new RemotingConnectException(addr); -// } -// } + //public static RemotingCommand invokeSync(final String addr, final RemotingCommand request, + // final long timeoutMillis) throws InterruptedException, RemotingConnectException, + // RemotingSendRequestException, RemotingTimeoutException { + // long beginTime = System.currentTimeMillis(); + // SocketAddress socketAddress = RemotingUtil.string2SocketAddress(addr); + // SocketChannel socketChannel = RemotingUtil.connect(socketAddress); + // if (socketChannel != null) { + // boolean sendRequestOK = false; + // + // try { + // + // socketChannel.configureBlocking(true); + // + // //bugfix http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4614802 + // socketChannel.socket().setSoTimeout((int) timeoutMillis); + // + // ByteBuffer byteBufferRequest = request.encode(); + // while (byteBufferRequest.hasRemaining()) { + // int length = socketChannel.write(byteBufferRequest); + // if (length > 0) { + // if (byteBufferRequest.hasRemaining()) { + // if ((System.currentTimeMillis() - beginTime) > timeoutMillis) { + // + // throw new RemotingSendRequestException(addr); + // } + // } + // } else { + // throw new RemotingSendRequestException(addr); + // } + // + // Thread.sleep(1); + // } + // + // sendRequestOK = true; + // + // ByteBuffer byteBufferSize = ByteBuffer.allocate(4); + // while (byteBufferSize.hasRemaining()) { + // int length = socketChannel.read(byteBufferSize); + // if (length > 0) { + // if (byteBufferSize.hasRemaining()) { + // if ((System.currentTimeMillis() - beginTime) > timeoutMillis) { + // + // throw new RemotingTimeoutException(addr, timeoutMillis); + // } + // } + // } else { + // throw new RemotingTimeoutException(addr, timeoutMillis); + // } + // + // Thread.sleep(1); + // } + // + // int size = byteBufferSize.getInt(0); + // ByteBuffer byteBufferBody = ByteBuffer.allocate(size); + // while (byteBufferBody.hasRemaining()) { + // int length = socketChannel.read(byteBufferBody); + // if (length > 0) { + // if (byteBufferBody.hasRemaining()) { + // if ((System.currentTimeMillis() - beginTime) > timeoutMillis) { + // + // throw new RemotingTimeoutException(addr, timeoutMillis); + // } + // } + // } else { + // throw new RemotingTimeoutException(addr, timeoutMillis); + // } + // + // Thread.sleep(1); + // } + // + // byteBufferBody.flip(); + // return RemotingCommand.decode(byteBufferBody); + // } catch (IOException e) { + // log.error("invokeSync failure", e); + // + // if (sendRequestOK) { + // throw new RemotingTimeoutException(addr, timeoutMillis); + // } else { + // throw new RemotingSendRequestException(addr); + // } + // } finally { + // try { + // socketChannel.close(); + // } catch (IOException e) { + // e.printStackTrace(); + // } + // } + // } else { + // throw new RemotingConnectException(addr); + // } + //} public static String parseChannelRemoteAddr(final Channel channel) { if (null == channel) { diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/Utils.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/Utils.java index fb3ee4bc1f..e6be33a347 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/Utils.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/Utils.java @@ -36,8 +36,8 @@ import io.netty.channel.ChannelHandlerContext; public class Utils { - private final static Logger logger = LoggerFactory.getLogger(Utils.class); - private final static Logger messageLogger = LoggerFactory.getLogger("message"); + private static final Logger logger = LoggerFactory.getLogger(Utils.class); + private static final Logger messageLogger = LoggerFactory.getLogger("message"); /** * used to send messages to the client @@ -49,30 +49,30 @@ public class Utils { */ public static void writeAndFlush(final Package pkg, long startTime, long taskExecuteTime, ChannelHandlerContext ctx, Session - session) { + session) { try { UserAgent user = session == null ? null : session.getClient(); if (session != null && session.getSessionState().equals(SessionState.CLOSED)) { logFailedMessageFlow(pkg, user, startTime, taskExecuteTime, - new Exception("the session has been closed")); + new Exception("the session has been closed")); return; } ctx.writeAndFlush(pkg).addListener( - new ChannelFutureListener() { - @Override - public void operationComplete(ChannelFuture future) throws Exception { - if (!future.isSuccess()) { - logFailedMessageFlow(future, pkg, user, startTime, taskExecuteTime); - } else { - logSucceedMessageFlow(pkg, user, startTime, taskExecuteTime); - - if (session != null) { - session.getClientGroupWrapper().get().getEventMeshTcpMonitor() - .getEventMesh2clientMsgNum().incrementAndGet(); + new ChannelFutureListener() { + @Override + public void operationComplete(ChannelFuture future) throws Exception { + if (!future.isSuccess()) { + logFailedMessageFlow(future, pkg, user, startTime, taskExecuteTime); + } else { + logSucceedMessageFlow(pkg, user, startTime, taskExecuteTime); + + if (session != null) { + session.getClientGroupWrapper().get().getEventMeshTcpMonitor() + .getEventMesh2clientMsgNum().incrementAndGet(); + } } } } - } ); } catch (Exception e) { logger.error("exception while sending message to client", e); @@ -96,13 +96,13 @@ private static void logFailedMessageFlow(Package pkg, UserAgent user, long start Throwable e) { if (pkg.getBody() instanceof EventMeshMessage) { messageLogger.error("pkg|eventMesh2c|failed|cmd={}|mqMsg={}|user={}|wait={}ms|cost={}ms|errMsg={}", - pkg.getHeader().getCmd(), - printMqMessage((EventMeshMessage) pkg.getBody()), user, taskExecuteTime - startTime, - System.currentTimeMillis() - startTime, e); + pkg.getHeader().getCmd(), + printMqMessage((EventMeshMessage) pkg.getBody()), user, taskExecuteTime - startTime, + System.currentTimeMillis() - startTime, e); } else { messageLogger.error("pkg|eventMesh2c|failed|cmd={}|pkg={}|user={}|wait={}ms|cost={}ms|errMsg={}", - pkg.getHeader().getCmd(), - pkg, user, taskExecuteTime - startTime, System.currentTimeMillis() - startTime, e); + pkg.getHeader().getCmd(), + pkg, user, taskExecuteTime - startTime, System.currentTimeMillis() - startTime, e); } } @@ -116,12 +116,12 @@ private static void logFailedMessageFlow(Package pkg, UserAgent user, long start public static void logSucceedMessageFlow(Package pkg, UserAgent user, long startTime, long taskExecuteTime) { if (pkg.getBody() instanceof EventMeshMessage) { messageLogger.info("pkg|eventMesh2c|cmd={}|mqMsg={}|user={}|wait={}ms|cost={}ms", pkg.getHeader().getCmd(), - printMqMessage((EventMeshMessage) pkg.getBody()), user, taskExecuteTime - startTime, - System.currentTimeMillis() - startTime); + printMqMessage((EventMeshMessage) pkg.getBody()), user, taskExecuteTime - startTime, + System.currentTimeMillis() - startTime); } else { messageLogger - .info("pkg|eventMesh2c|cmd={}|pkg={}|user={}|wait={}ms|cost={}ms", pkg.getHeader().getCmd(), pkg, - user, taskExecuteTime - startTime, System.currentTimeMillis() - startTime); + .info("pkg|eventMesh2c|cmd={}|pkg={}|user={}|wait={}ms|cost={}ms", pkg.getHeader().getCmd(), pkg, + user, taskExecuteTime - startTime, System.currentTimeMillis() - startTime); } } @@ -140,8 +140,8 @@ public static String printMqMessage(EventMeshMessage eventMeshMessage) { } String result = String.format("Message [topic=%s,TTL=%s,uniqueId=%s,bizSeq=%s]", eventMeshMessage - .getTopic(), properties.get(EventMeshConstants.TTL), properties.get(EventMeshConstants.RR_REQUEST_UNIQ_ID), - bizSeqNo); + .getTopic(), properties.get(EventMeshConstants.TTL), properties.get(EventMeshConstants.RR_REQUEST_UNIQ_ID), + bizSeqNo); return result; } @@ -151,13 +151,13 @@ public static String printMqMessage(EventMeshMessage eventMeshMessage) { * @param message * @return */ -// public static String printMqMessage(org.apache.rocketmq.common.message.Message message) { -// Map properties = message.getProperties(); -// String bizSeqNo = message.getKeys(); -// String result = String.format("Message [topic=%s,TTL=%s,uniqueId=%s,bizSeq=%s]", message.getTopic() -// , properties.get(EventMeshConstants.TTL), properties.get(EventMeshConstants.RR_REQUEST_UNIQ_ID), bizSeqNo); -// return result; -// } + //public static String printMqMessage(org.apache.rocketmq.common.message.Message message) { + // Map properties = message.getProperties(); + // String bizSeqNo = message.getKeys(); + // String result = String.format("Message [topic=%s,TTL=%s,uniqueId=%s,bizSeq=%s]", message.getTopic() + // , properties.get(EventMeshConstants.TTL), properties.get(EventMeshConstants.RR_REQUEST_UNIQ_ID), bizSeqNo); + // return result; + //} /** * get serviceId according to topic diff --git a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/ValueComparator.java b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/ValueComparator.java index 510db76109..d8c8f4d0c6 100644 --- a/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/ValueComparator.java +++ b/eventmesh-runtime/src/main/java/org/apache/eventmesh/runtime/util/ValueComparator.java @@ -23,9 +23,9 @@ public class ValueComparator implements Comparator> { @Override public int compare(Map.Entry x, Map.Entry y) { - if(x.getValue().intValue() != y.getValue().intValue()){ + if (x.getValue().intValue() != y.getValue().intValue()) { return x.getValue().intValue() - y.getValue().intValue(); - }else { + } else { return x.getKey().compareTo(y.getKey()); } } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java index c28a460d7a..7ed08f7db4 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/admin/handler/RedirectClientByIpPortHandlerTest.java @@ -19,18 +19,20 @@ package org.apache.eventmesh.runtime.admin.handler; -import com.sun.net.httpserver.HttpExchange; import org.apache.eventmesh.runtime.boot.EventMeshTCPServer; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.powermock.api.mockito.PowerMockito; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.URI; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.powermock.api.mockito.PowerMockito; + +import com.sun.net.httpserver.HttpExchange; + public class RedirectClientByIpPortHandlerTest { private RedirectClientByIpPortHandler redirectClientByIpPortHandler; diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/EventMeshClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/EventMeshClient.java index 2ba50e7dbf..59c060e826 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/EventMeshClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/EventMeshClient.java @@ -17,12 +17,14 @@ package org.apache.eventmesh.runtime.client.api; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.Package; - import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; -import org.apache.eventmesh.common.protocol.SubscriptionMode; +/** + * EventMeshClient + */ public interface EventMeshClient { Package rr(Package msg, long timeout) throws Exception; diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/PubClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/PubClient.java index 938b5e05de..f0097af0b7 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/PubClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/PubClient.java @@ -19,10 +19,11 @@ import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.common.protocol.tcp.UserAgent; - import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; - +/** + * PubClient + */ public interface PubClient { void init() throws Exception; diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/SubClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/SubClient.java index 03772d19d7..524b1ba14a 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/SubClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/api/SubClient.java @@ -17,14 +17,15 @@ package org.apache.eventmesh.runtime.client.api; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.Package; -import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; - import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; - +/** + * SubClient + */ public interface SubClient { void init() throws Exception; diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/ClientConstants.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/ClientConstants.java index ed8a9dbb68..466e8d1e5e 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/ClientConstants.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/ClientConstants.java @@ -17,7 +17,9 @@ package org.apache.eventmesh.runtime.client.common; - +/** + * ClientConstants + */ public interface ClientConstants { /** diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/ClientGlobal.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/ClientGlobal.java index 2f29d88412..65e14fd2fa 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/ClientGlobal.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/ClientGlobal.java @@ -19,14 +19,14 @@ import java.util.TimeZone; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class ClientGlobal { diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/Codec.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/Codec.java index d31bb43c9f..1124287c86 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/Codec.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/Codec.java @@ -17,15 +17,6 @@ package org.apache.eventmesh.runtime.client.common; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.List; - -import io.netty.buffer.ByteBuf; -import io.netty.channel.ChannelHandlerContext; -import io.netty.handler.codec.MessageToByteEncoder; -import io.netty.handler.codec.ReplayingDecoder; - import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Header; @@ -34,14 +25,24 @@ import org.apache.eventmesh.common.protocol.tcp.Subscription; import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.constants.EventMeshConstants; + +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.List; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToByteEncoder; +import io.netty.handler.codec.ReplayingDecoder; + public class Codec { - private final static Logger logger = LoggerFactory.getLogger(Codec.class); + private static final Logger logger = LoggerFactory.getLogger(Codec.class); private static final int FRAME_MAX_LENGTH = 1024 * 1024 * 4; - private static Charset UTF8 = Charset.forName(EventMeshConstants.DEFAULT_CHARSET); + private static final Charset UTF8 = Charset.forName(EventMeshConstants.DEFAULT_CHARSET); private static final byte[] CONSTANT_MAGIC_FLAG = "EventMesh".getBytes(UTF8); private static final byte[] VERSION = "0000".getBytes(UTF8); @@ -72,10 +73,12 @@ public void encode(ChannelHandlerContext ctx, Package pkg, ByteBuf out) throws E out.writeBytes(VERSION); out.writeInt(length); out.writeInt(headerLength); - if (headerData != null) + if (headerData != null) { out.writeBytes(headerData); - if (bodyData != null) + } + if (bodyData != null) { out.writeBytes(bodyData); + } } } @@ -90,8 +93,9 @@ public void decode(ChannelHandlerContext ctx, ByteBuf in, List out) thro int bodyLength = 0; try { - if (null == in) + if (null == in) { return; + } byte[] flagBytes = new byte[CONSTANT_MAGIC_FLAG.length]; byte[] versionBytes = new byte[VERSION.length]; @@ -99,9 +103,10 @@ public void decode(ChannelHandlerContext ctx, ByteBuf in, List out) thro in.readBytes(flagBytes); in.readBytes(versionBytes); if (!Arrays.equals(flagBytes, CONSTANT_MAGIC_FLAG) || !Arrays.equals(versionBytes, VERSION)) { - String errorMsg = String.format("invalid magic flag or " + - "version|flag=%s|version=%s|remoteAddress=%s", new String(flagBytes, UTF8), new String - (versionBytes, UTF8), ctx.channel().remoteAddress()); + String errorMsg = String.format("invalid magic flag or " + + + "version|flag=%s|version=%s|remoteAddress=%s", new String(flagBytes, UTF8), + new String(versionBytes, UTF8), ctx.channel().remoteAddress()); throw new Exception(errorMsg); } @@ -136,16 +141,23 @@ public void decode(ChannelHandlerContext ctx, ByteBuf in, List out) thro private static Object parseFromJson(Command cmd, String data) throws Exception { if (cmd == Command.HELLO_REQUEST || cmd == Command.RECOMMEND_REQUEST) { return ClientGlobal.jsonMapper.readValue(data, UserAgent.class); - } else if (cmd == Command.SUBSCRIBE_REQUEST || - cmd == Command.UNSUBSCRIBE_REQUEST) { + } else if (cmd == Command.SUBSCRIBE_REQUEST + || cmd == Command.UNSUBSCRIBE_REQUEST) { return ClientGlobal.jsonMapper.readValue(data, Subscription.class); - } else if (cmd == Command.REQUEST_TO_SERVER || cmd == Command.REQUEST_TO_CLIENT || cmd == Command.RESPONSE_TO_SERVER || cmd == - Command.RESPONSE_TO_CLIENT || cmd == Command.ASYNC_MESSAGE_TO_SERVER || cmd == Command.ASYNC_MESSAGE_TO_CLIENT || cmd == - Command.BROADCAST_MESSAGE_TO_SERVER || cmd == Command.BROADCAST_MESSAGE_TO_CLIENT || cmd == - Command.BROADCAST_MESSAGE_TO_CLIENT_ACK || cmd == Command.ASYNC_MESSAGE_TO_CLIENT_ACK || cmd == Command.REQUEST_TO_CLIENT_ACK + } else if (cmd == Command.REQUEST_TO_SERVER + || cmd == Command.REQUEST_TO_CLIENT + || cmd == Command.RESPONSE_TO_SERVER + || cmd == Command.RESPONSE_TO_CLIENT + || cmd == Command.ASYNC_MESSAGE_TO_SERVER + || cmd == Command.ASYNC_MESSAGE_TO_CLIENT + || cmd == Command.BROADCAST_MESSAGE_TO_SERVER + || cmd == Command.BROADCAST_MESSAGE_TO_CLIENT + || cmd == Command.BROADCAST_MESSAGE_TO_CLIENT_ACK + || cmd == Command.ASYNC_MESSAGE_TO_CLIENT_ACK + || cmd == Command.REQUEST_TO_CLIENT_ACK || cmd == Command.RESPONSE_TO_CLIENT_ACK) { return ClientGlobal.jsonMapper.readValue(data, EventMeshMessage.class); - } else if (cmd == (Command.REDIRECT_TO_CLIENT)) { + } else if (cmd == Command.REDIRECT_TO_CLIENT) { return ClientGlobal.jsonMapper.readValue(data, RedirectInfo.class); } else { return null; diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/MessageUtils.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/MessageUtils.java index 0f20828bcb..04af7d0823 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/MessageUtils.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/MessageUtils.java @@ -17,16 +17,19 @@ package org.apache.eventmesh.runtime.client.common; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ThreadLocalRandom; - -import org.apache.eventmesh.common.protocol.SubscriptionType; -import org.apache.eventmesh.common.protocol.tcp.Subscription; import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.SubscriptionMode; -import org.apache.eventmesh.common.protocol.tcp.*; +import org.apache.eventmesh.common.protocol.SubscriptionType; +import org.apache.eventmesh.common.protocol.tcp.Command; +import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; +import org.apache.eventmesh.common.protocol.tcp.Header; import org.apache.eventmesh.common.protocol.tcp.Package; +import org.apache.eventmesh.common.protocol.tcp.Subscription; +import org.apache.eventmesh.common.protocol.tcp.UserAgent; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ThreadLocalRandom; public class MessageUtils { public static int seqLength = 10; @@ -167,12 +170,13 @@ public static UserAgent generateSubServer() { } public static Subscription generateSubscription() { - Subscription subscription = new Subscription(); + List subscriptionItems = new ArrayList<>(); subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC)); subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC2", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC)); subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC3", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC)); subscriptionItems.add(new SubscriptionItem("TEST-TOPIC-TCP-SYNC4", SubscriptionMode.CLUSTERING, SubscriptionType.SYNC)); + Subscription subscription = new Subscription(); subscription.setTopicList(subscriptionItems); return subscription; } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/RequestContext.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/RequestContext.java index 5855e1fe35..63044dbe79 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/RequestContext.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/RequestContext.java @@ -17,9 +17,10 @@ package org.apache.eventmesh.runtime.client.common; +import org.apache.eventmesh.common.protocol.tcp.Package; + import java.util.concurrent.CountDownLatch; -import org.apache.eventmesh.common.protocol.tcp.Package; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,13 +76,13 @@ public void finish(Package msg) { latch.countDown(); } - public static RequestContext _context(Object key, Package request, CountDownLatch latch) throws Exception { + public static RequestContext context(Object key, Package request, CountDownLatch latch) throws Exception { RequestContext c = new RequestContext(key, request, latch); logger.info("_RequestContext|create|key=" + key); return c; } - public static Object _key(Package request) { + public static Object key(Package request) { return request.getHeader().getSeq(); } } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/TCPClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/TCPClient.java index c73376a8dc..90d728a189 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/TCPClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/TCPClient.java @@ -17,6 +17,8 @@ package org.apache.eventmesh.runtime.client.common; +import org.apache.eventmesh.common.protocol.tcp.Package; + import java.io.Closeable; import java.net.InetSocketAddress; import java.util.Random; @@ -28,6 +30,9 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import io.netty.bootstrap.Bootstrap; import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.AdaptiveRecvByteBufAllocator; @@ -43,14 +48,12 @@ import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; -import org.apache.eventmesh.common.protocol.tcp.Package; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - /** * one Client connects one ACCESS - * Provides the most basic connection, send capability, and cannot provide disconnected reconnection capability, The service is request-dependent. If the disconnection and reconnection capability is provided, it will cause business insensitivity, that is, it will not follow the business reconnection logic. + * Provides the most basic connection, send capability, and cannot provide disconnected reconnection capability, + * The service is request-dependent. If the disconnection and reconnection capability is provided, + * it will cause business insensitivity, that is, it will not follow the business reconnection logic. */ public abstract class TCPClient implements Closeable { @@ -117,17 +120,19 @@ protected Package io(Package msg, long timeout) throws Exception { send(msg); return null; } else { - Object key = RequestContext._key(msg); + Object key = RequestContext.key(msg); CountDownLatch latch = new CountDownLatch(1); - RequestContext c = RequestContext._context(key, msg, latch); + RequestContext c = RequestContext.context(key, msg, latch); if (!contexts.contains(c)) { contexts.put(key, c); } else { logger.info("duplicate key : {}", key); } send(msg); - if (!c.getLatch().await(timeout, TimeUnit.MILLISECONDS)) + if (!c.getLatch().await(timeout, TimeUnit.MILLISECONDS)) { throw new TimeoutException("operation timeout, context.key=" + c.getKey()); + } + return c.getResponse(); } } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/UserAgentUtils.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/UserAgentUtils.java index c18e8185ac..a916a91679 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/UserAgentUtils.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/common/UserAgentUtils.java @@ -17,11 +17,11 @@ package org.apache.eventmesh.runtime.client.common; -import java.util.concurrent.ThreadLocalRandom; - import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.constants.EventMeshConstants; +import java.util.concurrent.ThreadLocalRandom; + public class UserAgentUtils { public static UserAgent createPubUserAgent() { UserAgent userAgent = new UserAgent(); @@ -42,8 +42,8 @@ public static UserAgent createPubUserAgent() { public static UserAgent createUserAgent() { UserAgent userAgent = new UserAgent(); userAgent.setSubsystem("5123"); -// userAgent.setPid(UtilAll.getPid()); -// userAgent.setHost(RemotingUtil.getLocalAddress()); + //userAgent.setPid(UtilAll.getPid()); + //userAgent.setHost(RemotingUtil.getLocalAddress()); userAgent.setVersion("2.0.8"); userAgent.setUsername("username"); userAgent.setPassword("1234"); @@ -53,8 +53,8 @@ public static UserAgent createUserAgent() { public static UserAgent createSubUserAgent() { UserAgent userAgent = new UserAgent(); userAgent.setSubsystem("5243"); -// userAgent.setPid(UtilAll.getPid()); -// userAgent.setHost(RemotingUtil.getLocalAddress()); + //userAgent.setPid(UtilAll.getPid()); + //userAgent.setHost(RemotingUtil.getLocalAddress()); userAgent.setPort(8888); userAgent.setVersion("2.0.8"); userAgent.setUsername("username"); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/hook/ReceiveMsgHook.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/hook/ReceiveMsgHook.java index 31cd763ed4..a3364795dd 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/hook/ReceiveMsgHook.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/hook/ReceiveMsgHook.java @@ -17,10 +17,10 @@ package org.apache.eventmesh.runtime.client.hook; -import io.netty.channel.ChannelHandlerContext; - import org.apache.eventmesh.common.protocol.tcp.Package; +import io.netty.channel.ChannelHandlerContext; + /** * Business callback hook, which is a callback for all types of messages */ diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/EventMeshClientImpl.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/EventMeshClientImpl.java index 9d830f7912..5536c2eaf5 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/EventMeshClientImpl.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/EventMeshClientImpl.java @@ -17,11 +17,10 @@ package org.apache.eventmesh.runtime.client.impl; +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.Package; -import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.tcp.UserAgent; - import org.apache.eventmesh.runtime.client.api.EventMeshClient; import org.apache.eventmesh.runtime.client.api.PubClient; import org.apache.eventmesh.runtime.client.api.SubClient; @@ -84,13 +83,13 @@ public Package listen() throws Exception { @Override public Package justSubscribe(String topic, SubscriptionMode subscriptionMode, - SubscriptionType subscriptionType) throws Exception { + SubscriptionType subscriptionType) throws Exception { return this.subClient.justSubscribe(topic, subscriptionMode, subscriptionType); } @Override public Package justUnsubscribe(String topic, SubscriptionMode subscriptionMode, - SubscriptionType subscriptionType) throws Exception { + SubscriptionType subscriptionType) throws Exception { return this.subClient.justUnsubscribe(topic, subscriptionMode, subscriptionType); } @@ -104,33 +103,37 @@ public void registerPubBusiHandler(ReceiveMsgHook handler) throws Exception { @Override public String toString() { - return "AccessClientImpl{" + - "accessHost='" + accessHost + '\'' + - ", accessPort=" + accessPort + - ", agent=" + agent + - '}'; + return "AccessClientImpl{" + + + "accessHost='" + accessHost + '\'' + + + ", accessPort=" + accessPort + + + ", agent=" + agent + + + '}'; } @Deprecated public EventMeshClientImpl(String accessServer, String busiTag, String subSystem) { -// this.accessServer = accessServer; -// this.pubClient = new PubClientImpl(StringUtils.split(this.accessServer, ":")[0], -// Integer.parseInt(StringUtils.split(this.accessServer, ":")[1]), OldTestUserAgentFactory.createPubUserAgent -// (busiTag, subSystem)); -// this.subClient = new SubClientImpl(StringUtils.split(this.accessServer, ":")[0], -// Integer.parseInt(StringUtils.split(this.accessServer, ":")[1]), OldTestUserAgentFactory.createSubUserAgent -// (busiTag, subSystem)); - } - -// @Override -// public void sysLog() throws Exception { -// subClient.sysLog(); -// } -// -// @Override -// public void traceLog() throws Exception { -// subClient.traceLog(); -// } + //this.accessServer = accessServer; + //this.pubClient = new PubClientImpl(StringUtils.split(this.accessServer, ":")[0], + // Integer.parseInt(StringUtils.split(this.accessServer, ":")[1]), OldTestUserAgentFactory.createPubUserAgent + // (busiTag, subSystem)); + //this.subClient = new SubClientImpl(StringUtils.split(this.accessServer, ":")[0], + // Integer.parseInt(StringUtils.split(this.accessServer, ":")[1]), OldTestUserAgentFactory.createSubUserAgent + // (busiTag, subSystem)); + } + + //@Override + //public void sysLog() throws Exception { + // subClient.sysLog(); + //} + // + //@Override + //public void traceLog() throws Exception { + // subClient.traceLog(); + //} @Override public void goodbye() throws Exception { diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/PubClientImpl.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/PubClientImpl.java index 701b519e4e..f4293e79ff 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/PubClientImpl.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/PubClientImpl.java @@ -17,21 +17,10 @@ package org.apache.eventmesh.runtime.client.impl; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; - import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; import org.apache.eventmesh.common.protocol.tcp.UserAgent; -import org.junit.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import org.apache.eventmesh.runtime.client.api.PubClient; import org.apache.eventmesh.runtime.client.common.ClientConstants; import org.apache.eventmesh.runtime.client.common.MessageUtils; @@ -39,6 +28,17 @@ import org.apache.eventmesh.runtime.client.common.TCPClient; import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; + public class PubClientImpl extends TCPClient implements PubClient { private Logger publogger = LoggerFactory.getLogger(this.getClass()); @@ -90,6 +90,7 @@ public void run() { publogger.debug("PubClientImpl|{}|send heartbeat|Command={}|msg={}", clientNo, msg.getHeader().getCommand(), msg); PubClientImpl.this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); } catch (Exception e) { + //ignore } } }, ClientConstants.HEARTBEAT, ClientConstants.HEARTBEAT, TimeUnit.MILLISECONDS); @@ -192,7 +193,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Package msg) throws Excep if (cmd == Command.RESPONSE_TO_CLIENT) { Package responseToClientAck = MessageUtils.responseToClientAck(msg); send(responseToClientAck); - RequestContext context = contexts.get(RequestContext._key(msg)); + RequestContext context = contexts.get(RequestContext.key(msg)); if (context != null) { contexts.remove(context.getKey()); context.finish(msg); @@ -205,7 +206,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Package msg) throws Excep publogger.error("server goodby request: ---------------------------" + msg.toString()); close(); } else { - RequestContext context = contexts.get(RequestContext._key(msg)); + RequestContext context = contexts.get(RequestContext.key(msg)); if (context != null) { contexts.remove(context.getKey()); context.finish(msg); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java index 473a82d1fa..1d3b98c49a 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/client/impl/SubClientImpl.java @@ -17,25 +17,13 @@ package org.apache.eventmesh.runtime.client.impl; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; - -import io.netty.channel.ChannelHandler; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.SimpleChannelInboundHandler; - -import org.apache.commons.collections4.CollectionUtils; -import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.SubscriptionItem; import org.apache.eventmesh.common.protocol.SubscriptionMode; -import org.apache.eventmesh.common.protocol.tcp.*; +import org.apache.eventmesh.common.protocol.SubscriptionType; +import org.apache.eventmesh.common.protocol.tcp.Command; +import org.apache.eventmesh.common.protocol.tcp.OPStatus; import org.apache.eventmesh.common.protocol.tcp.Package; -import org.junit.Assert; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - +import org.apache.eventmesh.common.protocol.tcp.UserAgent; import org.apache.eventmesh.runtime.client.api.SubClient; import org.apache.eventmesh.runtime.client.common.ClientConstants; import org.apache.eventmesh.runtime.client.common.MessageUtils; @@ -43,6 +31,21 @@ import org.apache.eventmesh.runtime.client.common.TCPClient; import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + +import org.junit.Assert; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.netty.channel.ChannelHandler; +import io.netty.channel.ChannelHandlerContext; +import io.netty.channel.SimpleChannelInboundHandler; + public class SubClientImpl extends TCPClient implements SubClient { private static final Logger logger = LoggerFactory.getLogger(SubClientImpl.class); @@ -103,6 +106,7 @@ public void run() { logger.debug("SubClientImpl|{}|send heartbeat|Command={}|msg={}", clientNo, msg.getHeader().getCommand(), msg); SubClientImpl.this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); } catch (Exception e) { + //ignore } } }, ClientConstants.HEARTBEAT, ClientConstants.HEARTBEAT, TimeUnit.MILLISECONDS); @@ -129,19 +133,19 @@ public Package listen() throws Exception { return this.dispatcher(request, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); } -// @Override -// public void traceLog() throws Exception { -// Package msg = MessageUtils.traceLog(); -// this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); -// } + //@Override + //public void traceLog() throws Exception { + // Package msg = MessageUtils.traceLog(); + // this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); + //} -// public void sysLog() throws Exception { -// Package msg = MessageUtils.sysLog(); -// this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); -// } + //public void sysLog() throws Exception { + // Package msg = MessageUtils.sysLog(); + // this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); + //} public Package justUnsubscribe(String topic, SubscriptionMode subscriptionMode, - SubscriptionType subscriptionType) throws Exception { + SubscriptionType subscriptionType) throws Exception { subscriptionItems.remove(topic); Package msg = MessageUtils.unsubscribe(topic, subscriptionMode, subscriptionType); return this.dispatcher(msg, ClientConstants.DEFAULT_TIMEOUT_IN_MILLISECONDS); @@ -202,8 +206,8 @@ protected void channelRead0(ChannelHandlerContext ctx, Package msg) throws Excep try { Package ackMsg = MessageUtils.requestToClientAck(msg); send(ackMsg); - Package aPackage = MessageUtils.rrResponse(msg); - send(aPackage); + Package responsePKG = MessageUtils.rrResponse(msg); + send(responsePKG); } catch (Exception e) { logger.info("send rr request to client ack failed"); } @@ -226,7 +230,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Package msg) throws Excep close(); } else { //control instruction set - RequestContext context = contexts.get(RequestContext._key(msg)); + RequestContext context = contexts.get(RequestContext.key(msg)); if (context != null) { contexts.remove(context.getKey()); context.finish(msg); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/CSVFormat.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/CSVFormat.java deleted file mode 100644 index 6a9d3c594c..0000000000 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/CSVFormat.java +++ /dev/null @@ -1,107 +0,0 @@ -/* - * 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.runtime.cloudevent; - -import io.cloudevents.CloudEvent; -import io.cloudevents.SpecVersion; -import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.core.data.BytesCloudEventData; -import io.cloudevents.core.format.EventFormat; -import io.cloudevents.rw.CloudEventDataMapper; -import io.cloudevents.types.Time; - -import java.net.URI; -import java.nio.charset.StandardCharsets; -import java.time.OffsetDateTime; -import java.util.Base64; -import java.util.Collections; -import java.util.Objects; -import java.util.Set; -import java.util.regex.Pattern; - -public class CSVFormat implements EventFormat { - - public static final CSVFormat INSTANCE = new CSVFormat(); - - @Override - public byte[] serialize(CloudEvent event) { - return String.join( - ",", - event.getSpecVersion().toString(), - event.getId(), - event.getType(), - event.getSource().toString(), - Objects.toString(event.getDataContentType()), - Objects.toString(event.getDataSchema()), - Objects.toString(event.getSubject()), - event.getTime() != null - ? Time.writeTime(event.getTime()) - : "null", - event.getData() != null - ? new String(Base64.getEncoder().encode(event.getData().toBytes()), StandardCharsets.UTF_8) - : "null" - ).getBytes(); - } - - @Override - public CloudEvent deserialize(byte[] bytes, CloudEventDataMapper mapper) { - String[] splitted = new String(bytes, StandardCharsets.UTF_8).split(Pattern.quote(",")); - SpecVersion sv = SpecVersion.parse(splitted[0]); - - String id = splitted[1]; - String type = splitted[2]; - URI source = URI.create(splitted[3]); - String datacontenttype = splitted[4].equals("null") ? null : splitted[4]; - URI dataschema = splitted[5].equals("null") ? null : URI.create(splitted[5]); - String subject = splitted[6].equals("null") ? null : splitted[6]; - OffsetDateTime time = splitted[7].equals("null") ? null : Time.parseTime(splitted[7]); - byte[] data = splitted[8].equals("null") ? null : Base64.getDecoder().decode(splitted[8].getBytes()); - - CloudEventBuilder builder = CloudEventBuilder.fromSpecVersion(sv) - .withId(id) - .withType(type) - .withSource(source); - - if (datacontenttype != null) { - builder.withDataContentType(datacontenttype); - } - if (dataschema != null) { - builder.withDataSchema(dataschema); - } - if (subject != null) { - builder.withSubject(subject); - } - if (time != null) { - builder.withTime(time); - } - if (data != null) { - builder.withData(mapper.map(BytesCloudEventData.wrap(data))); - } - return builder.build(); - } - - @Override - public Set deserializableContentTypes() { - return Collections.singleton(serializedContentType()); - } - - @Override - public String serializedContentType() { - return "application/cloudevents+csv"; - } -} diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/Data.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/Data.java deleted file mode 100644 index 001aa196b6..0000000000 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/Data.java +++ /dev/null @@ -1,197 +0,0 @@ -/* - * 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.runtime.cloudevent; - -import io.cloudevents.CloudEvent; -import io.cloudevents.core.builder.CloudEventBuilder; -import io.cloudevents.types.Time; - -import java.math.BigDecimal; -import java.net.URI; -import java.time.OffsetDateTime; -import java.util.Objects; -import java.util.stream.Stream; - -public class Data { - - public static final String ID = "1"; - public static final String TYPE = "mock.test"; - public static final URI SOURCE = URI.create("http://localhost/source"); - public static final String DATACONTENTTYPE_JSON = "application/json"; - public static final String DATACONTENTTYPE_XML = "application/xml"; - public static final String DATACONTENTTYPE_TEXT = "text/plain"; - public static final URI DATASCHEMA = URI.create("http://localhost/schema"); - public static final String SUBJECT = "sub"; - public static final OffsetDateTime TIME = Time.parseTime("2018-04-26T14:48:09+02:00"); - - protected static final byte[] DATA_JSON_SERIALIZED = "{}".getBytes(); - protected static final byte[] DATA_XML_SERIALIZED = "".getBytes(); - protected static final byte[] DATA_TEXT_SERIALIZED = "Hello World Lorena!".getBytes(); - protected static final byte[] BINARY_VALUE = { (byte) 0xE0, (byte) 0xFF, (byte) 0x00, (byte) 0x44, (byte) 0xAA }; // Base64: 4P8ARKo= - - protected static final CloudEvent V1_MIN = CloudEventBuilder.v1() - .withId(ID) - .withType(TYPE) - .withSource(SOURCE) - .build(); - - public static final CloudEvent V1_WITH_JSON_DATA = CloudEventBuilder.v1() - .withId(ID) - .withType(TYPE) - .withSource(SOURCE) - .withData(DATACONTENTTYPE_JSON, DATASCHEMA, DATA_JSON_SERIALIZED) - .withSubject(SUBJECT) - .withTime(TIME) - .build(); - - public static final CloudEvent V1_WITH_JSON_DATA_WITH_FRACTIONAL_TIME = CloudEventBuilder.v1() - .withId(ID) - .withType(TYPE) - .withSource(SOURCE) - .withData(DATACONTENTTYPE_JSON, DATASCHEMA, DATA_JSON_SERIALIZED) - .withSubject(SUBJECT) - .withTime(Time.parseTime("2018-04-26T14:48:09.1234Z")) - .build(); - - public static final CloudEvent V1_WITH_JSON_DATA_WITH_EXT = CloudEventBuilder.v1() - .withId(ID) - .withType(TYPE) - .withSource(SOURCE) - .withData(DATACONTENTTYPE_JSON, DATASCHEMA, DATA_JSON_SERIALIZED) - .withSubject(SUBJECT) - .withTime(TIME) - .withExtension("astring", "aaa") - .withExtension("aboolean", true) - .withExtension("anumber", 10) - .build(); - - public static final CloudEvent V1_WITH_JSON_DATA_WITH_EXT_STRING = CloudEventBuilder.v1() - .withId(ID) - .withType(TYPE) - .withSource(SOURCE) - .withData(DATACONTENTTYPE_JSON, DATASCHEMA, DATA_JSON_SERIALIZED) - .withSubject(SUBJECT) - .withTime(TIME) - .withExtension("astring", "aaa") - .withExtension("aboolean", "true") - .withExtension("anumber", "10") - .build(); - - public static final CloudEvent V1_WITH_XML_DATA = CloudEventBuilder.v1() - .withId(ID) - .withType(TYPE) - .withSource(SOURCE) - .withData(DATACONTENTTYPE_XML, DATA_XML_SERIALIZED) - .withSubject(SUBJECT) - .withTime(TIME) - .build(); - - public static final CloudEvent V1_WITH_TEXT_DATA = CloudEventBuilder.v1() - .withId(ID) - .withType(TYPE) - .withSource(SOURCE) - .withData(DATACONTENTTYPE_TEXT, DATA_TEXT_SERIALIZED) - .withSubject(SUBJECT) - .withTime(TIME) - .build(); - - public static final CloudEvent V1_WITH_BINARY_EXT = CloudEventBuilder.v1() - .withId(ID) - .withType(TYPE) - .withSource(SOURCE) - .withExtension("binary", BINARY_VALUE) - .build(); - - public static final CloudEvent V1_WITH_NUMERIC_EXT = CloudEventBuilder.v1() - .withId(ID) - .withType(TYPE) - .withSource(SOURCE) - .withExtension("integer", 42) - .withExtension("decimal", new BigDecimal("42.42")) - .withExtension("float", 4.2f) - .withExtension("long", new Long(4200)) - .build(); - - public static final CloudEvent V03_MIN = CloudEventBuilder.v03(V1_MIN).build(); - public static final CloudEvent V03_WITH_JSON_DATA = CloudEventBuilder.v03(V1_WITH_JSON_DATA).build(); - public static final CloudEvent V03_WITH_JSON_DATA_WITH_EXT = CloudEventBuilder.v03(V1_WITH_JSON_DATA_WITH_EXT).build(); - public static final CloudEvent V03_WITH_JSON_DATA_WITH_EXT_STRING = CloudEventBuilder.v03(V1_WITH_JSON_DATA_WITH_EXT_STRING).build(); - public static final CloudEvent V03_WITH_XML_DATA = CloudEventBuilder.v03(V1_WITH_XML_DATA).build(); - public static final CloudEvent V03_WITH_TEXT_DATA = CloudEventBuilder.v03(V1_WITH_TEXT_DATA).build(); - - public static Stream allEvents() { - return Stream.concat(v1Events(), v03Events()); - } - - public static Stream allEventsWithoutExtensions() { - return Stream.concat(v1Events(), v03Events()).filter(e -> e.getExtensionNames().isEmpty()); - } - - public static Stream allEventsWithStringExtensions() { - return Stream.concat(v1EventsWithStringExt(), v03EventsWithStringExt()); - } - - public static Stream v1Events() { - return Stream.of( - Data.V1_MIN, - Data.V1_WITH_JSON_DATA, - Data.V1_WITH_JSON_DATA_WITH_EXT, - Data.V1_WITH_XML_DATA, - Data.V1_WITH_TEXT_DATA - ); - } - - /** - * Due to the nature of CE there are scenarios where an event might be serialized - * in such a fashion that it can not be deserialized while retaining the orginal - * type information, this varies from format-2-format - */ - - public static Stream v1NonRoundTripEvents() { - return Stream.of( - Data.V1_WITH_BINARY_EXT - ); - } - - public static Stream v03Events() { - return Stream.of( - Data.V03_MIN, - Data.V03_WITH_JSON_DATA, - Data.V03_WITH_JSON_DATA_WITH_EXT, - Data.V03_WITH_XML_DATA, - Data.V03_WITH_TEXT_DATA - ); - } - - public static Stream v1EventsWithStringExt() { - return v1Events().map(ce -> { - io.cloudevents.core.v1.CloudEventBuilder builder = CloudEventBuilder.v1(ce); - ce.getExtensionNames().forEach(k -> builder.withExtension(k, Objects.toString(ce.getExtension(k)))); - return builder.build(); - }); - } - - public static Stream v03EventsWithStringExt() { - return v03Events().map(ce -> { - io.cloudevents.core.v03.CloudEventBuilder builder = CloudEventBuilder.v03(ce); - ce.getExtensionNames().forEach(k -> builder.withExtension(k, Objects.toString(ce.getExtension(k)))); - return builder.build(); - }); - } - -} diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/OMSFactoryTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/OMSFactoryTest.java deleted file mode 100644 index 583262edbb..0000000000 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/OMSFactoryTest.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * 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.runtime.cloudevent; - - -import io.cloudevents.CloudEvent; -import io.cloudevents.SpecVersion; -import io.cloudevents.core.message.Encoding; -import io.cloudevents.core.message.MessageReader; -import io.cloudevents.core.provider.EventFormatProvider; -import io.cloudevents.core.v03.CloudEventV03; -import io.cloudevents.core.v1.CloudEventV1; -import io.cloudevents.types.Time; -import org.apache.eventmesh.runtime.core.protocol.cloudevent.OMSMessageFactory; -import org.apache.eventmesh.runtime.core.protocol.cloudevent.impl.OMSHeaders; -import org.junit.Test; - -import java.util.AbstractMap; -import java.util.Map; -import java.util.Properties; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; - -public class OMSFactoryTest { - - private static final String PREFIX_TEMPLATE = OMSHeaders.CE_PREFIX + "%s"; - private static final String DATACONTENTTYPE_NULL = null; - private static final byte[] DATAPAYLOAD_NULL = null; - - @Test - public void readBinary() { - Stream argumentsStream=binaryTestArguments(); - argumentsStream.forEach(argument -> { - if (argument.contentType != null) { - argument.props.put(OMSHeaders.CONTENT_TYPE, argument.contentType); - } - Properties properties = new Properties(); - properties.putAll(argument.props); - final MessageReader reader = OMSMessageFactory.createReader(properties, argument.body); - assertThat(reader.getEncoding()).isEqualTo(Encoding.BINARY); - assertThat(reader.toEvent()).isEqualTo(argument.event); - - }); - - } - - @Test - public void readStructured() { - Stream cloudEventStream= Data.allEventsWithoutExtensions(); - EventFormatProvider.getInstance().registerFormat(CSVFormat.INSTANCE); - cloudEventStream.forEach(event -> { - final String contentType = CSVFormat.INSTANCE.serializedContentType() + "; charset=utf8"; - final byte[] contentPayload = CSVFormat.INSTANCE.serialize(event); - Properties properties = new Properties(); - properties.put(OMSHeaders.CONTENT_TYPE, contentType); - final MessageReader reader = OMSMessageFactory.createReader(properties, contentPayload); - assertThat(reader.getEncoding()).isEqualTo(Encoding.STRUCTURED); - assertThat(reader.toEvent()).isEqualTo(event); - }); - } - - private Stream binaryTestArguments() { - - return Stream.of( - // V03 - new Arguments( - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property("ignored", "ignore") - ), - DATACONTENTTYPE_NULL, - DATAPAYLOAD_NULL, - Data.V03_MIN - ), - new Arguments( - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property(CloudEventV03.SCHEMAURL, Data.DATASCHEMA.toString()), - property(CloudEventV03.SUBJECT, Data.SUBJECT), - property(CloudEventV03.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignore") - ), - Data.DATACONTENTTYPE_JSON, - Data.DATA_JSON_SERIALIZED, - Data.V03_WITH_JSON_DATA - ), - new Arguments( - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property(CloudEventV03.SCHEMAURL, Data.DATASCHEMA.toString()), - property(CloudEventV03.SUBJECT, Data.SUBJECT), - property(CloudEventV03.TIME, Time.writeTime(Data.TIME)), - property("astring", "aaa"), - property("aboolean", "true"), - property("anumber", "10"), - property("ignored", "ignored") - ), - Data.DATACONTENTTYPE_JSON, - Data.DATA_JSON_SERIALIZED, - Data.V03_WITH_JSON_DATA_WITH_EXT_STRING - ), - new Arguments( - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property(CloudEventV03.SUBJECT, Data.SUBJECT), - property(CloudEventV03.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - Data.DATACONTENTTYPE_XML, - Data.DATA_XML_SERIALIZED, - Data.V03_WITH_XML_DATA - ), - new Arguments( - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property(CloudEventV03.SUBJECT, Data.SUBJECT), - property(CloudEventV03.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - Data.DATACONTENTTYPE_TEXT, - Data.DATA_TEXT_SERIALIZED, - Data.V03_WITH_TEXT_DATA - ), - // V1 - new Arguments( - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property("ignored", "ignored") - ), - DATACONTENTTYPE_NULL, - DATAPAYLOAD_NULL, - Data.V1_MIN - ), - new Arguments( - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property(CloudEventV1.DATASCHEMA, Data.DATASCHEMA.toString()), - property(CloudEventV1.SUBJECT, Data.SUBJECT), - property(CloudEventV1.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - Data.DATACONTENTTYPE_JSON, - Data.DATA_JSON_SERIALIZED, - Data.V1_WITH_JSON_DATA - ), - new Arguments( - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property(CloudEventV1.DATASCHEMA, Data.DATASCHEMA.toString()), - property(CloudEventV1.SUBJECT, Data.SUBJECT), - property(CloudEventV1.TIME, Time.writeTime(Data.TIME)), - property("astring", "aaa"), - property("aboolean", "true"), - property("anumber", "10"), - property("ignored", "ignored") - ), - Data.DATACONTENTTYPE_JSON, - Data.DATA_JSON_SERIALIZED, - Data.V1_WITH_JSON_DATA_WITH_EXT_STRING - ), - new Arguments( - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property(CloudEventV1.SUBJECT, Data.SUBJECT), - property(CloudEventV1.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - Data.DATACONTENTTYPE_XML, - Data.DATA_XML_SERIALIZED, - Data.V1_WITH_XML_DATA - ), - new Arguments( - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property(CloudEventV1.SUBJECT, Data.SUBJECT), - property(CloudEventV1.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - Data.DATACONTENTTYPE_TEXT, - Data.DATA_TEXT_SERIALIZED, - Data.V1_WITH_TEXT_DATA - ) - ); - } - - private static final AbstractMap.SimpleEntry property(final String name, final String value) { - return name.equalsIgnoreCase("ignored") ? - new AbstractMap.SimpleEntry<>(name, value) : - new AbstractMap.SimpleEntry<>(String.format(PREFIX_TEMPLATE, name), value); - } - - @SafeVarargs - private static final Map properties(final AbstractMap.SimpleEntry... entries) { - return Stream.of(entries) - .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); - - } - - - private class Arguments { - private Map props; - private String contentType; - private byte[] body; - private CloudEvent event; - - public Arguments(Map props, String contentType, byte[] body, CloudEvent event) { - this.props = props; - this.contentType = contentType; - this.body = body; - this.event = event; - } - } -} diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/OMSWriterTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/OMSWriterTest.java deleted file mode 100644 index 834f156d68..0000000000 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/cloudevent/OMSWriterTest.java +++ /dev/null @@ -1,287 +0,0 @@ -/* - * 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.runtime.cloudevent; - -import io.cloudevents.CloudEvent; -import io.cloudevents.SpecVersion; -import io.cloudevents.core.message.StructuredMessageReader; -import io.cloudevents.core.v03.CloudEventV03; -import io.cloudevents.core.v1.CloudEventV1; -import io.cloudevents.types.Time; -import io.openmessaging.api.Message; -import org.apache.eventmesh.runtime.core.protocol.cloudevent.OMSMessageFactory; -import org.apache.eventmesh.runtime.core.protocol.cloudevent.impl.OMSHeaders; -import org.junit.Test; - -import java.util.AbstractMap; -import java.util.Map; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -import static org.assertj.core.api.Assertions.assertThat; - -public class OMSWriterTest { - - private static final String PREFIX_TEMPLATE = OMSHeaders.CE_PREFIX + "%s"; - private static final String DATACONTENTTYPE_NULL = null; - private static final byte[] DATAPAYLOAD_NULL = null; - - - @Test - public void testRequestWithStructured() { - Stream cloudEventStream = Data.allEventsWithoutExtensions(); - //String expectedContentType = CSVFormat.INSTANCE.serializedContentType(); - cloudEventStream.forEach(event -> { - byte[] expectedBuffer = CSVFormat.INSTANCE.serialize(event); - - String topic = "test"; - String keys = "keys"; - String tags = "tags"; - - Message message = StructuredMessageReader - .from(event, CSVFormat.INSTANCE) - .read(OMSMessageFactory.createWriter(topic, keys, tags)); - - assertThat(message.getTopic()) - .isEqualTo(topic); - assertThat(message.getKey()) - .isEqualTo(keys); - assertThat(message.getTag()) - .isEqualTo(tags); - assertThat(message.getBody()) - .isEqualTo(expectedBuffer); - }); - - } - - @Test - public void testRequestWithBinary() { - Stream argumentsStream = binaryTestArguments(); - String topic = "test"; - String keys = "keys"; - String tags = "tags"; - argumentsStream.forEach(argument -> { - Message message = OMSMessageFactory - .createWriter(topic, keys, tags) - .writeBinary(argument.cloudEvent); - - assertThat(message.getTopic()) - .isEqualTo(topic); - assertThat(message.getKey()) - .isEqualTo(keys); - assertThat(message.getTag()) - .isEqualTo(tags); - assertThat(message.getBody()) - .isEqualTo(argument.body); - assertThat(message.getUserProperties() - .keySet().containsAll(argument.properties.keySet())); - assertThat(message.getUserProperties() - .values().containsAll(argument.properties.values())); - - - }); - - } - - private Stream binaryTestArguments() { - - return Stream.of( - // V03 - new Arguments( - Data.V03_MIN, - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property("ignored", "ignore") - ), - DATAPAYLOAD_NULL - ), - new Arguments( - Data.V03_WITH_JSON_DATA, - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property(CloudEventV03.SCHEMAURL, Data.DATASCHEMA.toString()), - property(CloudEventV03.SUBJECT, Data.SUBJECT), - property(CloudEventV03.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignore") - ), - Data.DATA_JSON_SERIALIZED - - ), - new Arguments( - Data.V03_WITH_JSON_DATA_WITH_EXT_STRING, - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property(CloudEventV03.SCHEMAURL, Data.DATASCHEMA.toString()), - property(CloudEventV03.SUBJECT, Data.SUBJECT), - property(CloudEventV03.TIME, Time.writeTime(Data.TIME)), - property("astring", "aaa"), - property("aboolean", "true"), - property("anumber", "10"), - property("ignored", "ignored") - ), - Data.DATA_JSON_SERIALIZED - - ), - new Arguments( - Data.V03_WITH_XML_DATA, - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property(CloudEventV03.SUBJECT, Data.SUBJECT), - property(CloudEventV03.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - - Data.DATA_XML_SERIALIZED - - ), - new Arguments( - Data.V03_WITH_TEXT_DATA, - properties( - property(CloudEventV03.SPECVERSION, SpecVersion.V03.toString()), - property(CloudEventV03.ID, Data.ID), - property(CloudEventV03.TYPE, Data.TYPE), - property(CloudEventV03.SOURCE, Data.SOURCE.toString()), - property(CloudEventV03.SUBJECT, Data.SUBJECT), - property(CloudEventV03.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - - Data.DATA_TEXT_SERIALIZED - - ), - // V1 - new Arguments( - Data.V1_MIN, - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property("ignored", "ignored") - ), - - DATAPAYLOAD_NULL - - ), - new Arguments( - Data.V1_WITH_JSON_DATA, - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property(CloudEventV1.DATASCHEMA, Data.DATASCHEMA.toString()), - property(CloudEventV1.SUBJECT, Data.SUBJECT), - property(CloudEventV1.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - - Data.DATA_JSON_SERIALIZED - - ), - new Arguments( - Data.V1_WITH_JSON_DATA_WITH_EXT_STRING, - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property(CloudEventV1.DATASCHEMA, Data.DATASCHEMA.toString()), - property(CloudEventV1.SUBJECT, Data.SUBJECT), - property(CloudEventV1.TIME, Time.writeTime(Data.TIME)), - property("astring", "aaa"), - property("aboolean", "true"), - property("anumber", "10"), - property("ignored", "ignored") - ), - - Data.DATA_JSON_SERIALIZED - - ), - new Arguments( - Data.V1_WITH_XML_DATA, - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property(CloudEventV1.SUBJECT, Data.SUBJECT), - property(CloudEventV1.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - - Data.DATA_XML_SERIALIZED - - ), - new Arguments( - Data.V1_WITH_TEXT_DATA, - properties( - property(CloudEventV1.SPECVERSION, SpecVersion.V1.toString()), - property(CloudEventV1.ID, Data.ID), - property(CloudEventV1.TYPE, Data.TYPE), - property(CloudEventV1.SOURCE, Data.SOURCE.toString()), - property(CloudEventV1.SUBJECT, Data.SUBJECT), - property(CloudEventV1.TIME, Time.writeTime(Data.TIME)), - property("ignored", "ignored") - ), - - Data.DATA_TEXT_SERIALIZED - - ) - ); - } - - private static final AbstractMap.SimpleEntry property(final String name, final String value) { - return name.equalsIgnoreCase("ignored") ? - new AbstractMap.SimpleEntry<>(name, value) : - new AbstractMap.SimpleEntry<>(String.format(PREFIX_TEMPLATE, name), value); - } - - @SafeVarargs - private static final Map properties(final AbstractMap.SimpleEntry... entries) { - return Stream.of(entries) - .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); - - } - - private class Arguments { - CloudEvent cloudEvent; - Map properties; - byte[] body; - - public Arguments(CloudEvent cloudEvent, Map properties, byte[] body) { - this.cloudEvent = cloudEvent; - this.properties = properties; - this.body = body; - } - - - } -} diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/AsyncPubClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/AsyncPubClient.java index 14ee1ddbc7..a2dd1d904d 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/AsyncPubClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/AsyncPubClient.java @@ -17,19 +17,19 @@ package org.apache.eventmesh.runtime.demo; -import io.netty.channel.ChannelHandlerContext; - -import org.apache.eventmesh.common.utils.ThreadUtils; import org.apache.eventmesh.common.protocol.tcp.Package; - +import org.apache.eventmesh.common.utils.ThreadUtils; import org.apache.eventmesh.runtime.client.common.ClientConstants; import org.apache.eventmesh.runtime.client.common.MessageUtils; import org.apache.eventmesh.runtime.client.common.UserAgentUtils; import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; import org.apache.eventmesh.runtime.client.impl.PubClientImpl; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public class AsyncPubClient { private static final Logger logger = LoggerFactory.getLogger(AsyncPubClient.class); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/AsyncSubClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/AsyncSubClient.java index c634d35eeb..2783e136ed 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/AsyncSubClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/AsyncSubClient.java @@ -17,20 +17,20 @@ package org.apache.eventmesh.runtime.demo; -import io.netty.channel.ChannelHandlerContext; - +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; - import org.apache.eventmesh.runtime.client.common.ClientConstants; import org.apache.eventmesh.runtime.client.common.MessageUtils; import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; import org.apache.eventmesh.runtime.client.impl.SubClientImpl; -import org.apache.eventmesh.common.protocol.SubscriptionMode; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public class AsyncSubClient { private static final Logger logger = LoggerFactory.getLogger(AsyncSubClient.class); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/BroadCastPubClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/BroadCastPubClient.java index d85e8c364f..5f3fa158bd 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/BroadCastPubClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/BroadCastPubClient.java @@ -18,7 +18,6 @@ package org.apache.eventmesh.runtime.demo; import org.apache.eventmesh.common.utils.ThreadUtils; - import org.apache.eventmesh.runtime.client.common.ClientConstants; import org.apache.eventmesh.runtime.client.common.MessageUtils; import org.apache.eventmesh.runtime.client.common.UserAgentUtils; diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/BroadCastSubClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/BroadCastSubClient.java index a61c562214..8e00541dc0 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/BroadCastSubClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/BroadCastSubClient.java @@ -17,21 +17,21 @@ package org.apache.eventmesh.runtime.demo; -import io.netty.channel.ChannelHandlerContext; - +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; - import org.apache.eventmesh.runtime.client.common.ClientConstants; import org.apache.eventmesh.runtime.client.common.MessageUtils; import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; import org.apache.eventmesh.runtime.client.impl.SubClientImpl; -import org.apache.eventmesh.common.protocol.SubscriptionMode; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public class BroadCastSubClient { private static final Logger logger = LoggerFactory.getLogger(BroadCastSubClient.class); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/CCSubClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/CCSubClient.java index bb96c1db83..9e60011fa5 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/CCSubClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/CCSubClient.java @@ -17,20 +17,20 @@ package org.apache.eventmesh.runtime.demo; -import io.netty.channel.ChannelHandlerContext; - +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.Package; - import org.apache.eventmesh.runtime.client.common.MessageUtils; import org.apache.eventmesh.runtime.client.common.UserAgentUtils; import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; import org.apache.eventmesh.runtime.client.impl.SubClientImpl; -import org.apache.eventmesh.common.protocol.SubscriptionMode; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public class CCSubClient { private static final Logger logger = LoggerFactory.getLogger(CCSubClient.class); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/CClientDemo.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/CClientDemo.java index cad2c5018b..9ebaf74f2b 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/CClientDemo.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/CClientDemo.java @@ -17,19 +17,19 @@ package org.apache.eventmesh.runtime.demo; -import io.netty.channel.ChannelHandlerContext; - +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.Package; -import org.apache.eventmesh.common.protocol.SubscriptionMode; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import org.apache.eventmesh.runtime.client.common.MessageUtils; import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; import org.apache.eventmesh.runtime.client.impl.EventMeshClientImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import io.netty.channel.ChannelHandlerContext; + /** * simple client usage example */ @@ -48,18 +48,18 @@ public static void main(String[] args) throws Exception { client.justSubscribe(ASYNC_TOPIC, SubscriptionMode.CLUSTERING, SubscriptionType.ASYNC); client.justSubscribe(BROADCAST_TOPIC, SubscriptionMode.BROADCASTING, SubscriptionType.ASYNC); client.listen(); -// for (int i = 0; i < 10000; i++) { -// Package rr = null; -// AccessMessage rrMessage = null; -// try { -// rr = client.rr(MessageUtils.rrMesssage("TEST-TOPIC-TCP-SYNC"), 3000); -// Thread.sleep(100); -// //rrMessage = (AccessMessage) rr.getBody(); -// logger.error( "rr-reply-------------------------------------------------" + rr.toString()); -// } catch (Exception e) { -// e.printStackTrace(); -// } -// } + //for (int i = 0; i < 10000; i++) { + // Package rr = null; + // AccessMessage rrMessage = null; + // try { + // rr = client.rr(MessageUtils.rrMesssage("TEST-TOPIC-TCP-SYNC"), 3000); + // Thread.sleep(100); + // //rrMessage = (AccessMessage) rr.getBody(); + // logger.error( "rr-reply-------------------------------------------------" + rr.toString()); + // } catch (Exception e) { + // e.printStackTrace(); + // } + //} client.registerSubBusiHandler(new ReceiveMsgHook() { @Override public void handle(Package msg, ChannelHandlerContext ctx) { @@ -69,15 +69,15 @@ public void handle(Package msg, ChannelHandlerContext ctx) { } }); for (int i = 0; i < 10000; i++) { -// ThreadUtil.randomSleep(0,200); + //ThreadUtil.randomSleep(0,200); //broadcast message client.broadcast(MessageUtils.broadcastMessage("TEST-TOPIC-TCP-BROADCAST", i), 5000); //asynchronous message client.publish(MessageUtils.asyncMessage(ASYNC_TOPIC, i), 5000); } -// -// Thread.sleep(10000); -// client.close(); + // + //Thread.sleep(10000); + //client.close(); } diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/SyncPubClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/SyncPubClient.java index 9694620e79..6375a3b2d5 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/SyncPubClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/SyncPubClient.java @@ -19,10 +19,10 @@ import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; import org.apache.eventmesh.common.protocol.tcp.Package; - import org.apache.eventmesh.runtime.client.common.MessageUtils; import org.apache.eventmesh.runtime.client.common.UserAgentUtils; import org.apache.eventmesh.runtime.client.impl.PubClientImpl; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/SyncSubClient.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/SyncSubClient.java index 6921f3dd20..3e3ed201a0 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/SyncSubClient.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/demo/SyncSubClient.java @@ -17,20 +17,20 @@ package org.apache.eventmesh.runtime.demo; -import io.netty.channel.ChannelHandlerContext; - +import org.apache.eventmesh.common.protocol.SubscriptionMode; import org.apache.eventmesh.common.protocol.SubscriptionType; import org.apache.eventmesh.common.protocol.tcp.Command; import org.apache.eventmesh.common.protocol.tcp.Package; - import org.apache.eventmesh.runtime.client.common.ClientConstants; import org.apache.eventmesh.runtime.client.common.MessageUtils; import org.apache.eventmesh.runtime.client.hook.ReceiveMsgHook; import org.apache.eventmesh.runtime.client.impl.SubClientImpl; -import org.apache.eventmesh.common.protocol.SubscriptionMode; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import io.netty.channel.ChannelHandlerContext; + public class SyncSubClient { private static final Logger logger = LoggerFactory.getLogger(SyncSubClient.class); diff --git a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/EventMeshUtilTest.java b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/EventMeshUtilTest.java index 6f55615d3a..e9c4928c1c 100644 --- a/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/EventMeshUtilTest.java +++ b/eventmesh-runtime/src/test/java/org/apache/eventmesh/runtime/util/EventMeshUtilTest.java @@ -17,11 +17,11 @@ package org.apache.eventmesh.runtime.util; +import java.util.regex.Pattern; + import org.junit.Assert; import org.junit.Test; -import java.util.regex.Pattern; - public class EventMeshUtilTest { @Test diff --git a/eventmesh-runtime/src/test/resources/log4j2.xml b/eventmesh-runtime/src/test/resources/log4j2.xml index c429b4e8e2..da0a6059fa 100644 --- a/eventmesh-runtime/src/test/resources/log4j2.xml +++ b/eventmesh-runtime/src/test/resources/log4j2.xml @@ -28,15 +28,18 @@ - + - + - + diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractHttpClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractHttpClient.java index bb415248a4..463968cb45 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractHttpClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/AbstractHttpClient.java @@ -53,7 +53,7 @@ public AbstractHttpClient(EventMeshHttpClientConfig eventMeshHttpClientConfig) t this.eventMeshHttpClientConfig = eventMeshHttpClientConfig; this.eventMeshServerSelector = HttpLoadBalanceUtils.createEventMeshServerLoadBalanceSelector( - eventMeshHttpClientConfig); + eventMeshHttpClientConfig); this.httpClient = setHttpClient(); } @@ -73,14 +73,14 @@ private CloseableHttpClient setHttpClient() throws EventMeshException { try { // todo: config in properties file? String protocol = System.getProperty("ssl.client.protocol", "TLSv1.2"); - TrustManager[] tm = new TrustManager[] {new MyX509TrustManager()}; + TrustManager[] tm = new TrustManager[]{new MyX509TrustManager()}; sslContext = SSLContext.getInstance(protocol); sslContext.init(null, tm, new SecureRandom()); // todo: custom client pool return HttpClients.custom() - .setSSLContext(sslContext) - .setSSLHostnameVerifier(new DefaultHostnameVerifier()) - .build(); + .setSSLContext(sslContext) + .setSSLHostnameVerifier(new DefaultHostnameVerifier()) + .build(); } catch (Exception e) { log.error("Error in creating HttpClient.", e); throw new EventMeshException(e); diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java index 00c544a261..a891bdf177 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/EventMeshHttpConsumer.java @@ -46,10 +46,11 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import io.netty.handler.codec.http.HttpMethod; + import com.google.common.base.Preconditions; import com.google.common.util.concurrent.ThreadFactoryBuilder; -import io.netty.handler.codec.http.HttpMethod; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -66,15 +67,15 @@ public EventMeshHttpConsumer(EventMeshHttpClientConfig eventMeshHttpClientConfig } public EventMeshHttpConsumer(EventMeshHttpClientConfig eventMeshHttpClientConfig, ThreadPoolExecutor customExecutor) - throws EventMeshException { + throws EventMeshException { super(eventMeshHttpClientConfig); this.consumeExecutor = Optional.ofNullable(customExecutor).orElseGet( - () -> ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpClientConfig.getConsumeThreadCore(), - eventMeshHttpClientConfig.getConsumeThreadMax(), "EventMesh-client-consume-") + () -> ThreadPoolFactory.createThreadPoolExecutor(eventMeshHttpClientConfig.getConsumeThreadCore(), + eventMeshHttpClientConfig.getConsumeThreadMax(), "EventMesh-client-consume-") ); this.scheduler = new ScheduledThreadPoolExecutor( - Runtime.getRuntime().availableProcessors(), - new ThreadFactoryBuilder().setNameFormat("HTTPClientScheduler").setDaemon(true).build() + Runtime.getRuntime().availableProcessors(), + new ThreadFactoryBuilder().setNameFormat("HTTPClientScheduler").setDaemon(true).build() ); } @@ -89,10 +90,10 @@ public void subscribe(List topicList, String subscribeUrl) thr Preconditions.checkNotNull(topicList, "Subscribe item cannot be null"); Preconditions.checkNotNull(subscribeUrl, "SubscribeUrl cannot be null"); RequestParam subscribeParam = buildCommonRequestParam() - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.SUBSCRIBE.getRequestCode()) - .addBody(SubscribeRequestBody.TOPIC, JsonUtils.serialize(topicList)) - .addBody(SubscribeRequestBody.CONSUMERGROUP, eventMeshHttpClientConfig.getConsumerGroup()) - .addBody(SubscribeRequestBody.URL, subscribeUrl); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.SUBSCRIBE.getRequestCode()) + .addBody(SubscribeRequestBody.TOPIC, JsonUtils.serialize(topicList)) + .addBody(SubscribeRequestBody.CONSUMERGROUP, eventMeshHttpClientConfig.getConsumerGroup()) + .addBody(SubscribeRequestBody.URL, subscribeUrl); String target = selectEventMesh(); try { @@ -114,16 +115,16 @@ public void heartBeat(List topicList, String subscribeUrl) { scheduler.scheduleAtFixedRate(() -> { try { List heartbeatEntities = topicList.stream().map(subscriptionItem - -> { + -> { HeartbeatRequestBody.HeartbeatEntity heartbeatEntity = new HeartbeatRequestBody.HeartbeatEntity(); heartbeatEntity.topic = subscriptionItem.getTopic(); heartbeatEntity.url = subscribeUrl; return heartbeatEntity; }).collect(Collectors.toList()); RequestParam requestParam = buildCommonRequestParam() - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.HEARTBEAT.getRequestCode()) - .addBody(HeartbeatRequestBody.CLIENTTYPE, ClientType.SUB.name()) - .addBody(HeartbeatRequestBody.HEARTBEATENTITIES, JsonUtils.serialize(heartbeatEntities)); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.HEARTBEAT.getRequestCode()) + .addBody(HeartbeatRequestBody.CLIENTTYPE, ClientType.SUB.name()) + .addBody(HeartbeatRequestBody.HEARTBEATENTITIES, JsonUtils.serialize(heartbeatEntities)); String target = selectEventMesh(); String res = HttpUtils.post(httpClient, target, requestParam); EventMeshRetObj ret = JsonUtils.deserialize(res, EventMeshRetObj.class); @@ -145,9 +146,9 @@ public void unsubscribe(List topicList, String unSubscribeUrl) throws Ev Preconditions.checkNotNull(topicList, "Topics cannot be null"); Preconditions.checkNotNull(unSubscribeUrl, "unSubscribeUrl cannot be null"); RequestParam unSubscribeParam = buildCommonRequestParam() - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.UNSUBSCRIBE.getRequestCode()) - .addBody(UnSubscribeRequestBody.TOPIC, JsonUtils.serialize(topicList)) - .addBody(UnSubscribeRequestBody.URL, unSubscribeUrl); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.UNSUBSCRIBE.getRequestCode()) + .addBody(UnSubscribeRequestBody.TOPIC, JsonUtils.serialize(topicList)) + .addBody(UnSubscribeRequestBody.URL, unSubscribeUrl); String target = selectEventMesh(); try { String unSubRes = HttpUtils.post(httpClient, target, unSubscribeParam); @@ -176,17 +177,17 @@ public void close() throws EventMeshException { private RequestParam buildCommonRequestParam() { return new RequestParam(HttpMethod.POST) - .addHeader(ProtocolKey.ClientInstanceKey.ENV, eventMeshHttpClientConfig.getEnv()) - .addHeader(ProtocolKey.ClientInstanceKey.IDC, eventMeshHttpClientConfig.getIdc()) - .addHeader(ProtocolKey.ClientInstanceKey.IP, eventMeshHttpClientConfig.getIp()) - .addHeader(ProtocolKey.ClientInstanceKey.PID, eventMeshHttpClientConfig.getPid()) - .addHeader(ProtocolKey.ClientInstanceKey.SYS, eventMeshHttpClientConfig.getSys()) - .addHeader(ProtocolKey.ClientInstanceKey.USERNAME, eventMeshHttpClientConfig.getUserName()) - .addHeader(ProtocolKey.ClientInstanceKey.PASSWD, eventMeshHttpClientConfig.getPassword()) - // add protocol version? - .addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()) - .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) - .setTimeout(Constants.DEFAULT_HTTP_TIME_OUT) - .addBody(HeartbeatRequestBody.CONSUMERGROUP, eventMeshHttpClientConfig.getConsumerGroup()); + .addHeader(ProtocolKey.ClientInstanceKey.ENV, eventMeshHttpClientConfig.getEnv()) + .addHeader(ProtocolKey.ClientInstanceKey.IDC, eventMeshHttpClientConfig.getIdc()) + .addHeader(ProtocolKey.ClientInstanceKey.IP, eventMeshHttpClientConfig.getIp()) + .addHeader(ProtocolKey.ClientInstanceKey.PID, eventMeshHttpClientConfig.getPid()) + .addHeader(ProtocolKey.ClientInstanceKey.SYS, eventMeshHttpClientConfig.getSys()) + .addHeader(ProtocolKey.ClientInstanceKey.USERNAME, eventMeshHttpClientConfig.getUserName()) + .addHeader(ProtocolKey.ClientInstanceKey.PASSWD, eventMeshHttpClientConfig.getPassword()) + // add protocol version? + .addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()) + .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) + .setTimeout(Constants.DEFAULT_HTTP_TIME_OUT) + .addBody(HeartbeatRequestBody.CONSUMERGROUP, eventMeshHttpClientConfig.getConsumerGroup()); } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/context/LiteConsumeContext.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/context/LiteConsumeContext.java index cced4ccb7d..63635f0d52 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/context/LiteConsumeContext.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/context/LiteConsumeContext.java @@ -17,9 +17,10 @@ package org.apache.eventmesh.client.http.consumer.context; -import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.eventmesh.common.Constants; +import org.apache.commons.lang3.time.DateFormatUtils; + public class LiteConsumeContext { private String eventMeshIp; diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/listener/LiteMessageListener.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/listener/LiteMessageListener.java index 38ac5b2705..78de0225b7 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/listener/LiteMessageListener.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/consumer/listener/LiteMessageListener.java @@ -22,6 +22,9 @@ import org.apache.eventmesh.client.http.consumer.context.LiteConsumeContext; import org.apache.eventmesh.common.EventMeshMessage; +/** + * LiteMessageListener + */ public interface LiteMessageListener { HandleResult handle(EventMeshMessage eventMeshMessage, LiteConsumeContext liteConsumeContext); diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/model/RequestParam.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/model/RequestParam.java index 2e33444285..97f4c95cb6 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/model/RequestParam.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/model/RequestParam.java @@ -26,6 +26,7 @@ import java.util.Map; import io.netty.handler.codec.http.HttpMethod; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -80,11 +81,11 @@ public String getQueryParams() { for (Map.Entry query : queryParams.entrySet()) { for (String val : query.getValue()) { stringBuilder.append("&") - .append(URLEncoder.encode(query.getKey(), "UTF-8")); + .append(URLEncoder.encode(query.getKey(), "UTF-8")); if (val != null && !val.isEmpty()) { stringBuilder.append("=") - .append(URLEncoder.encode(val, "UTF-8")); + .append(URLEncoder.encode(val, "UTF-8")); } } } @@ -105,7 +106,7 @@ public RequestParam addQueryParam(String key, String value) { queryParams = new HashMap<>(); } if (!queryParams.containsKey(key)) { - queryParams.put(key, new String[] {value}); + queryParams.put(key, new String[]{value}); } else { queryParams.put(key, (String[]) Arrays.asList(queryParams.get(key), value).toArray()); } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/CloudEventProducer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/CloudEventProducer.java index 9a4ac1d985..098c8f067f 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/CloudEventProducer.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/CloudEventProducer.java @@ -28,7 +28,6 @@ import org.apache.eventmesh.common.protocol.http.body.message.SendMessageResponseBody; import org.apache.eventmesh.common.protocol.http.common.EventMeshRetCode; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; -import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.utils.JsonUtils; import org.apache.eventmesh.common.utils.RandomStringUtils; @@ -36,12 +35,13 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; -import com.google.common.base.Preconditions; - import io.cloudevents.CloudEvent; import io.cloudevents.core.builder.CloudEventBuilder; import io.cloudevents.core.provider.EventFormatProvider; import io.netty.handler.codec.http.HttpMethod; + +import com.google.common.base.Preconditions; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -61,7 +61,7 @@ public void publish(CloudEvent cloudEvent) throws EventMeshException { CloudEvent enhanceCloudEvent = enhanceCloudEvent(cloudEvent); // todo: Can put to abstract class, all protocol use the same send method? This can be a template method RequestParam requestParam = buildCommonPostParam(enhanceCloudEvent) - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_ASYNC.getRequestCode()); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_ASYNC.getRequestCode()); String target = selectEventMesh(); try { String response = HttpUtils.post(httpClient, target, requestParam); @@ -81,8 +81,8 @@ public CloudEvent request(CloudEvent cloudEvent, long timeout) throws EventMeshE validateCloudEvent(cloudEvent); CloudEvent enhanceCloudEvent = enhanceCloudEvent(cloudEvent); RequestParam requestParam = buildCommonPostParam(enhanceCloudEvent) - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) - .setTimeout(timeout); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) + .setTimeout(timeout); String target = selectEventMesh(); try { @@ -99,15 +99,15 @@ public CloudEvent request(CloudEvent cloudEvent, long timeout) throws EventMeshE @Override public void request(final CloudEvent cloudEvent, final RRCallback rrCallback, long timeout) - throws EventMeshException { + throws EventMeshException { validateCloudEvent(cloudEvent); CloudEvent enhanceCloudEvent = enhanceCloudEvent(cloudEvent); RequestParam requestParam = buildCommonPostParam(enhanceCloudEvent) - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) - .setTimeout(timeout); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) + .setTimeout(timeout); String target = selectEventMesh(); RRCallbackResponseHandlerAdapter adapter = new RRCallbackResponseHandlerAdapter<>( - enhanceCloudEvent, rrCallback, timeout); + enhanceCloudEvent, rrCallback, timeout); try { HttpUtils.post(httpClient, null, target, requestParam, adapter); } catch (IOException e) { @@ -122,47 +122,47 @@ private void validateCloudEvent(CloudEvent cloudEvent) { private RequestParam buildCommonPostParam(CloudEvent cloudEvent) { byte[] bodyByte = EventFormatProvider.getInstance().resolveFormat(cloudEvent.getDataContentType()) - .serialize(cloudEvent); + .serialize(cloudEvent); String content = new String(bodyByte, StandardCharsets.UTF_8); RequestParam requestParam = new RequestParam(HttpMethod.POST); requestParam - .addHeader(ProtocolKey.ClientInstanceKey.ENV, eventMeshHttpClientConfig.getEnv()) - .addHeader(ProtocolKey.ClientInstanceKey.IDC, eventMeshHttpClientConfig.getIdc()) - .addHeader(ProtocolKey.ClientInstanceKey.IP, eventMeshHttpClientConfig.getIp()) - .addHeader(ProtocolKey.ClientInstanceKey.PID, eventMeshHttpClientConfig.getPid()) - .addHeader(ProtocolKey.ClientInstanceKey.SYS, eventMeshHttpClientConfig.getSys()) - .addHeader(ProtocolKey.ClientInstanceKey.USERNAME, eventMeshHttpClientConfig.getUserName()) - .addHeader(ProtocolKey.ClientInstanceKey.PASSWD, eventMeshHttpClientConfig.getPassword()) - .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) - .addHeader(ProtocolKey.PROTOCOL_TYPE, PROTOCOL_TYPE) - .addHeader(ProtocolKey.PROTOCOL_DESC, PROTOCOL_DESC) - .addHeader(ProtocolKey.PROTOCOL_VERSION, cloudEvent.getSpecVersion().toString()) - - // todo: move producerGroup tp header - .addBody(SendMessageRequestBody.PRODUCERGROUP, eventMeshHttpClientConfig.getProducerGroup()) - .addBody(SendMessageRequestBody.CONTENT, content); + .addHeader(ProtocolKey.ClientInstanceKey.ENV, eventMeshHttpClientConfig.getEnv()) + .addHeader(ProtocolKey.ClientInstanceKey.IDC, eventMeshHttpClientConfig.getIdc()) + .addHeader(ProtocolKey.ClientInstanceKey.IP, eventMeshHttpClientConfig.getIp()) + .addHeader(ProtocolKey.ClientInstanceKey.PID, eventMeshHttpClientConfig.getPid()) + .addHeader(ProtocolKey.ClientInstanceKey.SYS, eventMeshHttpClientConfig.getSys()) + .addHeader(ProtocolKey.ClientInstanceKey.USERNAME, eventMeshHttpClientConfig.getUserName()) + .addHeader(ProtocolKey.ClientInstanceKey.PASSWD, eventMeshHttpClientConfig.getPassword()) + .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) + .addHeader(ProtocolKey.PROTOCOL_TYPE, PROTOCOL_TYPE) + .addHeader(ProtocolKey.PROTOCOL_DESC, PROTOCOL_DESC) + .addHeader(ProtocolKey.PROTOCOL_VERSION, cloudEvent.getSpecVersion().toString()) + + // todo: move producerGroup tp header + .addBody(SendMessageRequestBody.PRODUCERGROUP, eventMeshHttpClientConfig.getProducerGroup()) + .addBody(SendMessageRequestBody.CONTENT, content); return requestParam; } private CloudEvent enhanceCloudEvent(final CloudEvent cloudEvent) { return CloudEventBuilder.from(cloudEvent) - .withExtension(ProtocolKey.ClientInstanceKey.ENV, eventMeshHttpClientConfig.getEnv()) - .withExtension(ProtocolKey.ClientInstanceKey.IDC, eventMeshHttpClientConfig.getIdc()) - .withExtension(ProtocolKey.ClientInstanceKey.IP, eventMeshHttpClientConfig.getIp()) - .withExtension(ProtocolKey.ClientInstanceKey.PID, eventMeshHttpClientConfig.getPid()) - .withExtension(ProtocolKey.ClientInstanceKey.SYS, eventMeshHttpClientConfig.getSys()) - .withExtension(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) - .withExtension(ProtocolKey.PROTOCOL_DESC, cloudEvent.getSpecVersion().name()) - .withExtension(ProtocolKey.PROTOCOL_VERSION, cloudEvent.getSpecVersion().toString()) - .withExtension(ProtocolKey.ClientInstanceKey.BIZSEQNO, RandomStringUtils.generateNum(30)) - .withExtension(ProtocolKey.ClientInstanceKey.UNIQUEID, RandomStringUtils.generateNum(30)) - .build(); + .withExtension(ProtocolKey.ClientInstanceKey.ENV, eventMeshHttpClientConfig.getEnv()) + .withExtension(ProtocolKey.ClientInstanceKey.IDC, eventMeshHttpClientConfig.getIdc()) + .withExtension(ProtocolKey.ClientInstanceKey.IP, eventMeshHttpClientConfig.getIp()) + .withExtension(ProtocolKey.ClientInstanceKey.PID, eventMeshHttpClientConfig.getPid()) + .withExtension(ProtocolKey.ClientInstanceKey.SYS, eventMeshHttpClientConfig.getSys()) + .withExtension(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) + .withExtension(ProtocolKey.PROTOCOL_DESC, cloudEvent.getSpecVersion().name()) + .withExtension(ProtocolKey.PROTOCOL_VERSION, cloudEvent.getSpecVersion().toString()) + .withExtension(ProtocolKey.ClientInstanceKey.BIZSEQNO, RandomStringUtils.generateNum(30)) + .withExtension(ProtocolKey.ClientInstanceKey.UNIQUEID, RandomStringUtils.generateNum(30)) + .build(); } private CloudEvent transformMessage(EventMeshRetObj retObj) { SendMessageResponseBody.ReplyMessage replyMessage = JsonUtils.deserialize(retObj.getRetMsg(), - SendMessageResponseBody.ReplyMessage.class); + SendMessageResponseBody.ReplyMessage.class); // todo: deserialize message return null; } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshHttpProducer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshHttpProducer.java index 1077427535..5b63861dae 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshHttpProducer.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshHttpProducer.java @@ -23,14 +23,15 @@ import io.cloudevents.CloudEvent; import io.openmessaging.api.Message; + import lombok.extern.slf4j.Slf4j; @Slf4j public class EventMeshHttpProducer implements AutoCloseable { private final EventMeshMessageProducer eventMeshMessageProducer; - private final CloudEventProducer cloudEventProducer; - private final OpenMessageProducer openMessageProducer; + private final CloudEventProducer cloudEventProducer; + private final OpenMessageProducer openMessageProducer; public EventMeshHttpProducer(final EventMeshHttpClientConfig eventMeshHttpClientConfig) throws EventMeshException { this.cloudEventProducer = new CloudEventProducer(eventMeshHttpClientConfig); @@ -63,26 +64,26 @@ public Message request(final Message openMessage, final long timeout) throws Eve } public void request(final EventMeshMessage message, final RRCallback rrCallback, final long timeout) - throws EventMeshException { + throws EventMeshException { eventMeshMessageProducer.request(message, rrCallback, timeout); } public void request(final CloudEvent cloudEvent, final RRCallback rrCallback, final long timeout) - throws EventMeshException { + throws EventMeshException { cloudEventProducer.request(cloudEvent, rrCallback, timeout); } public void request(final Message openMessage, final RRCallback rrCallback, final long timeout) - throws EventMeshException { + throws EventMeshException { openMessageProducer.request(openMessage, rrCallback, timeout); } @Override public void close() throws EventMeshException { try ( - final EventMeshMessageProducer ignored = eventMeshMessageProducer; - final OpenMessageProducer ignored1 = openMessageProducer; - final CloudEventProducer ignored2 = cloudEventProducer) { + final EventMeshMessageProducer ignored = eventMeshMessageProducer; + final OpenMessageProducer ignored1 = openMessageProducer; + final CloudEventProducer ignored2 = cloudEventProducer) { log.info("Close producer"); } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshMessageProducer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshMessageProducer.java index 5f528a376b..5092ecb03a 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshMessageProducer.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshMessageProducer.java @@ -17,7 +17,6 @@ package org.apache.eventmesh.client.http.producer; -import io.cloudevents.SpecVersion; import org.apache.eventmesh.client.http.AbstractHttpClient; import org.apache.eventmesh.client.http.EventMeshRetObj; import org.apache.eventmesh.client.http.conf.EventMeshHttpClientConfig; @@ -36,9 +35,11 @@ import java.io.IOException; +import io.cloudevents.SpecVersion; +import io.netty.handler.codec.http.HttpMethod; + import com.google.common.base.Preconditions; -import io.netty.handler.codec.http.HttpMethod; import lombok.extern.slf4j.Slf4j; @Slf4j @@ -56,7 +57,7 @@ public EventMeshMessageProducer(EventMeshHttpClientConfig eventMeshHttpClientCon public void publish(EventMeshMessage message) throws EventMeshException { validateEventMeshMessage(message); RequestParam requestParam = buildCommonPostParam(message) - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_ASYNC.getRequestCode()); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_ASYNC.getRequestCode()); String target = selectEventMesh(); try { @@ -75,8 +76,8 @@ public void publish(EventMeshMessage message) throws EventMeshException { public EventMeshMessage request(EventMeshMessage message, long timeout) throws EventMeshException { validateEventMeshMessage(message); RequestParam requestParam = buildCommonPostParam(message) - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) - .setTimeout(timeout); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) + .setTimeout(timeout); String target = selectEventMesh(); @@ -94,16 +95,16 @@ public EventMeshMessage request(EventMeshMessage message, long timeout) throws E @Override public void request(EventMeshMessage message, RRCallback rrCallback, long timeout) - throws EventMeshException { + throws EventMeshException { validateEventMeshMessage(message); RequestParam requestParam = buildCommonPostParam(message) - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) - .setTimeout(timeout); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) + .setTimeout(timeout); String target = selectEventMesh(); RRCallbackResponseHandlerAdapter adapter = - new RRCallbackResponseHandlerAdapter<>(message, rrCallback, timeout); + new RRCallbackResponseHandlerAdapter<>(message, rrCallback, timeout); try { HttpUtils.post(httpClient, null, target, requestParam, adapter); } catch (IOException e) { @@ -120,35 +121,35 @@ private void validateEventMeshMessage(EventMeshMessage message) { private RequestParam buildCommonPostParam(EventMeshMessage message) { RequestParam requestParam = new RequestParam(HttpMethod.POST); requestParam - .addHeader(ProtocolKey.ClientInstanceKey.ENV, eventMeshHttpClientConfig.getEnv()) - .addHeader(ProtocolKey.ClientInstanceKey.IDC, eventMeshHttpClientConfig.getIdc()) - .addHeader(ProtocolKey.ClientInstanceKey.IP, eventMeshHttpClientConfig.getIp()) - .addHeader(ProtocolKey.ClientInstanceKey.PID, eventMeshHttpClientConfig.getPid()) - .addHeader(ProtocolKey.ClientInstanceKey.SYS, eventMeshHttpClientConfig.getSys()) - .addHeader(ProtocolKey.ClientInstanceKey.USERNAME, eventMeshHttpClientConfig.getUserName()) - .addHeader(ProtocolKey.ClientInstanceKey.PASSWD, eventMeshHttpClientConfig.getPassword()) - .addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()) - .addHeader(ProtocolKey.PROTOCOL_TYPE, PROTOCOL_TYPE) - .addHeader(ProtocolKey.PROTOCOL_DESC, PROTOCOL_DESC) - //default ce version is 1.0 - .addHeader(ProtocolKey.PROTOCOL_VERSION, SpecVersion.V1.toString()) - .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) - .addBody(SendMessageRequestBody.PRODUCERGROUP, eventMeshHttpClientConfig.getProducerGroup()) - // todo: set message to content is better - .addBody(SendMessageRequestBody.TOPIC, message.getTopic()) - .addBody(SendMessageRequestBody.CONTENT, message.getContent()) - .addBody(SendMessageRequestBody.TTL, message.getProp(Constants.EVENTMESH_MESSAGE_CONST_TTL)) - .addBody(SendMessageRequestBody.BIZSEQNO, message.getBizSeqNo()) - .addBody(SendMessageRequestBody.UNIQUEID, message.getUniqueId()); + .addHeader(ProtocolKey.ClientInstanceKey.ENV, eventMeshHttpClientConfig.getEnv()) + .addHeader(ProtocolKey.ClientInstanceKey.IDC, eventMeshHttpClientConfig.getIdc()) + .addHeader(ProtocolKey.ClientInstanceKey.IP, eventMeshHttpClientConfig.getIp()) + .addHeader(ProtocolKey.ClientInstanceKey.PID, eventMeshHttpClientConfig.getPid()) + .addHeader(ProtocolKey.ClientInstanceKey.SYS, eventMeshHttpClientConfig.getSys()) + .addHeader(ProtocolKey.ClientInstanceKey.USERNAME, eventMeshHttpClientConfig.getUserName()) + .addHeader(ProtocolKey.ClientInstanceKey.PASSWD, eventMeshHttpClientConfig.getPassword()) + .addHeader(ProtocolKey.VERSION, ProtocolVersion.V1.getVersion()) + .addHeader(ProtocolKey.PROTOCOL_TYPE, PROTOCOL_TYPE) + .addHeader(ProtocolKey.PROTOCOL_DESC, PROTOCOL_DESC) + //default ce version is 1.0 + .addHeader(ProtocolKey.PROTOCOL_VERSION, SpecVersion.V1.toString()) + .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) + .addBody(SendMessageRequestBody.PRODUCERGROUP, eventMeshHttpClientConfig.getProducerGroup()) + // todo: set message to content is better + .addBody(SendMessageRequestBody.TOPIC, message.getTopic()) + .addBody(SendMessageRequestBody.CONTENT, message.getContent()) + .addBody(SendMessageRequestBody.TTL, message.getProp(Constants.EVENTMESH_MESSAGE_CONST_TTL)) + .addBody(SendMessageRequestBody.BIZSEQNO, message.getBizSeqNo()) + .addBody(SendMessageRequestBody.UNIQUEID, message.getUniqueId()); return requestParam; } private EventMeshMessage transformMessage(EventMeshRetObj retObj) { SendMessageResponseBody.ReplyMessage replyMessage = JsonUtils.deserialize(retObj.getRetMsg(), - SendMessageResponseBody.ReplyMessage.class); + SendMessageResponseBody.ReplyMessage.class); return EventMeshMessage.builder() - .content(replyMessage.body) - .prop(replyMessage.properties) - .topic(replyMessage.topic).build(); + .content(replyMessage.body) + .prop(replyMessage.properties) + .topic(replyMessage.topic).build(); } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshProtocolProducer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshProtocolProducer.java index 1a0001e2cd..b3ad6a7956 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshProtocolProducer.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/EventMeshProtocolProducer.java @@ -34,6 +34,6 @@ public interface EventMeshProtocolProducer extends AutoCloseabl ProtocolMessage request(ProtocolMessage message, long timeout) throws EventMeshException; void request(ProtocolMessage message, RRCallback rrCallback, long timeout) - throws EventMeshException; + throws EventMeshException; } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/OpenMessageProducer.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/OpenMessageProducer.java index c0cc127f71..eeb9602c33 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/OpenMessageProducer.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/OpenMessageProducer.java @@ -28,16 +28,16 @@ import org.apache.eventmesh.common.protocol.http.body.message.SendMessageResponseBody; import org.apache.eventmesh.common.protocol.http.common.EventMeshRetCode; import org.apache.eventmesh.common.protocol.http.common.ProtocolKey; -import org.apache.eventmesh.common.protocol.http.common.ProtocolVersion; import org.apache.eventmesh.common.protocol.http.common.RequestCode; import org.apache.eventmesh.common.utils.JsonUtils; import java.io.IOException; -import com.google.common.base.Preconditions; - import io.netty.handler.codec.http.HttpMethod; import io.openmessaging.api.Message; + +import com.google.common.base.Preconditions; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -48,7 +48,7 @@ class OpenMessageProducer extends AbstractHttpClient implements EventMeshProtoco private static final String PROTOCOL_DESC = "http"; public OpenMessageProducer(EventMeshHttpClientConfig eventMeshHttpClientConfig) - throws EventMeshException { + throws EventMeshException { super(eventMeshHttpClientConfig); } @@ -56,7 +56,7 @@ public OpenMessageProducer(EventMeshHttpClientConfig eventMeshHttpClientConfig) public void publish(Message openMessage) throws EventMeshException { validateOpenMessage(openMessage); RequestParam requestParam = buildCommonPostParam(openMessage) - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_ASYNC.getRequestCode()); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_ASYNC.getRequestCode()); String target = selectEventMesh(); try { String response = HttpUtils.post(httpClient, target, requestParam); @@ -74,8 +74,8 @@ public void publish(Message openMessage) throws EventMeshException { public Message request(Message message, long timeout) throws EventMeshException { validateOpenMessage(message); RequestParam requestParam = buildCommonPostParam(message) - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) - .setTimeout(timeout); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) + .setTimeout(timeout); String target = selectEventMesh(); try { @@ -94,11 +94,11 @@ public Message request(Message message, long timeout) throws EventMeshException public void request(Message message, RRCallback rrCallback, long timeout) throws EventMeshException { validateOpenMessage(message); RequestParam requestParam = buildCommonPostParam(message) - .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) - .setTimeout(timeout); + .addHeader(ProtocolKey.REQUEST_CODE, RequestCode.MSG_SEND_SYNC.getRequestCode()) + .setTimeout(timeout); String target = selectEventMesh(); RRCallbackResponseHandlerAdapter adapter = - new RRCallbackResponseHandlerAdapter<>(message, rrCallback, timeout); + new RRCallbackResponseHandlerAdapter<>(message, rrCallback, timeout); try { HttpUtils.post(httpClient, null, target, requestParam, adapter); } catch (IOException e) { @@ -113,20 +113,20 @@ private void validateOpenMessage(Message openMessage) { private RequestParam buildCommonPostParam(Message openMessage) { RequestParam requestParam = new RequestParam(HttpMethod.POST); requestParam - .addHeader(ProtocolKey.ClientInstanceKey.USERNAME, eventMeshHttpClientConfig.getUserName()) - .addHeader(ProtocolKey.ClientInstanceKey.PASSWD, eventMeshHttpClientConfig.getPassword()) - .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) - .addHeader(ProtocolKey.PROTOCOL_TYPE, PROTOCOL_TYPE) - .addHeader(ProtocolKey.PROTOCOL_DESC, PROTOCOL_DESC) - // todo: add producerGroup to header, set protocol type, protocol version - .addBody(SendMessageRequestBody.PRODUCERGROUP, eventMeshHttpClientConfig.getProducerGroup()) - .addBody(SendMessageRequestBody.CONTENT, JsonUtils.serialize(openMessage)); + .addHeader(ProtocolKey.ClientInstanceKey.USERNAME, eventMeshHttpClientConfig.getUserName()) + .addHeader(ProtocolKey.ClientInstanceKey.PASSWD, eventMeshHttpClientConfig.getPassword()) + .addHeader(ProtocolKey.LANGUAGE, Constants.LANGUAGE_JAVA) + .addHeader(ProtocolKey.PROTOCOL_TYPE, PROTOCOL_TYPE) + .addHeader(ProtocolKey.PROTOCOL_DESC, PROTOCOL_DESC) + // todo: add producerGroup to header, set protocol type, protocol version + .addBody(SendMessageRequestBody.PRODUCERGROUP, eventMeshHttpClientConfig.getProducerGroup()) + .addBody(SendMessageRequestBody.CONTENT, JsonUtils.serialize(openMessage)); return requestParam; } private Message transformMessage(EventMeshRetObj retObj) { SendMessageResponseBody.ReplyMessage replyMessage = JsonUtils.deserialize(retObj.getRetMsg(), - SendMessageResponseBody.ReplyMessage.class); + SendMessageResponseBody.ReplyMessage.class); // todo: deserialize message return null; } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/RRCallbackResponseHandlerAdapter.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/RRCallbackResponseHandlerAdapter.java index 25237da861..e861384a04 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/RRCallbackResponseHandlerAdapter.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/producer/RRCallbackResponseHandlerAdapter.java @@ -33,10 +33,11 @@ import java.io.IOException; import java.nio.charset.Charset; -import com.google.common.base.Preconditions; - import io.cloudevents.CloudEvent; import io.openmessaging.api.Message; + +import com.google.common.base.Preconditions; + import lombok.extern.slf4j.Slf4j; /** @@ -58,7 +59,7 @@ public RRCallbackResponseHandlerAdapter(ProtocolMessage protocolMessage, RRCallb Preconditions.checkNotNull(rrCallback, "rrCallback invalid"); Preconditions.checkNotNull(protocolMessage, "message invalid"); if (!(protocolMessage instanceof EventMeshMessage) && !(protocolMessage instanceof CloudEvent) - && !(protocolMessage instanceof Message)) { + && !(protocolMessage instanceof Message)) { throw new IllegalArgumentException(String.format("ProtocolMessage: %s is not supported", protocolMessage)); } this.protocolMessage = protocolMessage; @@ -97,12 +98,12 @@ public String handleResponse(HttpResponse response) throws IOException { private ProtocolMessage transformToProtocolMessage(EventMeshRetObj ret) { // todo: constructor other protocol message, can judge by protocol type in properties SendMessageResponseBody.ReplyMessage replyMessage = JsonUtils.deserialize(ret.getRetMsg(), - SendMessageResponseBody.ReplyMessage.class); + SendMessageResponseBody.ReplyMessage.class); EventMeshMessage eventMeshMessage = EventMeshMessage.builder() - .content(replyMessage.body) - .prop(replyMessage.properties) - .topic(replyMessage.topic) - .build(); + .content(replyMessage.body) + .prop(replyMessage.properties) + .topic(replyMessage.topic) + .build(); return (ProtocolMessage) eventMeshMessage; } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java index 000f13b8fa..1a50038cab 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/ssl/MyX509TrustManager.java @@ -19,10 +19,6 @@ import org.apache.commons.lang3.StringUtils; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.TrustManagerFactory; -import javax.net.ssl.X509TrustManager; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; @@ -31,6 +27,11 @@ import java.security.cert.CertificateException; import java.security.cert.X509Certificate; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.X509TrustManager; + public class MyX509TrustManager implements X509TrustManager { X509TrustManager myTrustManager; @@ -47,7 +48,7 @@ public MyX509TrustManager() throws Exception { + fileName), StandardOpenOption.READ), filePass); TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init(keyStore); - TrustManager trustManagers[] = trustManagerFactory.getTrustManagers(); + TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); for (TrustManager trustManager : trustManagers) { if (trustManager instanceof X509TrustManager) { myTrustManager = (X509TrustManager) trustManager; diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java index d2a779e518..0b17d01ca8 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtils.java @@ -17,42 +17,43 @@ package org.apache.eventmesh.client.http.util; -import com.google.common.base.Splitter; -import org.apache.commons.collections4.CollectionUtils; - import org.apache.eventmesh.client.http.conf.EventMeshHttpClientConfig; import org.apache.eventmesh.common.exception.EventMeshException; import org.apache.eventmesh.common.loadbalance.LoadBalanceSelector; import org.apache.eventmesh.common.loadbalance.RandomLoadBalanceSelector; import org.apache.eventmesh.common.loadbalance.Weight; -import org.apache.eventmesh.common.loadbalance.WeightRoundRobinLoadBalanceSelector; import org.apache.eventmesh.common.loadbalance.WeightRandomLoadBalanceSelector; +import org.apache.eventmesh.common.loadbalance.WeightRoundRobinLoadBalanceSelector; + +import org.apache.commons.collections4.CollectionUtils; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; +import com.google.common.base.Splitter; + public class HttpLoadBalanceUtils { private static final Pattern IP_PORT_PATTERN = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d{4,5}"); private static final Pattern IP_PORT_WEIGHT_PATTERN = Pattern.compile("\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}:\\d{4,5}:\\d{1,6}"); public static LoadBalanceSelector createEventMeshServerLoadBalanceSelector( - EventMeshHttpClientConfig eventMeshHttpClientConfig) + EventMeshHttpClientConfig eventMeshHttpClientConfig) throws EventMeshException { LoadBalanceSelector eventMeshServerSelector = null; switch (eventMeshHttpClientConfig.getLoadBalanceType()) { case RANDOM: eventMeshServerSelector = new RandomLoadBalanceSelector<>(buildClusterGroupFromConfig( - eventMeshHttpClientConfig)); + eventMeshHttpClientConfig)); break; case WEIGHT_RANDOM: eventMeshServerSelector = new WeightRandomLoadBalanceSelector<>(buildWeightedClusterGroupFromConfig( - eventMeshHttpClientConfig)); + eventMeshHttpClientConfig)); break; case WEIGHT_ROUND_ROBIN: eventMeshServerSelector = new WeightRoundRobinLoadBalanceSelector<>(buildWeightedClusterGroupFromConfig( - eventMeshHttpClientConfig)); + eventMeshHttpClientConfig)); break; default: // ignore @@ -64,7 +65,7 @@ public static LoadBalanceSelector createEventMeshServerLoadBalanceSelect } private static List> buildWeightedClusterGroupFromConfig( - EventMeshHttpClientConfig eventMeshHttpClientConfig) + EventMeshHttpClientConfig eventMeshHttpClientConfig) throws EventMeshException { List eventMeshAddrs = Splitter.on(";").trimResults().splitToList(eventMeshHttpClientConfig.getLiteEventMeshAddr()); if (CollectionUtils.isEmpty(eventMeshAddrs)) { diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpUtils.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpUtils.java index ef3c5ab76c..000a5c0451 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpUtils.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/http/util/HttpUtils.java @@ -42,9 +42,10 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import io.netty.handler.codec.http.HttpMethod; + import com.google.common.base.Preconditions; -import io.netty.handler.codec.http.HttpMethod; import lombok.Data; import lombok.extern.slf4j.Slf4j; @@ -60,7 +61,7 @@ public static String post(CloseableHttpClient client, @Override public String handleResponse(HttpResponse response) throws IOException { responseHolder.response = - EntityUtils.toString(response.getEntity(), Charset.forName(Constants.DEFAULT_CHARSET)); + EntityUtils.toString(response.getEntity(), Charset.forName(Constants.DEFAULT_CHARSET)); countDownLatch.countDown(); if (log.isDebugEnabled()) { log.debug("{}", responseHolder); @@ -72,6 +73,7 @@ public String handleResponse(HttpResponse response) throws IOException { try { countDownLatch.await(requestParam.getTimeout(), TimeUnit.MILLISECONDS); } catch (InterruptedException ie) { + //ignore } return responseHolder.response; @@ -87,7 +89,7 @@ public static String post(CloseableHttpClient client, @Override public String handleResponse(HttpResponse response) throws IOException { responseHolder.response = - EntityUtils.toString(response.getEntity(), Charset.forName(Constants.DEFAULT_CHARSET)); + EntityUtils.toString(response.getEntity(), Charset.forName(Constants.DEFAULT_CHARSET)); countDownLatch.countDown(); if (log.isDebugEnabled()) { log.debug("{}", responseHolder); @@ -137,8 +139,8 @@ public static void post(CloseableHttpClient client, //ttl RequestConfig.Builder configBuilder = RequestConfig.custom(); configBuilder.setSocketTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))) - .setConnectTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))) - .setConnectionRequestTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))); + .setConnectTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))) + .setConnectionRequestTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))); if (forwardAgent != null) { configBuilder.setProxy(forwardAgent); @@ -180,8 +182,8 @@ public static void get(CloseableHttpClient client, //ttl RequestConfig.Builder configBuilder = RequestConfig.custom(); configBuilder.setSocketTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))) - .setConnectTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))) - .setConnectionRequestTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))); + .setConnectTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))) + .setConnectionRequestTimeout(Integer.parseInt(String.valueOf(requestParam.getTimeout()))); if (forwardAgent != null) { configBuilder.setProxy(forwardAgent); @@ -205,7 +207,7 @@ public static String get(CloseableHttpClient client, @Override public String handleResponse(HttpResponse response) throws IOException { responseHolder.response = - EntityUtils.toString(response.getEntity(), Charset.forName(Constants.DEFAULT_CHARSET)); + EntityUtils.toString(response.getEntity(), Charset.forName(Constants.DEFAULT_CHARSET)); countDownLatch.countDown(); if (log.isDebugEnabled()) { log.debug("{}", responseHolder); @@ -217,6 +219,7 @@ public String handleResponse(HttpResponse response) throws IOException { try { countDownLatch.await(requestParam.getTimeout(), TimeUnit.MILLISECONDS); } catch (InterruptedException ie) { + //ignore } return responseHolder.response; @@ -232,7 +235,7 @@ public static String get(CloseableHttpClient client, @Override public String handleResponse(HttpResponse response) throws IOException { responseHolder.response = - EntityUtils.toString(response.getEntity(), Charset.forName(Constants.DEFAULT_CHARSET)); + EntityUtils.toString(response.getEntity(), Charset.forName(Constants.DEFAULT_CHARSET)); countDownLatch.countDown(); if (log.isDebugEnabled()) { log.debug("{}", responseHolder); @@ -244,6 +247,7 @@ public String handleResponse(HttpResponse response) throws IOException { try { countDownLatch.await(requestParam.getTimeout(), TimeUnit.MILLISECONDS); } catch (InterruptedException ie) { + //ignore } return responseHolder.response; diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClient.java index a4a7c8d174..60c27afc0e 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClient.java @@ -46,7 +46,7 @@ public interface EventMeshTCPClient extends AutoCloseable { void listen() throws EventMeshException; void subscribe(String topic, SubscriptionMode subscriptionMode, SubscriptionType subscriptionType) - throws EventMeshException; + throws EventMeshException; void unsubscribe() throws EventMeshException; diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClientFactory.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClientFactory.java index 4291043db3..69fd2e0a61 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClientFactory.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPClientFactory.java @@ -23,10 +23,11 @@ import org.apache.eventmesh.client.tcp.impl.openmessage.OpenMessageTCPClient; import org.apache.eventmesh.common.protocol.tcp.EventMeshMessage; -import com.google.common.base.Preconditions; - import io.cloudevents.CloudEvent; import io.openmessaging.api.Message; + +import com.google.common.base.Preconditions; + import lombok.experimental.UtilityClass; @UtilityClass @@ -42,7 +43,7 @@ public class EventMeshTCPClientFactory { */ @SuppressWarnings("unchecked") public static EventMeshTCPClient createEventMeshTCPClient( - EventMeshTCPClientConfig eventMeshTcpClientConfig, Class protocolMessageClass) { + EventMeshTCPClientConfig eventMeshTcpClientConfig, Class protocolMessageClass) { Preconditions.checkNotNull(protocolMessageClass, "ProtocolMessage type cannot be null"); Preconditions.checkNotNull(eventMeshTcpClientConfig, "EventMeshTcpClientConfig cannot be null"); @@ -56,6 +57,6 @@ public static EventMeshTCPClient createEventM return (EventMeshTCPClient) new OpenMessageTCPClient(eventMeshTcpClientConfig); } throw new IllegalArgumentException( - String.format("ProtocolMessageClass: %s is not supported", protocolMessageClass)); + String.format("ProtocolMessageClass: %s is not supported", protocolMessageClass)); } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPSubClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPSubClient.java index 0cb2a03f3f..8b1ec7b372 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPSubClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/EventMeshTCPSubClient.java @@ -39,7 +39,7 @@ public interface EventMeshTCPSubClient extends AutoCloseable { void reconnect() throws EventMeshException; void subscribe(String topic, SubscriptionMode subscriptionMode, SubscriptionType subscriptionType) - throws EventMeshException; + throws EventMeshException; void unsubscribe() throws EventMeshException; diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/AsyncRRCallback.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/AsyncRRCallback.java index 135e88dd88..949c0efa50 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/AsyncRRCallback.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/AsyncRRCallback.java @@ -17,6 +17,9 @@ package org.apache.eventmesh.client.tcp.common; +/** + * AsyncRRCallback + */ public interface AsyncRRCallback { void callback(Package msg); } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java index a6c9eea245..96b6ad7eab 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/MessageUtils.java @@ -98,7 +98,7 @@ public static Package buildPackage(Object message, Command command) { msg.getHeader().putProperty(Constants.PROTOCOL_VERSION, cloudEvent.getSpecVersion().toString()); msg.getHeader().putProperty(Constants.PROTOCOL_DESC, "tcp"); byte[] bodyByte = EventFormatProvider.getInstance().resolveFormat(cloudEvent.getDataContentType()) - .serialize((CloudEvent) message); + .serialize((CloudEvent) message); msg.setBody(bodyByte); } else if (message instanceof EventMeshMessage) { msg.getHeader().putProperty(Constants.PROTOCOL_TYPE, EventMeshCommon.EM_MESSAGE_PROTOCOL_NAME); @@ -140,38 +140,38 @@ public static Package responseToClientAck(Package in) { public static UserAgent generateSubClient(UserAgent agent) { return UserAgent.builder() - .env(agent.getEnv()) - .host(agent.getHost()) - .password(agent.getPassword()) - .username(agent.getUsername()) - .path(agent.getPath()) - .port(agent.getPort()) - .subsystem(agent.getSubsystem()) - .pid(agent.getPid()) - .version(agent.getVersion()) - .idc(agent.getIdc()) - .consumerGroup(agent.getConsumerGroup()) - .producerGroup(agent.getProducerGroup()) - .purpose(EventMeshCommon.USER_AGENT_PURPOSE_SUB) - .build(); + .env(agent.getEnv()) + .host(agent.getHost()) + .password(agent.getPassword()) + .username(agent.getUsername()) + .path(agent.getPath()) + .port(agent.getPort()) + .subsystem(agent.getSubsystem()) + .pid(agent.getPid()) + .version(agent.getVersion()) + .idc(agent.getIdc()) + .consumerGroup(agent.getConsumerGroup()) + .producerGroup(agent.getProducerGroup()) + .purpose(EventMeshCommon.USER_AGENT_PURPOSE_SUB) + .build(); } public static UserAgent generatePubClient(UserAgent agent) { return UserAgent.builder() - .env(agent.getEnv()) - .host(agent.getHost()) - .password(agent.getPassword()) - .username(agent.getUsername()) - .path(agent.getPath()) - .port(agent.getPort()) - .subsystem(agent.getSubsystem()) - .pid(agent.getPid()) - .version(agent.getVersion()) - .idc(agent.getIdc()) - .consumerGroup(agent.getConsumerGroup()) - .producerGroup(agent.getProducerGroup()) - .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) - .build(); + .env(agent.getEnv()) + .host(agent.getHost()) + .password(agent.getPassword()) + .username(agent.getUsername()) + .path(agent.getPath()) + .port(agent.getPort()) + .subsystem(agent.getSubsystem()) + .pid(agent.getPid()) + .version(agent.getVersion()) + .idc(agent.getIdc()) + .consumerGroup(agent.getConsumerGroup()) + .producerGroup(agent.getProducerGroup()) + .purpose(EventMeshCommon.USER_AGENT_PURPOSE_PUB) + .build(); } private static Subscription generateSubscription(String topic, SubscriptionMode subscriptionMode, diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/RequestContext.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/RequestContext.java index ae36e6a746..a713bd8850 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/RequestContext.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/RequestContext.java @@ -17,9 +17,10 @@ package org.apache.eventmesh.client.tcp.common; +import org.apache.eventmesh.common.protocol.tcp.Package; + import java.util.concurrent.CountDownLatch; -import org.apache.eventmesh.common.protocol.tcp.Package; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -75,19 +76,19 @@ public void finish(Package msg) { latch.countDown(); } - public static RequestContext _context(Object key, Package request, CountDownLatch latch) throws Exception { + public static RequestContext context(Object key, Package request, CountDownLatch latch) throws Exception { RequestContext c = new RequestContext(key, request, latch); logger.info("_RequestContext|create|key=" + key); return c; } - public static Object _key(Package request) { -// MessageType type = request.getHeader().getType(); -// if(MessageType.SyncRequest == type || MessageType.SyncResponse == type -// || MessageType.AsyncRequest == type || MessageType.AsyncResponse == type) { -// return request.getBody().getSysHeader().getUniqueId() ; -// } + public static Object key(Package request) { + //MessageType type = request.getHeader().getType(); + //if(MessageType.SyncRequest == type || MessageType.SyncResponse == type + // || MessageType.AsyncRequest == type || MessageType.AsyncResponse == type) { + // return request.getBody().getSysHeader().getUniqueId() ; + //} return request.getHeader().getSeq(); } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java index b31f876688..7f37b73a8d 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/common/TcpClient.java @@ -32,9 +32,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import com.google.common.base.Preconditions; -import com.google.common.util.concurrent.ThreadFactoryBuilder; - import io.netty.bootstrap.Bootstrap; import io.netty.buffer.PooledByteBufAllocator; import io.netty.channel.AdaptiveRecvByteBufAllocator; @@ -50,6 +47,10 @@ import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel; + +import com.google.common.base.Preconditions; +import com.google.common.util.concurrent.ThreadFactoryBuilder; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -59,8 +60,8 @@ public abstract class TcpClient implements Closeable { protected final ConcurrentHashMap contexts = new ConcurrentHashMap<>(); - protected final String host; - protected final int port; + protected final String host; + protected final int port; protected final UserAgent userAgent; private final Bootstrap bootstrap = new Bootstrap(); @@ -72,8 +73,8 @@ public abstract class TcpClient implements Closeable { private ScheduledFuture heartTask; protected static final ScheduledThreadPoolExecutor scheduler = new ScheduledThreadPoolExecutor( - Runtime.getRuntime().availableProcessors(), - new ThreadFactoryBuilder().setNameFormat("TCPClientScheduler").setDaemon(true).build()); + Runtime.getRuntime().availableProcessors(), + new ThreadFactoryBuilder().setNameFormat("TCPClientScheduler").setDaemon(true).build()); public TcpClient(EventMeshTCPClientConfig eventMeshTcpClientConfig) { Preconditions.checkNotNull(eventMeshTcpClientConfig, "EventMeshTcpClientConfig cannot be null"); @@ -88,15 +89,15 @@ protected synchronized void open(SimpleChannelInboundHandler handler) t bootstrap.group(workers); bootstrap.channel(NioSocketChannel.class); bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 1_000) - .option(ChannelOption.SO_KEEPALIVE, true) - .option(ChannelOption.SO_SNDBUF, 64 * 1024) - .option(ChannelOption.SO_RCVBUF, 64 * 1024) - .option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(1024, 8192, 65536)) - .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); + .option(ChannelOption.SO_KEEPALIVE, true) + .option(ChannelOption.SO_SNDBUF, 64 * 1024) + .option(ChannelOption.SO_RCVBUF, 64 * 1024) + .option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(1024, 8192, 65536)) + .option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT); bootstrap.handler(new ChannelInitializer() { public void initChannel(SocketChannel ch) { ch.pipeline().addLast(new Codec.Encoder(), new Codec.Decoder()) - .addLast(handler, newExceptionHandler()); + .addLast(handler, newExceptionHandler()); } }); @@ -104,8 +105,8 @@ public void initChannel(SocketChannel ch) { InetSocketAddress localAddress = (InetSocketAddress) f.channel().localAddress(); channel = f.channel(); log - .info("connected|local={}:{}|server={}", localAddress.getAddress().getHostAddress(), localAddress.getPort(), - host + ":" + port); + .info("connected|local={}:{}|server={}", localAddress.getAddress().getHostAddress(), localAddress.getPort(), + host + ":" + port); } @Override @@ -164,9 +165,9 @@ protected void send(Package msg) throws Exception { } protected Package io(Package msg, long timeout) throws Exception { - Object key = RequestContext._key(msg); + Object key = RequestContext.key(msg); CountDownLatch latch = new CountDownLatch(1); - RequestContext c = RequestContext._context(key, msg, latch); + RequestContext c = RequestContext.context(key, msg, latch); if (!contexts.contains(c)) { contexts.put(key, c); } else { @@ -196,7 +197,7 @@ private ChannelDuplexHandler newExceptionHandler() { @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { log - .info("exceptionCaught, close connection.|remote address={}", ctx.channel().remoteAddress(), cause); + .info("exceptionCaught, close connection.|remote address={}", ctx.channel().remoteAddress(), cause); ctx.close(); } }; diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/conf/EventMeshTCPClientConfig.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/conf/EventMeshTCPClientConfig.java index 56b94f5e52..e47daa9245 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/conf/EventMeshTCPClientConfig.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/conf/EventMeshTCPClientConfig.java @@ -25,7 +25,7 @@ @Data @Builder public class EventMeshTCPClientConfig { - private String host; - private int port; + private String host; + private int port; private UserAgent userAgent; } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPPubHandler.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPPubHandler.java index 4eca20e98f..b83865991a 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPPubHandler.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPPubHandler.java @@ -24,10 +24,11 @@ import java.util.concurrent.ConcurrentHashMap; -import com.google.common.base.Preconditions; - import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; + +import com.google.common.base.Preconditions; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -57,7 +58,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Package msg) { break; } - RequestContext context = contexts.get(RequestContext._key(msg)); + RequestContext context = contexts.get(RequestContext.key(msg)); if (context != null) { contexts.remove(context.getKey()); context.finish(msg); diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPSubHandler.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPSubHandler.java index 1149e09ad5..4669244b9f 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPSubHandler.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/AbstractEventMeshTCPSubHandler.java @@ -24,10 +24,11 @@ import java.util.concurrent.ConcurrentHashMap; -import com.google.common.base.Preconditions; - import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; + +import com.google.common.base.Preconditions; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -64,7 +65,7 @@ protected void channelRead0(ChannelHandlerContext ctx, Package msg) throws Excep default: log.error("msg ignored|{}|{}", cmd, msg); } - RequestContext context = contexts.get(RequestContext._key(msg)); + RequestContext context = contexts.get(RequestContext.key(msg)); if (context != null) { contexts.remove(context.getKey()); context.finish(msg); diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPClient.java index abe029825c..d81cd84f89 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPClient.java @@ -74,7 +74,7 @@ public void listen() throws EventMeshException { @Override public void subscribe(String topic, SubscriptionMode subscriptionMode, SubscriptionType subscriptionType) - throws EventMeshException { + throws EventMeshException { cloudEventTCPSubClient.subscribe(topic, subscriptionMode, subscriptionType); } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPPubClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPPubClient.java index 13262d50b9..b7de41275f 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPPubClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPPubClient.java @@ -33,13 +33,14 @@ import java.nio.charset.StandardCharsets; import java.util.concurrent.ConcurrentHashMap; -import com.google.common.base.Preconditions; - import io.cloudevents.CloudEvent; import io.cloudevents.core.format.EventFormat; import io.cloudevents.core.provider.EventFormatProvider; import io.cloudevents.jackson.JsonFormat; import io.netty.channel.ChannelHandlerContext; + +import com.google.common.base.Preconditions; + import lombok.extern.slf4j.Slf4j; /** @@ -93,7 +94,7 @@ public void asyncRR(CloudEvent event, AsyncRRCallback callback, long timeout) th try { Package msg = MessageUtils.buildPackage(event, Command.REQUEST_TO_SERVER); super.send(msg); - this.callbackConcurrentHashMap.put((String) RequestContext._key(msg), callback); + this.callbackConcurrentHashMap.put((String) RequestContext.key(msg), callback); } catch (Exception ex) { // should trigger callback? throw new EventMeshException("asyncRR error", ex); @@ -105,7 +106,7 @@ public Package publish(CloudEvent cloudEvent, long timeout) throws EventMeshExce try { Package msg = MessageUtils.buildPackage(cloudEvent, Command.ASYNC_MESSAGE_TO_SERVER); log.info("SimplePubClientImpl cloud event|{}|publish|send|type={}|protocol={}|msg={}", - clientNo, msg.getHeader().getCmd(), msg.getHeader().getProperty(Constants.PROTOCOL_TYPE), msg); + clientNo, msg.getHeader().getCmd(), msg.getHeader().getProperty(Constants.PROTOCOL_TYPE), msg); return io(msg, timeout); } catch (Exception ex) { throw new EventMeshException("publish error", ex); @@ -117,7 +118,7 @@ public void broadcast(CloudEvent cloudEvent, long timeout) throws EventMeshExcep try { Package msg = MessageUtils.buildPackage(cloudEvent, Command.BROADCAST_MESSAGE_TO_SERVER); log.info("{}|publish|send|type={}|protocol={}|msg={}", clientNo, msg.getHeader().getCmd(), - msg.getHeader().getProperty(Constants.PROTOCOL_TYPE), msg); + msg.getHeader().getProperty(Constants.PROTOCOL_TYPE), msg); super.send(msg); } catch (Exception ex) { throw new EventMeshException("Broadcast message error", ex); @@ -148,7 +149,7 @@ public CloudEventTCPPubHandler(ConcurrentHashMap context public void callback(CloudEvent cloudEvent, ChannelHandlerContext ctx) { if (callback != null) { callback.handle(cloudEvent) - .ifPresent(responseMessage -> ctx.writeAndFlush(MessageUtils.buildPackage(responseMessage, Command.RESPONSE_TO_SERVER))); + .ifPresent(responseMessage -> ctx.writeAndFlush(MessageUtils.buildPackage(responseMessage, Command.RESPONSE_TO_SERVER))); } } @@ -156,7 +157,7 @@ public void callback(CloudEvent cloudEvent, ChannelHandlerContext ctx) { public CloudEvent getMessage(Package tcpPackage) { EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE); Preconditions.checkNotNull(eventFormat, - String.format("Cannot find the cloudevent format: %s", JsonFormat.CONTENT_TYPE)); + String.format("Cannot find the cloudevent format: %s", JsonFormat.CONTENT_TYPE)); return eventFormat.deserialize(tcpPackage.getBody().toString().getBytes(StandardCharsets.UTF_8)); } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java index 068e86daff..f6eee73e0f 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/cloudevent/CloudEventTCPSubClient.java @@ -40,13 +40,14 @@ import java.util.List; import java.util.concurrent.ConcurrentHashMap; -import com.google.common.base.Preconditions; - import io.cloudevents.CloudEvent; import io.cloudevents.core.format.EventFormat; import io.cloudevents.core.provider.EventFormatProvider; import io.cloudevents.jackson.JsonFormat; import io.netty.channel.ChannelHandlerContext; + +import com.google.common.base.Preconditions; + import lombok.extern.slf4j.Slf4j; /** @@ -55,8 +56,8 @@ @Slf4j class CloudEventTCPSubClient extends TcpClient implements EventMeshTCPSubClient { - private final List subscriptionItems = Collections.synchronizedList(new LinkedList<>()); - private ReceiveMsgHook callback; + private final List subscriptionItems = Collections.synchronizedList(new LinkedList<>()); + private ReceiveMsgHook callback; public CloudEventTCPSubClient(EventMeshTCPClientConfig eventMeshTcpClientConfig) { super(eventMeshTcpClientConfig); @@ -93,7 +94,7 @@ public void reconnect() throws EventMeshException { @Override public void subscribe(String topic, SubscriptionMode subscriptionMode, SubscriptionType subscriptionType) - throws EventMeshException { + throws EventMeshException { try { subscriptionItems.add(new SubscriptionItem(topic, subscriptionMode, subscriptionType)); Package request = MessageUtils.subscribe(topic, subscriptionMode, subscriptionType); @@ -141,7 +142,7 @@ public void close() { private class CloudEventTCPSubHandler extends AbstractEventMeshTCPSubHandler { public CloudEventTCPSubHandler( - ConcurrentHashMap contexts) { + ConcurrentHashMap contexts) { super(contexts); } @@ -149,7 +150,7 @@ public CloudEventTCPSubHandler( public CloudEvent getProtocolMessage(Package tcpPackage) { EventFormat eventFormat = EventFormatProvider.getInstance().resolveFormat(JsonFormat.CONTENT_TYPE); Preconditions.checkNotNull(eventFormat, - String.format("Cannot find the cloudevent format: %s", JsonFormat.CONTENT_TYPE)); + String.format("Cannot find the cloudevent format: %s", JsonFormat.CONTENT_TYPE)); return eventFormat.deserialize(tcpPackage.getBody().toString().getBytes(StandardCharsets.UTF_8)); } @@ -157,7 +158,7 @@ public CloudEvent getProtocolMessage(Package tcpPackage) { public void callback(CloudEvent cloudEvent, ChannelHandlerContext ctx) { if (callback != null) { callback.handle(cloudEvent).ifPresent( - responseMessage -> ctx.writeAndFlush(MessageUtils.buildPackage(responseMessage, Command.RESPONSE_TO_SERVER)) + responseMessage -> ctx.writeAndFlush(MessageUtils.buildPackage(responseMessage, Command.RESPONSE_TO_SERVER)) ); } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPClient.java index 6faf050c06..938345964b 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPClient.java @@ -52,7 +52,7 @@ public Package rr(EventMeshMessage eventMeshMessage, long timeout) throws EventM @Override public void asyncRR(EventMeshMessage eventMeshMessage, AsyncRRCallback callback, long timeout) - throws EventMeshException { + throws EventMeshException { eventMeshMessageTCPPubClient.asyncRR(eventMeshMessage, callback, timeout); } @@ -73,7 +73,7 @@ public void listen() throws EventMeshException { @Override public void subscribe(String topic, SubscriptionMode subscriptionMode, SubscriptionType subscriptionType) - throws EventMeshException { + throws EventMeshException { eventMeshMessageTCPSubClient.subscribe(topic, subscriptionMode, subscriptionType); } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPPubClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPPubClient.java index ae189f252c..9d7b958a0f 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPPubClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPPubClient.java @@ -35,6 +35,7 @@ import java.util.concurrent.ConcurrentHashMap; import io.netty.channel.ChannelHandlerContext; + import lombok.extern.slf4j.Slf4j; /** @@ -87,11 +88,11 @@ public Package rr(EventMeshMessage eventMeshMessage, long timeout) throws EventM @Override public void asyncRR(EventMeshMessage eventMeshMessage, AsyncRRCallback callback, long timeout) - throws EventMeshException { + throws EventMeshException { try { Package msg = MessageUtils.buildPackage(eventMeshMessage, Command.REQUEST_TO_SERVER); super.send(msg); - this.callbackConcurrentHashMap.put((String) RequestContext._key(msg), callback); + this.callbackConcurrentHashMap.put((String) RequestContext.key(msg), callback); } catch (Exception ex) { // should trigger callback? throw new EventMeshException("asyncRR error", ex); @@ -103,8 +104,8 @@ public Package publish(EventMeshMessage eventMeshMessage, long timeout) throws E try { Package msg = MessageUtils.buildPackage(eventMeshMessage, Command.ASYNC_MESSAGE_TO_SERVER); log.info("SimplePubClientImpl em message|{}|publish|send|type={}|protocol={}|msg={}", - clientNo, msg.getHeader().getCmd(), - msg.getHeader().getProperty(Constants.PROTOCOL_TYPE), msg); + clientNo, msg.getHeader().getCmd(), + msg.getHeader().getProperty(Constants.PROTOCOL_TYPE), msg); return io(msg, timeout); } catch (Exception ex) { throw new EventMeshException("publish error", ex); @@ -117,7 +118,7 @@ public void broadcast(EventMeshMessage eventMeshMessage, long timeout) throws Ev // todo: transform EventMeshMessage to Package Package msg = MessageUtils.buildPackage(eventMeshMessage, Command.BROADCAST_MESSAGE_TO_SERVER); log.info("{}|publish|send|type={}|protocol={}|msg={}", clientNo, msg.getHeader().getCmd(), - msg.getHeader().getProperty(Constants.PROTOCOL_TYPE), msg); + msg.getHeader().getProperty(Constants.PROTOCOL_TYPE), msg); super.send(msg); } catch (Exception ex) { throw new EventMeshException("Broadcast message error", ex); @@ -148,7 +149,7 @@ public EventMeshTCPPubHandler(ConcurrentHashMap contexts public void callback(EventMeshMessage eventMeshMessage, ChannelHandlerContext ctx) { if (callback != null) { callback.handle(eventMeshMessage).ifPresent( - responseMessage -> ctx.writeAndFlush(MessageUtils.buildPackage(responseMessage, Command.RESPONSE_TO_SERVER)) + responseMessage -> ctx.writeAndFlush(MessageUtils.buildPackage(responseMessage, Command.RESPONSE_TO_SERVER)) ); } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java index c03894d21f..5ff5587b5d 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/eventmeshmessage/EventMeshMessageTCPSubClient.java @@ -42,13 +42,14 @@ import java.util.concurrent.ConcurrentHashMap; import io.netty.channel.ChannelHandlerContext; + import lombok.extern.slf4j.Slf4j; @Slf4j class EventMeshMessageTCPSubClient extends TcpClient implements EventMeshTCPSubClient { - private final List subscriptionItems = Collections.synchronizedList(new LinkedList<>()); - private ReceiveMsgHook callback; + private final List subscriptionItems = Collections.synchronizedList(new LinkedList<>()); + private ReceiveMsgHook callback; public EventMeshMessageTCPSubClient(EventMeshTCPClientConfig eventMeshTcpClientConfig) { super(eventMeshTcpClientConfig); @@ -85,7 +86,7 @@ public void reconnect() throws EventMeshException { @Override public void subscribe(String topic, SubscriptionMode subscriptionMode, SubscriptionType subscriptionType) - throws EventMeshException { + throws EventMeshException { try { subscriptionItems.add(new SubscriptionItem(topic, subscriptionMode, subscriptionType)); Package request = MessageUtils.subscribe(topic, subscriptionMode, subscriptionType); @@ -143,7 +144,7 @@ public EventMeshMessage getProtocolMessage(Package tcpPackage) { public void callback(EventMeshMessage eventMeshMessage, ChannelHandlerContext ctx) { if (callback != null) { callback.handle(eventMeshMessage).ifPresent( - responseMessage -> ctx.writeAndFlush(MessageUtils.buildPackage(responseMessage, Command.RESPONSE_TO_SERVER)) + responseMessage -> ctx.writeAndFlush(MessageUtils.buildPackage(responseMessage, Command.RESPONSE_TO_SERVER)) ); } } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPClient.java index 25a929e5c5..e7ec849cb9 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPClient.java @@ -29,6 +29,7 @@ import org.apache.eventmesh.common.protocol.tcp.Package; import io.openmessaging.api.Message; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -75,7 +76,7 @@ public void listen() throws EventMeshException { @Override public void subscribe(String topic, SubscriptionMode subscriptionMode, SubscriptionType subscriptionType) - throws EventMeshException { + throws EventMeshException { eventMeshTCPSubClient.subscribe(topic, subscriptionMode, subscriptionType); } diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPPubClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPPubClient.java index 3eebdd206d..e24b2b5ba9 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPPubClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPPubClient.java @@ -25,6 +25,7 @@ import org.apache.eventmesh.common.protocol.tcp.Package; import io.openmessaging.api.Message; + import lombok.extern.slf4j.Slf4j; @Slf4j diff --git a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPSubClient.java b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPSubClient.java index 34c3ad0380..b601d4970a 100644 --- a/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPSubClient.java +++ b/eventmesh-sdk-java/src/main/java/org/apache/eventmesh/client/tcp/impl/openmessage/OpenMessageTCPSubClient.java @@ -25,6 +25,7 @@ import org.apache.eventmesh.common.protocol.SubscriptionType; import io.openmessaging.api.Message; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -48,7 +49,7 @@ public void reconnect() throws EventMeshException { @Override public void subscribe(String topic, SubscriptionMode subscriptionMode, SubscriptionType subscriptionType) - throws EventMeshException { + throws EventMeshException { } diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java index 1095de392b..0e74b3030d 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncPublishInstance.java @@ -36,23 +36,23 @@ public static void main(String[] args) throws Exception { final String topic = "TEST-TOPIC-HTTP-ASYNC"; EventMeshHttpClientConfig eventMeshClientConfig = EventMeshHttpClientConfig.builder() - .liteEventMeshAddr(eventMeshIPPort) - .producerGroup("EventMeshTest-producerGroup") - .env("env") - .idc("idc") - .ip(IPUtils.getLocalAddress()) - .sys("1234") - .pid(String.valueOf(ThreadUtils.getPID())).build(); + .liteEventMeshAddr(eventMeshIPPort) + .producerGroup("EventMeshTest-producerGroup") + .env("env") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())).build(); EventMeshHttpProducer eventMeshHttpProducer = new EventMeshHttpProducer(eventMeshClientConfig); for (int i = 0; i < 1; i++) { EventMeshMessage eventMeshMessage = EventMeshMessage.builder() - .bizSeqNo(RandomStringUtils.generateNum(30)) - .content("testPublishMessage") - .topic(topic) - .uniqueId(RandomStringUtils.generateNum(30)) - .build() - .addProp(Constants.EVENTMESH_MESSAGE_CONST_TTL, String.valueOf(4 * 1000)); + .bizSeqNo(RandomStringUtils.generateNum(30)) + .content("testPublishMessage") + .topic(topic) + .uniqueId(RandomStringUtils.generateNum(30)) + .build() + .addProp(Constants.EVENTMESH_MESSAGE_CONST_TTL, String.valueOf(4 * 1000)); eventMeshHttpProducer.publish(eventMeshMessage); Thread.sleep(1000); diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java index 28fe47ccae..9f84cb6ae6 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/AsyncSyncRequestInstance.java @@ -39,9 +39,9 @@ public static void main(String[] args) throws Exception { EventMeshHttpProducer eventMeshHttpProducer = null; try { -// String eventMeshIPPort = args[0]; + //String eventMeshIPPort = args[0]; String eventMeshIPPort = ""; -// final String topic = args[1]; + //final String topic = args[1]; final String topic = "TEST-TOPIC-HTTP-ASYNC"; if (StringUtils.isBlank(eventMeshIPPort)) { // if has multi value, can config as: 127.0.0.1:10105;127.0.0.2:10105 @@ -49,28 +49,28 @@ public static void main(String[] args) throws Exception { } EventMeshHttpClientConfig eventMeshClientConfig = EventMeshHttpClientConfig.builder() - .liteEventMeshAddr(eventMeshIPPort) - .producerGroup("EventMeshTest-producerGroup") - .env("env") - .idc("idc") - .ip(IPUtils.getLocalAddress()) - .sys("1234") - .pid(String.valueOf(ThreadUtils.getPID())).build(); + .liteEventMeshAddr(eventMeshIPPort) + .producerGroup("EventMeshTest-producerGroup") + .env("env") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())).build(); eventMeshHttpProducer = new EventMeshHttpProducer(eventMeshClientConfig); final long startTime = System.currentTimeMillis(); final EventMeshMessage eventMeshMessage = EventMeshMessage.builder() - .bizSeqNo(RandomStringUtils.generateNum(30)) - .content("testAsyncMessage") - .topic(topic) - .uniqueId(RandomStringUtils.generateNum(30)).build(); + .bizSeqNo(RandomStringUtils.generateNum(30)) + .content("testAsyncMessage") + .topic(topic) + .uniqueId(RandomStringUtils.generateNum(30)).build(); eventMeshHttpProducer.request(eventMeshMessage, new RRCallback() { @Override public void onSuccess(EventMeshMessage o) { logger.debug("sendmsg : {}, return : {}, cost:{}ms", eventMeshMessage.getContent(), o.getContent(), - System.currentTimeMillis() - startTime); + System.currentTimeMillis() - startTime); } @Override diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java index 30e7142ebf..6096438a97 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/demo/SyncRequestInstance.java @@ -47,34 +47,34 @@ public static void main(String[] args) throws Exception { } EventMeshHttpClientConfig eventMeshClientConfig = EventMeshHttpClientConfig.builder() - .liteEventMeshAddr(eventMeshIPPort) - .producerGroup("EventMeshTest-producerGroup") - .env("env") - .idc("idc") - .ip(IPUtils.getLocalAddress()) - .sys("1234") - .pid(String.valueOf(ThreadUtils.getPID())).build(); + .liteEventMeshAddr(eventMeshIPPort) + .producerGroup("EventMeshTest-producerGroup") + .env("env") + .idc("idc") + .ip(IPUtils.getLocalAddress()) + .sys("1234") + .pid(String.valueOf(ThreadUtils.getPID())).build(); eventMeshHttpProducer = new EventMeshHttpProducer(eventMeshClientConfig); long startTime = System.currentTimeMillis(); EventMeshMessage eventMeshMessage = EventMeshMessage.builder() - .bizSeqNo(RandomStringUtils.generateNum(30)) - .content("contentStr with special protocal") - .topic(topic) - .uniqueId(RandomStringUtils.generateNum(30)).build(); + .bizSeqNo(RandomStringUtils.generateNum(30)) + .content("contentStr with special protocal") + .topic(topic) + .uniqueId(RandomStringUtils.generateNum(30)).build(); EventMeshMessage rsp = eventMeshHttpProducer.request(eventMeshMessage, 10000); if (logger.isDebugEnabled()) { logger.debug("sendmsg : {}, return : {}, cost:{}ms", eventMeshMessage.getContent(), rsp.getContent(), - System.currentTimeMillis() - startTime); + System.currentTimeMillis() - startTime); } } catch (Exception e) { logger.warn("send msg failed", e); } Thread.sleep(30000); - try (final EventMeshHttpProducer closed = eventMeshHttpProducer){ + try (final EventMeshHttpProducer closed = eventMeshHttpProducer) { // close producer } catch (Exception e1) { logger.warn("producer shutdown exception", e1); diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java index aabafb1d69..f97c2d81eb 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/http/util/HttpLoadBalanceUtilsTest.java @@ -21,6 +21,7 @@ import org.apache.eventmesh.common.exception.EventMeshException; import org.apache.eventmesh.common.loadbalance.LoadBalanceSelector; import org.apache.eventmesh.common.loadbalance.LoadBalanceType; + import org.junit.Assert; import org.junit.Test; @@ -29,8 +30,8 @@ public class HttpLoadBalanceUtilsTest { @Test public void testCreateRandomSelector() throws EventMeshException { EventMeshHttpClientConfig eventMeshHttpClientConfig = EventMeshHttpClientConfig.builder() - .liteEventMeshAddr("127.0.0.1:1001;127.0.0.2:1002") - .build(); + .liteEventMeshAddr("127.0.0.1:1001;127.0.0.2:1002") + .build(); LoadBalanceSelector randomSelector = HttpLoadBalanceUtils .createEventMeshServerLoadBalanceSelector(eventMeshHttpClientConfig); Assert.assertEquals(LoadBalanceType.RANDOM, randomSelector.getType()); diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java index f90a2d25ef..94d273b0dc 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/common/EventMeshTestUtils.java @@ -35,33 +35,33 @@ public class EventMeshTestUtils { public static UserAgent generateClient1() { return UserAgent.builder() - .host("127.0.0.1") - .password(generateRandomString(8)) - .username("PU4283") - .consumerGroup("EventmeshTest-ConsumerGroup") - .producerGroup("EventmeshTest-ProducerGroup") - .path("/data/app/umg_proxy") - .port(8362) - .subsystem("5023") - .pid(32893) - .version("2.0.11") - .idc("FT") - .build(); + .host("127.0.0.1") + .password(generateRandomString(8)) + .username("PU4283") + .consumerGroup("EventmeshTest-ConsumerGroup") + .producerGroup("EventmeshTest-ProducerGroup") + .path("/data/app/umg_proxy") + .port(8362) + .subsystem("5023") + .pid(32893) + .version("2.0.11") + .idc("FT") + .build(); } public static UserAgent generateClient2() { return UserAgent.builder() - .host("127.0.0.1") - .password(generateRandomString(8)) - .username("PU4283") - .consumerGroup("EventmeshTest-ConsumerGroup") - .producerGroup("EventmeshTest-ProducerGroup") - .path("/data/app/umg_proxy") - .port(9362) - .subsystem("5017") - .pid(42893) - .version("2.0.11") - .idc("FT").build(); + .host("127.0.0.1") + .password(generateRandomString(8)) + .username("PU4283") + .consumerGroup("EventmeshTest-ConsumerGroup") + .producerGroup("EventmeshTest-ProducerGroup") + .path("/data/app/umg_proxy") + .port(9362) + .subsystem("5017") + .pid(42893) + .version("2.0.11") + .idc("FT").build(); } public static Package syncRR() { diff --git a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/impl/EventMeshTCPClientFactoryTest.java b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/impl/EventMeshTCPClientFactoryTest.java index 7e3943105c..3467a9e42a 100644 --- a/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/impl/EventMeshTCPClientFactoryTest.java +++ b/eventmesh-sdk-java/src/test/java/org/apache/eventmesh/client/tcp/impl/EventMeshTCPClientFactoryTest.java @@ -36,19 +36,21 @@ public class EventMeshTCPClientFactoryTest { @Test public void createEventMeshTCPClient() { EventMeshTCPClientConfig meshTCPClientConfig = EventMeshTCPClientConfig.builder() - .host("localhost") - .port(1234) - .build(); + .host("localhost") + .port(1234) + .build(); + + EventMeshTCPClient eventMeshMessageTCPClient = - EventMeshTCPClientFactory.createEventMeshTCPClient(meshTCPClientConfig, EventMeshMessage.class); + EventMeshTCPClientFactory.createEventMeshTCPClient(meshTCPClientConfig, EventMeshMessage.class); Assert.assertEquals(EventMeshMessageTCPClient.class, eventMeshMessageTCPClient.getClass()); EventMeshTCPClient cloudEventTCPClient = - EventMeshTCPClientFactory.createEventMeshTCPClient(meshTCPClientConfig, CloudEvent.class); + EventMeshTCPClientFactory.createEventMeshTCPClient(meshTCPClientConfig, CloudEvent.class); Assert.assertEquals(CloudEventTCPClient.class, cloudEventTCPClient.getClass()); EventMeshTCPClient openMessageTCPClient = - EventMeshTCPClientFactory.createEventMeshTCPClient(meshTCPClientConfig, Message.class); + EventMeshTCPClientFactory.createEventMeshTCPClient(meshTCPClientConfig, Message.class); Assert.assertEquals(OpenMessageTCPClient.class, openMessageTCPClient.getClass()); } } \ No newline at end of file diff --git a/eventmesh-security-plugin/eventmesh-security-api/src/main/java/org/apache/eventmesh/api/acl/AclService.java b/eventmesh-security-plugin/eventmesh-security-api/src/main/java/org/apache/eventmesh/api/acl/AclService.java index 38b2f1a86f..8387de2900 100644 --- a/eventmesh-security-plugin/eventmesh-security-api/src/main/java/org/apache/eventmesh/api/acl/AclService.java +++ b/eventmesh-security-plugin/eventmesh-security-api/src/main/java/org/apache/eventmesh/api/acl/AclService.java @@ -14,6 +14,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.api.acl; import org.apache.eventmesh.api.exception.AclException; @@ -22,6 +23,9 @@ import java.util.Properties; +/** + * AclService + */ @EventMeshSPI(isSingleton = true, eventMeshExtensionType = EventMeshExtensionType.SECURITY) public interface AclService { void init() throws AclException; diff --git a/eventmesh-security-plugin/eventmesh-security-api/src/main/java/org/apache/eventmesh/api/exception/AclException.java b/eventmesh-security-plugin/eventmesh-security-api/src/main/java/org/apache/eventmesh/api/exception/AclException.java index 389bf8a232..115be40bec 100644 --- a/eventmesh-security-plugin/eventmesh-security-api/src/main/java/org/apache/eventmesh/api/exception/AclException.java +++ b/eventmesh-security-plugin/eventmesh-security-api/src/main/java/org/apache/eventmesh/api/exception/AclException.java @@ -14,8 +14,12 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.apache.eventmesh.api.exception; +/** + * AclException + */ public class AclException extends RuntimeException { public AclException(String message) { diff --git a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshExtensionFactory.java b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshExtensionFactory.java index a096f1793d..eaf73ff6d2 100644 --- a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshExtensionFactory.java +++ b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshExtensionFactory.java @@ -17,18 +17,20 @@ package org.apache.eventmesh.spi; -import org.apache.commons.lang3.StringUtils; import org.apache.eventmesh.spi.loader.ExtensionClassLoader; import org.apache.eventmesh.spi.loader.JarExtensionClassLoader; import org.apache.eventmesh.spi.loader.MetaInfExtensionClassLoader; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; + +import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * The extension fetching factory, all extension plugins should be fetched by this factory. * And all the extension plugins defined in eventmesh should have {@link EventMeshSPI} annotation. diff --git a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshSPI.java b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshSPI.java index 364d197c9b..a0ae5ecd3e 100644 --- a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshSPI.java +++ b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/EventMeshSPI.java @@ -38,6 +38,7 @@ /** * {@link EventMeshExtensionType} + * * @return extension type */ EventMeshExtensionType eventMeshExtensionType(); diff --git a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/EventMeshUrlClassLoader.java b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/EventMeshUrlClassLoader.java index c53543b6df..9a27d495e1 100644 --- a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/EventMeshUrlClassLoader.java +++ b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/EventMeshUrlClassLoader.java @@ -37,6 +37,7 @@ public static EventMeshUrlClassLoader getInstance() { * method has no effect. *

* More detail see {@link URLClassLoader#addURL(URL)} + * * @param urls */ public void addUrls(List urls) { diff --git a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/JarExtensionClassLoader.java b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/JarExtensionClassLoader.java index 197e213dbb..77d147488d 100644 --- a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/JarExtensionClassLoader.java +++ b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/JarExtensionClassLoader.java @@ -49,11 +49,11 @@ public class JarExtensionClassLoader implements ExtensionClassLoader { private static final Logger logger = LoggerFactory.getLogger(JarExtensionClassLoader.class); private static final ConcurrentHashMap, Map>> EXTENSION_CLASS_CACHE = - new ConcurrentHashMap<>(16); + new ConcurrentHashMap<>(16); private static final String EVENTMESH_EXTENSION_PLUGIN_DIR = - System.getProperty("eventMeshPluginDir", - Joiner.on(File.separator).join(Lists.newArrayList(".", "plugin"))); + System.getProperty("eventMeshPluginDir", + Joiner.on(File.separator).join(Lists.newArrayList(".", "plugin"))); // META-INF/eventmesh private static final String EVENTMESH_EXTENSION_META_DIR = "META-INF/eventmesh/"; @@ -62,7 +62,7 @@ public class JarExtensionClassLoader implements ExtensionClassLoader { public Map> loadExtensionClass(Class extensionType, String extensionInstanceName) { return EXTENSION_CLASS_CACHE - .computeIfAbsent(extensionType, t -> doLoadExtensionClass(t, extensionInstanceName)); + .computeIfAbsent(extensionType, t -> doLoadExtensionClass(t, extensionInstanceName)); } private Map> doLoadExtensionClass(Class extensionType, @@ -71,13 +71,13 @@ private Map> doLoadExtensionClass(Class extensionType, EventMeshSPI eventMeshSpiAnnotation = extensionType.getAnnotation(EventMeshSPI.class); String pluginDir = Paths.get( - EVENTMESH_EXTENSION_PLUGIN_DIR, - eventMeshSpiAnnotation.eventMeshExtensionType().getExtensionTypeName(), - extensionInstanceName + EVENTMESH_EXTENSION_PLUGIN_DIR, + eventMeshSpiAnnotation.eventMeshExtensionType().getExtensionTypeName(), + extensionInstanceName ).toString(); String extensionFileName = - EVENTMESH_EXTENSION_META_DIR + extensionType.getName(); + EVENTMESH_EXTENSION_META_DIR + extensionType.getName(); EventMeshUrlClassLoader urlClassLoader = EventMeshUrlClassLoader.getInstance(); urlClassLoader.addUrls(loadJarPathFromResource(pluginDir)); try { @@ -122,7 +122,7 @@ private List loadJarPathFromResource(String pluginPath) { private static Map> loadResources(URLClassLoader urlClassLoader, URL url, Class extensionType) - throws IOException { + throws IOException { Map> extensionMap = new HashMap<>(); try (InputStream inputStream = url.openStream()) { Properties properties = new Properties(); @@ -133,12 +133,12 @@ private static Map> loadResources(URLClassLoader urlClassLo try { Class targetClass = urlClassLoader.loadClass(extensionClassStr); logger - .info("load extension class success, extensionType: {}, extensionClass: {}", - extensionType, targetClass); + .info("load extension class success, extensionType: {}, extensionClass: {}", + extensionType, targetClass); if (!extensionType.isAssignableFrom(targetClass)) { throw new ExtensionException( - String.format("class: %s is not subClass of %s", targetClass, - extensionType)); + String.format("class: %s is not subClass of %s", targetClass, + extensionType)); } extensionMap.put(extensionNameStr, targetClass); } catch (ClassNotFoundException e) { diff --git a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/MetaInfExtensionClassLoader.java b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/MetaInfExtensionClassLoader.java index ec07f4ea6f..4a98bc10a1 100644 --- a/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/MetaInfExtensionClassLoader.java +++ b/eventmesh-spi/src/main/java/org/apache/eventmesh/spi/loader/MetaInfExtensionClassLoader.java @@ -18,8 +18,6 @@ package org.apache.eventmesh.spi.loader; import org.apache.eventmesh.spi.ExtensionException; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.io.IOException; import java.io.InputStream; @@ -30,6 +28,9 @@ import java.util.Properties; import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * Load extension from classpath */ diff --git a/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/EventMeshExtensionFactoryTest.java b/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/EventMeshExtensionFactoryTest.java index dc75e24d81..5dc24c592a 100644 --- a/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/EventMeshExtensionFactoryTest.java +++ b/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/EventMeshExtensionFactoryTest.java @@ -19,6 +19,7 @@ import org.apache.eventmesh.spi.example.TestPrototypeExtension; import org.apache.eventmesh.spi.example.TestSingletonExtension; + import org.junit.Assert; import org.junit.Test; diff --git a/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/example/TestPrototypeExtension.java b/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/example/TestPrototypeExtension.java index 06e4549f54..8117ae8c8b 100644 --- a/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/example/TestPrototypeExtension.java +++ b/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/example/TestPrototypeExtension.java @@ -20,6 +20,9 @@ import org.apache.eventmesh.spi.EventMeshExtensionType; import org.apache.eventmesh.spi.EventMeshSPI; +/** + * TestPrototypeExtension + */ @EventMeshSPI(isSingleton = false, eventMeshExtensionType = EventMeshExtensionType.UNKNOWN) public interface TestPrototypeExtension { diff --git a/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/example/TestSingletonExtension.java b/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/example/TestSingletonExtension.java index b78744d2e9..9b67793e12 100644 --- a/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/example/TestSingletonExtension.java +++ b/eventmesh-spi/src/test/java/org/apache/eventmesh/spi/example/TestSingletonExtension.java @@ -20,6 +20,9 @@ import org.apache.eventmesh.spi.EventMeshExtensionType; import org.apache.eventmesh.spi.EventMeshSPI; +/** + * TestSingletonExtension + */ @EventMeshSPI(isSingleton = true, eventMeshExtensionType = EventMeshExtensionType.UNKNOWN) public interface TestSingletonExtension { diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..7454180f2a Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..69a9715077 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 7b957476e1..744e882ed5 100755 --- a/gradlew +++ b/gradlew @@ -1,21 +1,19 @@ #!/usr/bin/env sh + +# +# Copyright 2015 the original author or authors. # -# 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 +# Licensed 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 +# https://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. +# 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. # ############################################################################## @@ -74,7 +72,7 @@ case "`uname`" in Darwin* ) darwin=true ;; - MINGW* ) + MSYS* | MINGW* ) msys=true ;; NONSTOP* ) @@ -132,7 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index 192f884777..107acd32c4 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,20 +1,17 @@ @rem -@rem Licensed to the Apache Software Foundation (ASF) under one -@rem or more contributor license agreements. See the NOTICE file -@rem distributed with this work for additional information -@rem regarding copyright ownership. The ASF licenses this file -@rem to you under the Apache License, Version 2.0 (the -@rem "License"); you may not use this file except in compliance -@rem with the License. You may obtain a copy of the License at +@rem Copyright 2015 the original author or authors. @rem -@rem http://www.apache.org/licenses/LICENSE-2.0 +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at @rem -@rem Unless required by applicable law or agreed to in writing, -@rem software distributed under the License is distributed on an -@rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -@rem KIND, either express or implied. See the License for the -@rem specific language governing permissions and limitations -@rem under the License. +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. @rem @if "%DEBUG%" == "" @echo off @@ -43,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -57,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -67,21 +64,6 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line @@ -89,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* :end @rem End local scope for the variables with windows NT shell diff --git a/style/checkStyle.xml b/style/checkStyle.xml index f3fe5630d2..546777c7c6 100644 --- a/style/checkStyle.xml +++ b/style/checkStyle.xml @@ -74,9 +74,9 @@ - + - + @@ -183,7 +183,7 @@ - + @@ -225,7 +225,8 @@ value="Pattern variable name ''{0}'' must match pattern ''{1}''."/> - + + @@ -235,17 +236,20 @@ value="Record component name ''{0}'' must match pattern ''{1}''."/> - + + - + + - + + @@ -269,7 +273,7 @@ - +