private static void buildMqttPluginMap() throws IOException {
    ServiceLoader<PayloadFormatter> payloadFormatters = ServiceLoader.load(PayloadFormatter.class);
    for (PayloadFormatter formatter : payloadFormatters) {
      if (formatter == null) {
        logger.error("PayloadFormatManager(), formatter is null.");
        continue;
      }

      String pluginName = formatter.getName();
      mqttPayloadPluginMap.put(pluginName, formatter);
      logger.info("PayloadFormatManager(), find MQTT Payload Plugin {}.", pluginName);
    }

    URL[] jarURLs = getPluginJarURLs(mqttDir);
    logger.debug("MQTT Plugin jarURLs: {}", Arrays.toString(jarURLs));

    for (URL jarUrl : jarURLs) {
      ClassLoader classLoader = new URLClassLoader(new URL[] {jarUrl});

      // Use SPI to get all plugins' class
      ServiceLoader<PayloadFormatter> payloadFormatters2 =
          ServiceLoader.load(PayloadFormatter.class, classLoader);

      for (PayloadFormatter formatter : payloadFormatters2) {
        if (formatter == null) {
          logger.error("PayloadFormatManager(), formatter is null.");
          continue;
        }

        String pluginName = formatter.getName();
        if (mqttPayloadPluginMap.containsKey(pluginName)) {
          continue;
        }
        mqttPayloadPluginMap.put(pluginName, formatter);
        logger.info("PayloadFormatManager(), find MQTT Payload Plugin {}.", pluginName);
      }
    }
  }
PayloadFormatManager loads payload formatter from SPI services.
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/mqtt/PayloadFormatManager.java