Plugin Design

cranehovers edited this page Dec 7, 2015 · 12 revisions

Overview

Notice that 0.11.0 release use rebar to manage plugin's deps.

A plugin is just an erlang application that extends emqttd broker.

The plugin application should be put in "emqttd/plugins/" folder to build.

Plugin Project

You could create a standalone plugin project outside emqttd, and then add it to "emqttd/plugins/" folder by "git submodule".

Git submodule to compile emqttd_dashboard plugin with the broker, For example:

git submodule add https://github.com/emqtt/emqttd_dashboard.git plugins/emqttd_dashboard
make && make dist

plugin.config

Each plugin should have a 'etc/plugin.config' file

For example, project structure of emqttd_dashboard plugin:

 LICENSE
 README.md
 ebin
 etc
 priv
 rebar.config
 src

etc/plugin.config for emqttd_dashboard plugin:

[
  {emqttd_dashboard, [
    {listener,
        {emqttd_dashboard, 18083, [
            {acceptors, 4},
            {max_clients, 512}]}}
  ]}
].

rebar.config

Plugin should use 'rebar.config' to manage depencies

emqttd_plugin_pgsql plugin's rebar.config, for example:

%% -*- erlang -*-

{deps, [
    {epgsql, ".*",{git, "https://github.com/epgsql/epgsql.git", {branch, "master"}}}
]}.

Build emqttd with plugins

Put all the plugins you required in 'plugins/' folder of emqttd project, and then:

make && make dist

Load Plugin

'./bin/emqttd_ctl' to load/unload plugin, when emqttd broker started.

./bin/emqttd_ctl plugins load emqttd_plugin_demo

./bin/emqttd_ctl plugins unload emqttd_plugin_demo

List Plugins

./bin/emqttd_ctl plugins list

API

%% Load all active plugins after broker started
emqttd_plugins:load() 

%% Load new plugin
emqttd_plugins:load(Name)

%% Unload all active plugins before broker stopped
emqttd_plugins:unload()

%% Unload a plugin
emqttd_plugins:unload(Name)
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.