YunaiV/yudao-cloud · error · IllegalArgumentException

[createProtocol][协议实例 %s 的协议类型 %s 暂不支持]

Error message

[createProtocol][协议实例 %s 的协议类型 %s 暂不支持]

What it means

IotProtocolManager.createProtocol switches over the configured protocol type (HTTP, COAP, WEBSOCKET, MQTT, EMQX, MODBUS_TCP_CLIENT, MODBUS_TCP_SERVER) and throws IllegalArgumentException from the default branch when the value is anything else. The protocolType derives from the IoT protocol-instance config in yudao.gateway.properties, so this fires when a config entry's type is misspelled, unknown to this gateway build, or was written by a newer module version.

Source

Thrown at yudao-module-iot/yudao-module-iot-gateway/src/main/java/cn/iocoder/yudao/module/iot/gateway/protocol/IotProtocolManager.java:122

                return createHttpProtocol(config);
            case TCP:
                return createTcpProtocol(config);
            case UDP:
                return createUdpProtocol(config);
            case COAP:
                return createCoapProtocol(config);
            case WEBSOCKET:
                return createWebSocketProtocol(config);
            case MQTT:
                return createMqttProtocol(config);
            case EMQX:
                return createEmqxProtocol(config);
            case MODBUS_TCP_CLIENT:
                return createModbusTcpClientProtocol(config);
            case MODBUS_TCP_SERVER:
                return createModbusTcpServerProtocol(config);
            default:
                throw new IllegalArgumentException(String.format(
                        "[createProtocol][协议实例 %s 的协议类型 %s 暂不支持]", config.getId(), protocolType));
        }
    }

    /**
     * 创建 HTTP 协议实例
     *
     * @param config 协议实例配置
     * @return HTTP 协议实例
     */
    private IotHttpProtocol createHttpProtocol(IotGatewayProperties.ProtocolProperties config) {
        return new IotHttpProtocol(config);
    }

    /**
     * 创建 TCP 协议实例
     *
     * @param config 协议实例配置

View on GitHub (pinned to 477be9dd49)

Solutions

  1. Set type to one of the supported enum values: HTTP, COAP, WEBSOCKET, MQTT, EMQX, MODBUS_TCP_CLIENT, MODBUS_TCP_SERVER
  2. Keep the IoT gateway jar and IoT server module on the same release so the protocol type set matches
  3. Check YAML spelling/case of the type field after editing

Example fix

# before
yudao.gateway.protocols:
  - id: 1
    type: tcp        # unsupported

# after
yudao.gateway.protocols:
  - id: 1
    type: MQTT       # one of HTTP/COAP/WEBSOCKET/MQTT/EMQX/MODBUS_TCP_CLIENT/MODBUS_TCP_SERVER
Defensive patterns

Strategy: type-guard

Validate before calling

Set<String> supported = Set.of("HTTP","COAP","WEBSOCKET","MQTT","EMQX","MODBUS_TCP_CLIENT","MODBUS_TCP_SERVER");
if (!supported.contains(protocolType)) {
    throw new IllegalArgumentException("协议类型必须为 " + supported);
}

Type guard

boolean isSupportedProtocol(String type) {
    return Arrays.stream(IotGatewayProperties.ProtocolProperties.ProtocolType.values())
        .anyMatch(t -> t.name().equalsIgnoreCase(StrUtil.trimToEmpty(type)));
}

Prevention

When it happens

Trigger: yudao.gateway config (or DB-backed protocol instance) with type 'TCP', 'MQTTS', or lowercase 'mqtt' — not matching the enum values; gateway jar older than the IoT server that emitted a new protocol type; YAML typo in the type key.

Common situations: Upgrading the IoT module but not the gateway (or vice versa); hand-editing gateway properties; copying a config example from docs of a different release; enum renamed between versions.

Related errors


AI-assisted analysis of YunaiV/yudao-cloud@477be9dd49 (2026-08-14). Data as JSON: /api/errors/fcc0680e8e41ede1. Report an issue: GitHub.