You can do this by modifying the configuration file.
Emq v1.1.3, rel \ emqttd \ etc \ emqttd config
The ‘Subscription’ extension allows you to automatically subscribe or resume subscribing to certain topics when a client goes live:
%% 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"}]}
]},
Copy the code
In emQ v2.3.11, the software architecture has been adjusted to integrate functions into the EMq_modules module. /data/loaded_plugins load emq_modules by default.
We only need to change the configuration file 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
Copy the code
Set Module. subscription to on,
The module. Subscription. 1. The topic is set to % c/w, % c is wildcard, will automatically switch to clientId. Note that it is %c, not $c.