EMQX5.0.4 ExHook连接报错问题,unknown_hookpoint如何解决

环境信息

  • EMQX 版本:5.0.4
  • 操作系统及版本:win10专业版
  • 其他

问题描述

按照官方说明,运行https://github.com/emqx/emqx-extension-examples/tree/for-emqx-v5.0/exhook-svr-java ,运行起来后添加到emqx的后台管理中的 ExHook中,exhook-svr-java 中可打印onProviderLoaded类型的消息:
onProviderLoaded, request: broker {
version: “5.0.4”
sysdescr: “EMQX”
uptime: 1969325
datetime: “1970-07-12T13:04:23.592869871+08:00”
}
meta {
node: “emqx@127.0.0.1
version: “5.0.4”
sysdescr: “EMQX”
cluster_name: “emqxcl”
}

但是emqx后台一直显示连接中且日志有报错。

配置文件及日志

image

报错日志如下:
2022-08-17T11:22:19.362000+08:00 [error] channel_name: <<“hook1”>>, line: 209, mfa: emqx_exhook_server:do_init/2, msg: failed_to_init_channel, reason: {unknown_hookpoint,{error,badarg}}, stacktrace: [{emqx_exhook_server,’-resolve_hookspec/1-fun-0-’,2,[{file,“emqx_exhook_server.erl”},{line,234}]},{lists,foldr,3,[{file,“lists.erl”},{line,1280}]},{emqx_exhook_server,do_init,2,[{file,“emqx_exhook_server.erl”},{line,201}]},{emqx_exhook_server,load,2,[{file,“emqx_exhook_server.erl”},{line,107}]},{emqx_exhook_mgr,do_load_server,1,[{file,“emqx_exhook_mgr.erl”},{line,325}]},{emqx_exhook_mgr,do_load_server,2,[{file,“emqx_exhook_mgr.erl”},{line,349}]},{emqx_exhook_mgr,handle_info,2,[{file,“emqx_exhook_mgr.erl”},{line,291}]},{gen_server,try_dispatch,4,[{file,“gen_server.erl”},{line,695}]},{gen_server,handle_msg,6,[{file,“gen_server.erl”},{line,771}]},{proc_lib,init_p_do_apply,3,[{file,“proc_lib.erl”},{line,226}]}]
2022-08-17T11:22:19.363000+08:00 [error] line: 338, mfa: emqx_exhook_mgr:do_load_server/1, msg: failed_to_load_exhook_callback_server, name: <<“hook1”>>, reason: {unknown_hookpoint,{error,badarg}}

支持的 HootPoint 一共有这些,检查一下是不是写错了:

[
‘message.publish’,
‘message.delivered’,
‘message.acked’,
‘message.dropped’,
‘client.connect’,
‘client.connack’,
‘client.connected’,
‘client.disconnected’,
‘client.authenticate’,
‘client.authorize’,
‘client.subscribe’,
‘client.unsubscribe’,
‘session.created’,
‘session.subscribed’,
‘session.unsubscribed’,
‘session.resumed’,
‘session.discarded’,
‘session.takenover’,
‘session.terminated’
].

可以正常连接了。麻烦再问个问题,我想通过ExHook获取message.publish到message.acked的时间差来计算消息延迟。发送测试消息报文如下:

onMessagePublish, request: message {
  node: "emqx@127.0.0.1"
  id: "0005E66BAF395A85F44200000A1C0003"
  qos: 1
  from: "paho-84121774890800"
  topic: "test"
  payload: "1111111"
  timestamp: 1660725059213
  headers {
    key: "peerhost"
    value: "10.20.30.125"
  }
  headers {
    key: "protocol"
    value: "mqtt"
  }
  headers {
    key: "username"
    value: "admin"
  }
}
meta {
  node: "emqx@127.0.0.1"
  version: "5.0.4"
  sysdescr: "EMQX"
  cluster_name: "emqxcl"
}
onMessageDelivered, request: clientinfo {
  node: "emqx@127.0.0.1"
  clientid: "paho-84121774890800"
  username: "admin"
  peerhost: "10.20.30.125"
  sockport: 1883
  protocol: "mqtt"
  anonymous: true
}
message {
  node: "emqx@127.0.0.1"
  id: "0005E66BAF395A85F44200000A1C0003"
  qos: 1
  from: "paho-84121774890800"
  topic: "test"
  payload: "1111111"
  timestamp: 1660725059213
  headers {
    key: "peerhost"
    value: "10.20.30.125"
  }
  headers {
    key: "protocol"
    value: "mqtt"
  }
  headers {
    key: "username"
    value: "admin"
  }
}
meta {
  node: "emqx@127.0.0.1"
  version: "5.0.4"
  sysdescr: "EMQX"
  cluster_name: "emqxcl"
}
onMessageAcked, request: clientinfo {
  node: "emqx@127.0.0.1"
  clientid: "paho-84121774890800"
  username: "admin"
  peerhost: "10.20.30.125"
  sockport: 1883
  protocol: "mqtt"
  anonymous: true
}
message {
  node: "emqx@127.0.0.1"
  id: "0005E66BAF395A85F44200000A1C0003"
  qos: 1
  from: "paho-84121774890800"
  topic: "test"
  payload: "1111111"
  timestamp: 1660725059213
  headers {
    key: "peerhost"
    value: "10.20.30.125"
  }
  headers {
    key: "protocol"
    value: "mqtt"
  }
  headers {
    key: "username"
    value: "admin"
  }
}
meta {
  node: "emqx@127.0.0.1"
  version: "5.0.4"
  sysdescr: "EMQX"
  cluster_name: "emqxcl"
}

发现报文中 message.publish、message.delivered、message.acked 的时间戳都是,timestamp: 1660725059213。想问一下这里的时间戳具体是什么时间呢?有没有什么手段获取消息发送的延迟呢?

timestamp 就是消息到达 emqx 的时间了。延迟还没有办法追踪。

但是看日志只有一个clientId连接,没其他客户端用这个clientID,请问有没有好的处理方法,我用MQTTX连是可以的