duhenglucky commented on a change in pull request #733: [ISSUE #730]refactor Remoting module to support mqtt encode/decode and implement part of logic of mqtt CONNECT request URL: https://github.com/apache/rocketmq/pull/733#discussion_r252094640
########## File path: remoting/src/main/java/org/apache/rocketmq/remoting/transport/mqtt/Mqtt2RemotingCommandHandler.java ########## @@ -0,0 +1,106 @@ +/* + * 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.remoting.transport.mqtt; + +import com.alibaba.fastjson.JSON; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageDecoder; +import io.netty.handler.codec.mqtt.MqttConnectMessage; +import io.netty.handler.codec.mqtt.MqttConnectVariableHeader; +import io.netty.handler.codec.mqtt.MqttFixedHeader; +import io.netty.handler.codec.mqtt.MqttMessage; +import java.nio.charset.Charset; +import java.util.List; +import org.apache.rocketmq.remoting.common.RemotingUtil; +import org.apache.rocketmq.remoting.protocol.RemotingCommand; + +public class Mqtt2RemotingCommandHandler extends MessageToMessageDecoder<MqttMessage> { + + /** + * Decode from one message to an other. This method will be called for each written message that + * can be handled by this encoder. + * + * @param ctx the {@link ChannelHandlerContext} which this {@link MessageToMessageDecoder} + * belongs to + * @param msg the message to decode to an other one + * @param out the {@link List} to which decoded messages should be added + * @throws Exception is thrown if an error occurs + */ + @Override + protected void decode(ChannelHandlerContext ctx, MqttMessage msg, List<Object> out) + throws Exception { + if (!(msg instanceof MqttMessage)) { + return; + } + RemotingCommand requestCommand = null; + MqttFixedHeader mqttFixedHeader = msg.fixedHeader(); + Object variableHeader = msg.variableHeader(); + + switch (msg.fixedHeader().messageType()) { Review comment: It would be nice if we can abstract a dispatch class to resolve these different MQTT messages. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services