1

我使用 emqttd-windows 10-v2.3.11

我想在 EMQTT 中加载自定义插件。

我把插件文件放在EMQTT\emqttd-windows10-v2.3.11\emqttd\lib目录下,配置文件放在EMQTT\emqttd-windows 10-v2.3.11\emqttd\etc\plugins目录下。

在 CMD 中执行命令“.binemqttd 控制台”启动 EMQ 时出现以下错误。错误可能意味着 EMQTT 在插件中找不到新变量。

D:\softwareBag\EMQTT\emqttd-windows10-v2.3.11\emqttd>.\bin\emqttd console
21:47:46.858 [error] You've tried to set wunaozai.auth.redis.server, but there is no setting with that name.
21:47:46.858 [error]   Did you mean one of these?
21:47:46.906 [error]     auth.redis.server
21:47:46.906 [error]     auth.ldap.servers
21:47:46.906 [error]     auth.mongo.server
21:47:46.906 [error] You've tried to set wunaozai.auth.redis.pool, but there is no setting with that name.
21:47:46.906 [error]   Did you mean one of these?
21:47:46.948 [error]     auth.redis.pool
21:47:46.948 [error]     auth.mongo.pool
21:47:46.948 [error]     auth.mysql.pool
21:47:46.949 [error] You've tried to set wunaozai.auth.redis.database, but there is no setting with that name.
21:47:46.949 [error]   Did you mean one of these?
21:47:46.994 [error]     auth.redis.database
21:47:46.994 [error]     auth.mongo.database
21:47:46.994 [error]     auth.mysql.database
21:47:46.995 [error] You've tried to set wunaozai.auth.redis.auth_cmd, but there is no setting with that name.
21:47:46.995 [error]   Did you mean one of these?
21:47:47.056 [error]     auth.redis.auth_cmd
21:47:47.056 [error]     auth.redis.acl_cmd
21:47:47.056 [error]     auth.redis.super_cmd
21:47:47.056 [error] You've tried to set wunaozai.auth.redis.password_hash, but there is no setting with that name.
21:47:47.057 [error]   Did you mean one of these?
21:47:47.130 [error]     auth.redis.password_hash
21:47:47.130 [error]     auth.ldap.password_hash
21:47:47.130 [error]     auth.mongo.auth_query.password_hash
21:47:47.130 [error] You've tried to set wunaozai.auth.redis.super_cmd, but there is no setting with that name.
21:47:47.130 [error]   Did you mean one of these?
21:47:47.202 [error]     auth.redis.super_cmd
21:47:47.202 [error]     auth.redis.auth_cmd
21:47:47.202 [error]     auth.redis.acl_cmd
21:47:47.202 [error] You've tried to set wunaozai.auth.redis.acl_cmd, but there is no setting with that name.
21:47:47.202 [error]   Did you mean one of these?
21:47:47.266 [error]     auth.redis.acl_cmd
21:47:47.266 [error]     auth.redis.auth_cmd
21:47:47.266 [error]     auth.redis.super_cmd
21:47:47.267 [error] You've tried to set wunaozai.msg.kafka.server, but there is no setting with that name.
21:47:47.267 [error]   Did you mean one of these?
21:47:47.328 [error]     auth.mongo.server
21:47:47.328 [error]     auth.mysql.server
21:47:47.328 [error]     auth.pgsql.server
21:47:47.336 [error] Error generating configuration in phase transform_datatypes
21:47:47.336 [error] Conf file attempted to set unknown variable: wunaozai.msg.kafka.server
21:47:47.336 [error] Conf file attempted to set unknown variable: wunaozai.auth.redis.acl_cmd
21:47:47.336 [error] Conf file attempted to set unknown variable: wunaozai.auth.redis.super_cmd
21:47:47.336 [error] Conf file attempted to set unknown variable: wunaozai.auth.redis.password_hash
21:47:47.336 [error] Conf file attempted to set unknown variable: wunaozai.auth.redis.auth_cmd
21:47:47.336 [error] Conf file attempted to set unknown variable: wunaozai.auth.redis.database
21:47:47.336 [error] Conf file attempted to set unknown variable: wunaozai.auth.redis.pool
21:47:47.336 [error] Conf file attempted to set unknown variable: wunaozai.auth.redis.server

咨询过EMQTT客服,他们说插件配置文件和配置文件解析文件schema不对,不知道是什么问题。

以下是我的插件配置文件(.conf)的内容

## redis config
wunaozai.auth.redis.server = 127.0.0.1:6379
wunaozai.auth.redis.pool = 8
wunaozai.auth.redis.database = 0
##wunaozai.auth.redis.password =
wunaozai.auth.redis.auth_cmd = HMGET mqtt_user:%u password
wunaozai.auth.redis.password_hash = plain
wunaozai.auth.redis.super_cmd = HGET mqtt_user:%u is_superuser
wunaozai.auth.redis.acl_cmd = HGETALL mqtt_acl:%u
## kafka config
wunaozai.msg.kafka.server = 127.0.0.1:9092
##wunaozai.msg.kafka.topic = test

以下是我的插件配置文件解析文件(.schema)的内容

%% emq_auth_pgsl config mapping

{mapping, "auth.pgsql.server", "emq_auth_pgsql.server", [
  {default, {"127.0.0.1", 5432}},
  {datatype, [integer, ip, string]}
]}.

{mapping, "auth.pgsql.pool", "emq_auth_pgsql.server", [
  {default, 8},
  {datatype, integer}
]}.

{mapping, "auth.pgsql.database", "emq_auth_pgsql.server", [
  {datatype, string}
]}.

{mapping, "auth.pgsql.username", "emq_auth_pgsql.server", [
  {default, ""},
  {datatype, string}
]}.

{mapping, "auth.pgsql.password", "emq_auth_pgsql.server", [
  {default, ""},
  {datatype, string}
]}.

{mapping, "auth.pgsql.encoding", "emq_auth_pgsql.server", [
  {default, utf8},
  {datatype, atom}
]}.

{mapping, "auth.pgsql.ssl", "emq_auth_pgsql.server", [
  {default, false},
  {datatype, {enum, [true, false]}}
]}.

{mapping, "auth.pgsql.ssl_opts.keyfile", "emq_auth_pgsql.server", [
  {datatype, string}
]}.

{mapping, "auth.pgsql.ssl_opts.certfile", "emq_auth_pgsql.server", [
  {datatype, string}
]}.

{mapping, "auth.pgsql.ssl_opts.cacertfile", "emq_auth_pgsql.server", [
  {datatype, string}
]}.

{translation, "emq_auth_pgsql.server", fun(Conf) ->
  {PgHost, PgPort} =
  case cuttlefish:conf_get("auth.pgsql.server", Conf) of
    {Ip, Port} -> {Ip, Port};
    S          -> case string:tokens(S, ":") of
                    [Domain]       -> {Domain, 5432};
                    [Domain, Port] -> {Domain, list_to_integer(Port)}
                  end
    end,
  Pool = cuttlefish:conf_get("auth.pgsql.pool", Conf),
  Username = cuttlefish:conf_get("auth.pgsql.username", Conf),
  Passwd = cuttlefish:conf_get("auth.pgsql.password", Conf, ""),
  DB = cuttlefish:conf_get("auth.pgsql.database", Conf),
  Encoding = cuttlefish:conf_get("auth.pgsql.encoding", Conf),
  Ssl = cuttlefish:conf_get("auth.pgsql.ssl", Conf),

  Filter  = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end,
  SslOpts = fun(Prefix) ->
                Filter([{keyfile,    cuttlefish:conf_get(Prefix ++ ".keyfile", Conf, undefined)},
                        {certfile,   cuttlefish:conf_get(Prefix ++ ".certfile", Conf, undefined)},
                        {cacertfile, cuttlefish:conf_get(Prefix ++ ".cacertfile", Conf, undefined)}])
            end,
  [{pool_size, Pool},
   {auto_reconnect, 1},
   {host, PgHost},
   {port, PgPort},
   {username, Username},
   {password, Passwd},
   {database, DB},
   {encoding, Encoding},
   {ssl, Ssl},
   {ssl_opts, SslOpts("auth.pgsql.ssl_opts")}]
end}.

{mapping, "auth.pgsql.auth_query", "emq_auth_pgsql.auth_query", [
  {datatype, string}
]}.

{mapping, "auth.pgsql.password_hash", "emq_auth_pgsql.password_hash", [
  {datatype, string}
]}.

{mapping, "auth.pgsql.pbkdf2_macfun", "emq_auth_pgsql.pbkdf2_macfun", [
  {datatype, atom}
]}.

{mapping, "auth.pgsql.pbkdf2_iterations", "emq_auth_pgsql.pbkdf2_iterations", [
  {datatype, integer}
]}.

{mapping, "auth.pgsql.pbkdf2_dklen", "emq_auth_pgsql.pbkdf2_dklen", [
  {datatype, integer}
]}.

{mapping, "auth.pgsql.super_query", "emq_auth_pgsql.super_query", [
  {datatype, string}
]}.

{mapping, "auth.pgsql.acl_query", "emq_auth_pgsql.acl_query", [
  {datatype, string}
]}.

{translation, "emq_auth_pgsql.password_hash", fun(Conf) ->
  HashValue = cuttlefish:conf_get("auth.pgsql.password_hash", Conf),
  case string:tokens(HashValue, ",") of
    [Hash]           -> list_to_atom(Hash);
    [Prefix, Suffix] -> {list_to_atom(Prefix), list_to_atom(Suffix)};
    [Hash, MacFun, Iterations, Dklen] -> {list_to_atom(Hash), list_to_atom(MacFun), list_to_integer(Iterations), list_to_integer(Dklen)};
    _                -> plain
  end
end}.

插件完整代码:https ://files.cnblogs.com/files/wunaozai/emq_plugin_wunaozai.zip

我希望插件在执行命令“.\bin\emqttd console”时正确加载

4

1 回答 1

0

您的 .schema 文件中应该有一个条目wunaozai.auth.redis.server

在https://github.com/emqx/emqx/issues发布此类问题会得到更快的回答。

于 2019-08-31T08:11:47.103 回答