我的mqtt协议和emqttd开源项目个人理解(22) - 关于客户端上线自动订阅主题

通过修改配置文件即可实现。

 

emq v1.1.3,rel\emqttd\etc\emqttd.config

‘subscription’扩展模块支持客户端上线时,自动订阅或恢复订阅某些主题(Topic):

%% 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},
            {"$c/w", 1}

            %% Static subscriptions from backend
            %%backend
        ]}

        %% Rewrite rules
        %% {rewrite, [{file, "etc/rewrite.config"}]}
    ]},

 

emq v2.3.11,软件架构做了调整,把功能集成在了emq_modules模块,/data/loaded_plugins默认会加载emq_modules。

我们只需要改动配置文件emqx-rel-2.3.11/deps/emq_modules/etc/emq_modules.conf

##--------------------------------------------------------------------
## Subscription Module
##--------------------------------------------------------------------

## Enable Subscription Module.
##
## Value: on | off
module.subscription = on

## Subscribe the Topics automatically when client connected.
module.subscription.1.topic = %c/w
## Qos of the subscription: 0 | 1 | 2
module.subscription.1.qos = 1

把module.subscription设置为on,

把module.subscription.1.topic设置为%c/w,%c是通配符,会自动切换成clientId。注意是%c,而不是$c。

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值