https://github.com/emqx/emqx-elixir-plugin
An Example Plugin for EMQX in Elixir
https://github.com/emqx/emqx-elixir-plugin
elixir elixir-plugin emqx emqx-plugin
Last synced: 4 months ago
JSON representation
An Example Plugin for EMQX in Elixir
- Host: GitHub
- URL: https://github.com/emqx/emqx-elixir-plugin
- Owner: emqx
- Created: 2017-05-17T03:06:57.000Z (over 8 years ago)
- Default Branch: emqx50
- Last Pushed: 2024-06-18T13:41:22.000Z (over 1 year ago)
- Last Synced: 2025-09-29T22:58:33.574Z (4 months ago)
- Topics: elixir, elixir-plugin, emqx, emqx-plugin
- Language: Elixir
- Homepage: https://emqx.io
- Size: 59.6 KB
- Stars: 24
- Watchers: 22
- Forks: 8
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Example EMQX Elixir Plugin Template
An example Mix project that can be used to build an EMQX 5.7.0 plugin.
## Quickstart
1. `make` or `MIX_ENV=prod mix release --overwrite`
2. Copy `_build/prod/plugrelex/elixir_plugin_template/elixir_plugin_template-0.1.0.tar.gz` to the `plugins` directory in your EMQX installation.
3. ```sh
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
```
4. In a console in your broker (`emqx remote_console`):
```elixir
:emqx.subscribe("topic")
:emqx.publish(:emqx_message.make("topic", "payload"))
```
You should see your message printed by the plugin.
```elixir
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"
}
```
## Custom configuration schema
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.
- Set `:with_config_schema?` to `true` under the `emqx_plugin_opts` release config in
`mix.exs`.
- Add `:emqx_plugins` as a dependency by uncommenting the line containing `emqx_dep.(:emqx_plugins)` in `mix.exs`'s dependencies.