scwlkq commented on code in PR #55:
URL:
https://github.com/apache/eventmesh-dashboard/pull/55#discussion_r1518588847
##########
eventmesh-dashboard-console/src/main/java/org/apache/eventmesh/dashboard/console/function/health/check/impl/storage/rocketmq4/Rocketmq4TopicCheck.java:
##########
@@ -138,30 +139,18 @@ public void init() {
//TODO there are many functions that can be reused, they should be
collected in a util module
//this function that create topics can be reused
- try {
- CreateTopicRequestHeader requestHeader = new
CreateTopicRequestHeader();
- requestHeader.setTopic(HealthConstant.ROCKETMQ_CHECK_TOPIC);
-
requestHeader.setTopicFilterType(TopicFilterType.SINGLE_TAG.name());
- requestHeader.setReadQueueNums(8);
- requestHeader.setWriteQueueNums(8);
- requestHeader.setPerm(PermName.PERM_READ | PermName.PERM_WRITE);
- RemotingCommand request =
RemotingCommand.createRequestCommand(RequestCode.UPDATE_AND_CREATE_TOPIC,
requestHeader);
- Object result =
remotingClient.invokeSync(getConfig().getRocketmqConfig().getBrokerUrl(),
request, getConfig().getRequestTimeoutMillis());
- log.info(result.toString());
- } catch (Exception e) {
- log.error("RocketmqTopicCheck init failed when examining topic
stats.", e);
- return;
- }
+ RocketmqUtils.createTopic(HealthConstant.ROCKETMQ_CHECK_TOPIC,
TopicFilterType.SINGLE_TAG.name(), PermName.PERM_READ | PermName.PERM_WRITE,
+ getConfig().getRocketmqProperties().getBrokerUrl(), 8, 8,
getConfig().getRequestTimeoutMillis());
Review Comment:
我看源码里是String addr,我认为它是namesvr地址,不知道这里传brokerUrl会不会有问题
##########
eventmesh-dashboard-core/src/main/java/org/apache/eventmesh/dashboard/core/store/RocketmqTopicCore.java:
##########
@@ -17,42 +17,57 @@
package org.apache.eventmesh.dashboard.core.store;
+
import org.apache.eventmesh.dashboard.common.model.TopicProperties;
-import org.apache.eventmesh.dashboard.core.config.AdminProperties;
+import org.apache.eventmesh.dashboard.common.properties.RocketmqProperties;
+import org.apache.eventmesh.dashboard.common.util.RocketmqUtils;
import org.apache.eventmesh.dashboard.service.store.TopicCore;
+import org.apache.rocketmq.common.TopicConfig;
+import org.apache.rocketmq.common.TopicFilterType;
+import org.apache.rocketmq.common.constant.PermName;
+
+import java.util.ArrayList;
import java.util.List;
import org.springframework.stereotype.Service;
import lombok.extern.slf4j.Slf4j;
-/**
- * TODO implement methods from storage-plugin.admin
- */
-
@Slf4j
@Service
public class RocketmqTopicCore implements TopicCore {
- AdminProperties adminProperties;
+ private final RocketmqProperties rocketmqProperties;
- public RocketmqTopicCore(AdminProperties adminProperties) {
- this.adminProperties = adminProperties;
+ public RocketmqTopicCore(RocketmqProperties rocketmqProperties) {
+ this.rocketmqProperties = rocketmqProperties;
}
@Override
- public List<TopicProperties> getTopic() {
- return null;
+ public List<TopicProperties> getTopics() {
+ List<TopicConfig> topicConfigList =
+ RocketmqUtils.getTopics(rocketmqProperties.getNamesrvAddr(),
rocketmqProperties.getRequestTimeoutMillis());
+ List<TopicProperties> topicPropertiesList = new ArrayList<>();
+ for (TopicConfig topicConfig : topicConfigList) {
+ TopicProperties topicProperties = new TopicProperties();
+ topicProperties.setRocketmqTopicConfig(topicConfig);
+ topicPropertiesList.add(topicProperties);
+ }
+ return topicPropertiesList;
}
Review Comment:
我本来想的是RocketmqUtils的getTopics就直接返回SDK里原生的TopicConfig,然后TopicCore里再封装一层TopicProperties(这么写我是想兼容其他的中间件配置)。新的pr里我把转换这一步也放在rocketmqUtils里了
##########
eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/model/TopicProperties.java:
##########
@@ -17,24 +17,17 @@
package org.apache.eventmesh.dashboard.common.model;
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.rocketmq.common.TopicConfig;
+
+import lombok.Data;
/**
* One record displayed in 'Topic' page.
*/
+@Data
public class TopicProperties {
- public String name;
- public long messageCount;
+ private TopicConfig rocketmqTopicConfig;
- @JsonCreator
- public TopicProperties(
- @JsonProperty("name") String name,
- @JsonProperty("messageCount") long messageCount) {
- super();
- this.name = name;
- this.messageCount = messageCount;
- }
}
Review Comment:
想的是有其他的中间件的Topic的时候可以复用
##########
eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/model/TopicProperties.java:
##########
@@ -17,24 +17,17 @@
package org.apache.eventmesh.dashboard.common.model;
-import com.fasterxml.jackson.annotation.JsonCreator;
-import com.fasterxml.jackson.annotation.JsonProperty;
+import org.apache.rocketmq.common.TopicConfig;
+
+import lombok.Data;
/**
* One record displayed in 'Topic' page.
*/
+@Data
public class TopicProperties {
- public String name;
- public long messageCount;
+ private TopicConfig rocketmqTopicConfig;
- @JsonCreator
- public TopicProperties(
- @JsonProperty("name") String name,
- @JsonProperty("messageCount") long messageCount) {
- super();
- this.name = name;
- this.messageCount = messageCount;
- }
}
Review Comment:
不确定这么写是否优雅,还可以改造
##########
eventmesh-dashboard-common/src/main/java/org/apache/eventmesh/dashboard/common/properties/RocketmqProperties.java:
##########
@@ -0,0 +1,42 @@
+/*
+ * 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.dashboard.common.properties;
+
Review Comment:
如果要让core同时访问到的话 只能放在`service`模块了。
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]