我的mqtt协议和emqttd开源项目个人理解(5) - hook的使用,源码分析

学习mqtt协议和emqttd开源项目http://emqtt.com/

emqttd源码版本号是v1.1.3。http://emqtt.com/downloads/1113


1、-module(emqttd_app).

start(_StartType, _StartArgs) ->
load_all_mods(),


2、读取emqttd.config文件,modules字段

%% Modules
    {modules, [
        %% Client presence management module.
        %% Publish messages when client connected or disconnected
        {presence, [{qos, 0}]},
 
        %% Subscribe topics automatically when client connected
        {subscription, [
 
            %% $c will be replaced by clientid
            %% {"$queue/clients/$c", 1},
 
            %% Static subscriptions from backend
            backend
        ]}
 
        %% Rewrite rules
        %% {rewrite, [{file, "etc/rewrite.config"}]}
    ]},

3、加载

-module(emqttd_mod_presence).

l

load(Opts) ->
    emqttd:hook('client.connected', fun ?MODULE:on_client_connected/3, [Opts]),
    emqttd:hook('client.disconnected', fun ?MODULE:on_client_disconnected/3, [Opts]).

具体某个节点的某个clientId方式的主题是:

$SYS/brokers/emqttd@172.16.6.161/clients/861694030142478/connected

$SYS/brokers/emqttd@172.16.6.161/clients/861694030142478/disconnected



-module(emqttd_mod_subscription).

load(Opts) ->  



上一篇:《TCP/IP详解卷1》学习小结(一)------链接层


下一篇:Gradle2.0用户指南翻译——第九章. Groovy 快速入门