RongtongJin commented on code in PR #9549:
URL: https://github.com/apache/rocketmq/pull/9549#discussion_r2331839420
##########
broker/src/main/java/org/apache/rocketmq/broker/topic/TopicConfigManager.java:
##########
@@ -224,9 +225,25 @@ protected void init() {
this.topicConfigTable.put(topicConfig.getTopicName(),
topicConfig);
}
}
+
+ {
+ // TopicValidator.RMQ_ROUTE_EVENT_TOPIC
+ String topic = TopicValidator.RMQ_ROUTE_EVENT_TOPIC;
+ TopicConfig topicConfig = new TopicConfig(topic);
+ TopicValidator.addSystemTopic(topic);
+ topicConfig.setReadQueueNums(1);
+ topicConfig.setWriteQueueNums(1);
+ putTopicConfig(topicConfig);
+ }
}
public TopicConfig putTopicConfig(TopicConfig topicConfig) {
+ if (!TopicValidator.isSystemTopic(topicConfig.getTopicName())) {
Review Comment:
有很多其他地方也会调用到这两个方法(比如复制、初始化等),应该在topic创建和删除的入口做,而不是在底层方法做。
##########
proxy/src/main/java/org/apache/rocketmq/proxy/service/route/RouteEventSubscriber.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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.rocketmq.proxy.service.route;
+
+import java.nio.charset.StandardCharsets;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.function.BiConsumer;
+
+import org.apache.rocketmq.broker.route.RouteEventConstants;
+import org.apache.rocketmq.broker.route.RouteEventType;
+import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
+import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
+import
org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
+import org.apache.rocketmq.client.exception.MQClientException;
+import org.apache.rocketmq.common.constant.LoggerName;
+import org.apache.rocketmq.common.message.MessageExt;
+import org.apache.rocketmq.common.topic.TopicValidator;
+import org.apache.rocketmq.logging.org.slf4j.Logger;
+import org.apache.rocketmq.logging.org.slf4j.LoggerFactory;
+import org.apache.rocketmq.remoting.protocol.heartbeat.MessageModel;
+
+import com.alibaba.fastjson2.JSON;
+
+public class RouteEventSubscriber {
+ private final BiConsumer<String, Long> dirtyMarker;
+ private final TopicRouteService topicRouteService;
+ private final DefaultMQPushConsumer consumer;
+ private static final Logger LOGGER =
LoggerFactory.getLogger(LoggerName.PROXY_LOGGER_NAME);
+
+ public RouteEventSubscriber(TopicRouteService topicRouteService,
BiConsumer<String, Long> dirtyMarker) {
+ this.topicRouteService = topicRouteService;
+ this.dirtyMarker = dirtyMarker;
+ this.consumer = new DefaultMQPushConsumer("PROXY_ROUTE_EVENT_GROUP");
+ this.consumer.setMessageModel(MessageModel.BROADCASTING);
+ }
+ public void start() {
+ try {
+ consumer.subscribe(TopicValidator.RMQ_ROUTE_EVENT_TOPIC, "*");
+ consumer.registerMessageListener((MessageListenerConcurrently)
(msgs, context) -> {
+ processMessages(msgs);
+ return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
+ });
+
+ consumer.start();
+ } catch (MQClientException e) {
+ LOGGER.error("Failed to start route event consumer", e);
+ }
+ }
+
+ private void processMessages(List<MessageExt> msgs) {
+ for (MessageExt msg : msgs) {
+ try {
+ String json = new String(msg.getBody(),
StandardCharsets.UTF_8);
+ Map<String, Object> event = JSON.parseObject(json, Map.class);
+
+ String brokerName = (String)
event.get(RouteEventConstants.BROKER_NAME);
+ RouteEventType eventType = RouteEventType.valueOf((String)
event.get(RouteEventConstants.EVENT_TYPE));
+ Long eventTimeStamp = (Long)
event.get(RouteEventConstants.TIMESTAMP);
+
+
+ switch (eventType) {
+ case SHUTDOWN:
Review Comment:
为什么Start事件不做处理
--
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]