An example Mix project that can be used to build an EMQX 5.7.0 plugin.
-
make
orMIX_ENV=prod mix release --overwrite
-
Copy
_build/prod/plugrelex/elixir_plugin_template/elixir_plugin_template-0.1.0.tar.gz
to theplugins
directory in your EMQX installation. -
emqx ctl plugins install elixir_plugin_template-0.1.0 emqx ctl plugins enable elixir_plugin_template-0.1.0 emqx ctl plugins start elixir_plugin_template-0.1.0
-
In a console in your broker (
emqx remote_console
)::emqx.subscribe("topic") :emqx.publish(:emqx_message.make("topic", "payload"))
You should see your message printed by the plugin.
emqx_msg: %{ extra: [], flags: %{}, from: :undefined, headers: %{}, id: <<0, 5, 216, 140, 219, 62, 202, 170, 244, 66, 0, 0, 10, 211, 0, 0>>, payload: "payload", qos: 0, timestamp: 1645474368899, topic: "topic" }
EMQX 5.7.0 introduced the Avro configuration schema feature which allows plugins to define their own config schema to be used and managed. In order to use this feature:
- Be sure to use EMQX 5.7.0 or newer;
- Rename and edit the following files:
priv/config.hocon.example
->priv/config.hocon
priv/config_i18n.json.example
->priv/config_i18n.json
priv/config_schema.avsc.example
->priv/config_schema.avsc
- Refer to
priv/config_schema.avsc.enterprise.example
if using EMQX Enterprise Edition.
- Refer to
- Set
:with_config_schema?
totrue
under theemqx_plugin_opts
release config inmix.exs
. - Add
:emqx_plugins
as a dependency by uncommenting the line containingemqx_dep.(:emqx_plugins)
inmix.exs
's dependencies.