You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/03/22 11:06:27 UTC

[GitHub] [incubator-iotdb] qiaojialin commented on a change in pull request #929: [IOTDB-565] MQTT Protocol Support

qiaojialin commented on a change in pull request #929: [IOTDB-565] MQTT Protocol Support
URL: https://github.com/apache/incubator-iotdb/pull/929#discussion_r396080620
 
 

 ##########
 File path: mqtt/src/main/java/org/apache/iotdb/mqtt/PublishHandler.java
 ##########
 @@ -0,0 +1,93 @@
+/*
+ * 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.iotdb.mqtt;
+
+import io.moquette.interception.AbstractInterceptHandler;
+import io.moquette.interception.messages.InterceptPublishMessage;
+import io.netty.buffer.ByteBuf;
+import io.netty.handler.codec.mqtt.MqttQoS;
+import org.apache.iotdb.service.rpc.thrift.TSStatus;
+import org.apache.iotdb.session.IoTDBSessionException;
+import org.apache.iotdb.session.Session;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * PublishHandler handle the messages from MQTT clients.
+ */
+public class PublishHandler extends AbstractInterceptHandler {
+    private static final Logger LOG = LoggerFactory.getLogger(PublishHandler.class);
+
+    private Session session;
+    private PayloadFormatter payloadFormat;
+    static boolean testing = false;
+
+    public PublishHandler(MQTTBrokerConfig config) {
+        payloadFormat = PayloadFormatManager.getPayloadFormat(config.getPayloadFormatter());
+        initSession(config);
+    }
+
+    public void initSession(MQTTBrokerConfig config) {
+        if (testing) {
+            return;
+        }
+        session = new Session(config.getIotDBHost(), config.getIotDBPort(),
+                config.getIotDBUsername(), config.getIotDBPassword());
+        try {
+            session.open();
+        } catch (IoTDBSessionException e) {
 
 Review comment:
   Hi, the IoTDBSessionException is replaced by StatementExecuteException and IoTDBConnectionException

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services