我自己试了一下,开发非常的丝滑,整个过程就不超过 5 分钟,大部分时间花在下依赖上。
➜ ~ mkdir -p ~/.config/rebar3/templates
➜ ~ pushd ~/.config/rebar3/templates
~/.config/rebar3/templates ~ ~/emqx/emqx-v5 ~/github/emqx-dev/mqttable
➜ templates ls
➜ templates git clone https://github.com/emqx/emqx-plugin-template.git
Cloning into 'emqx-plugin-template'...
remote: Enumerating objects: 1341, done.
remote: Counting objects: 100% (216/216), done.
remote: Compressing objects: 100% (101/101), done.
remote: Total 1341 (delta 132), reused 163 (delta 108), pack-reused 1125 (from 4)
Receiving objects: 100% (1341/1341), 925.34 KiB | 3.32 MiB/s, done.
Resolving deltas: 100% (735/735), done.
➜ templates popd
~ ~/emqx/emqx-v5 ~/github/emqx-dev/mqttable
➜ ~ rebar3 new emqx-plugin my_rabbitmq
===> Writing my_rabbitmq/.tool-versions
===> Writing my_rabbitmq/LICENSE
===> Writing my_rabbitmq/Makefile
===> Writing my_rabbitmq/erlang_ls.config
===> Writing my_rabbitmq/priv/config.hocon.example
===> Writing my_rabbitmq/priv/config_schema.avsc.enterprise.example
===> Writing my_rabbitmq/priv/config_schema.avsc.example
===> Writing my_rabbitmq/priv/config_i18n.json.example
===> Writing my_rabbitmq/scripts/ensure-rebar3.sh
===> Writing my_rabbitmq/scripts/get-otp-vsn.sh
===> Writing my_rabbitmq/.gitignore
===> Writing my_rabbitmq/README.md
===> Writing my_rabbitmq/rebar.config
===> Writing my_rabbitmq/src/my_rabbitmq.app.src
===> Writing my_rabbitmq/src/my_rabbitmq.erl
===> Writing my_rabbitmq/src/my_rabbitmq_app.erl
===> Writing my_rabbitmq/src/my_rabbitmq_cli.erl
===> Writing my_rabbitmq/src/my_rabbitmq_sup.erl
➜ ~ rm -rf my_rabbitmq
➜ ~ rebar3 new emqx-plugin my_rabbitmq_plugin
===> Writing my_rabbitmq_plugin/.tool-versions
===> Writing my_rabbitmq_plugin/LICENSE
===> Writing my_rabbitmq_plugin/Makefile
===> Writing my_rabbitmq_plugin/erlang_ls.config
===> Writing my_rabbitmq_plugin/priv/config.hocon.example
===> Writing my_rabbitmq_plugin/priv/config_schema.avsc.enterprise.example
===> Writing my_rabbitmq_plugin/priv/config_schema.avsc.example
===> Writing my_rabbitmq_plugin/priv/config_i18n.json.example
===> Writing my_rabbitmq_plugin/scripts/ensure-rebar3.sh
===> Writing my_rabbitmq_plugin/scripts/get-otp-vsn.sh
===> Writing my_rabbitmq_plugin/.gitignore
===> Writing my_rabbitmq_plugin/README.md
===> Writing my_rabbitmq_plugin/rebar.config
===> Writing my_rabbitmq_plugin/src/my_rabbitmq_plugin.app.src
===> Writing my_rabbitmq_plugin/src/my_rabbitmq_plugin.erl
===> Writing my_rabbitmq_plugin/src/my_rabbitmq_plugin_app.erl
===> Writing my_rabbitmq_plugin/src/my_rabbitmq_plugin_cli.erl
===> Writing my_rabbitmq_plugin/src/my_rabbitmq_plugin_sup.erl
➜ ~ cd my_rabbitmq_plugin/
➜ my_rabbitmq_plugin make rel
/Library/Developer/CommandLineTools/usr/bin/make ensure-rebar3
downloading rebar3 3.24.0-emqx-1
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 799k 100 799k 0 0 255k 0 0:00:03 0:00:03 --:--:-- 475k
/Users/zw/my_rabbitmq_plugin/rebar3 emqx_plugrel tar
===> Failed to restore /Users/zw/.cache/rebar3/plugins/.rebar3/rebar_compiler_erl/source_apps.dag file. Discarding it.
===> Analyzing applications...
===> Compiling verl
===> Compiling hex_core
===> Compiling rebar3_hex
===> Fetching erlfmt v1.6.0
===> Analyzing applications...
===> Compiling erlfmt
===> Fetching emqx_plugin_helper (from {git,"https://github.com/emqx/emqx-plugin-helper.git",
{tag,"v5.9.0"}})
===> Fetching typerefl (from {git,"https://github.com/ieQu1/typerefl",{tag,"0.9.6"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/ieQu1/typerefl
===> Fetching erlang_qq (from {git,"https://github.com/k32/erlang_qq.git",
{ref,"beab75239f799240397aee0aec30685b9bbf33bb"}})
===> Analyzing applications...
===> Compiling erlang_qq
===> Compiling typerefl
===> Plugin typerefl does not export init/1. It will not be used.
===> Fetching emqx_plugrel (from {git,"https://github.com/emqx/emqx_plugrel.git",
{tag,"0.6.2"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/emqx/emqx_plugrel
===> Fetching erlavro (from {git,"https://github.com/emqx/erlavro.git",
{tag,"2.10.2-emqx-1"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/emqx/erlavro
===> Fetching hocon (from {git,"https://github.com/emqx/hocon.git",{tag,"0.44.0"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/emqx/hocon
===> Fetching getopt v1.0.3
===> Fetching jsone v1.9.0
===> Fetching snappyer v1.2.10
===> Fetching pc v1.15.0
===> Analyzing applications...
===> Compiling pc
===> Compiling c_src/snappy-sinksource.cc
===> Compiling c_src/snappy-stubs-internal.cc
===> Compiling c_src/snappy.cc
===> Compiling c_src/snappyer.cc
===> Linking /Users/zw/my_rabbitmq_plugin/_build/default/plugins/snappyer/priv/snappyer.so
===> Analyzing applications...
===> Compiling jsone
===> Compiling snappyer
===> Compiling erlang_qq
===> Compiling typerefl
===> Compiling getopt
===> Compiling erlavro
===> Compiling hocon
===> Compiling emqx_plugrel
===> Fetching emqx_utils (from {git_subdir,"https://github.com/emqx/emqx.git",
{tag,"e5.9.0"},
"apps/emqx_utils"})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/emqx/emqx
===> Fetching snabbkaffe (from {git,"https://github.com/kafka4beam/snabbkaffe.git",
{tag,"1.0.10"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/kafka4beam/snabbkaffe
===> Fetching emqx_http_lib (from {git,"https://github.com/emqx/emqx_http_lib.git",
{tag,"0.5.3"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/emqx/emqx_http_lib
===> Skipping erlang_qq (from {git,"https://github.com/k32/erlang_qq.git",
{ref,"beab75239f799240397aee0aec30685b9bbf33bb"}}) as an app of the same name has already been fetched
===> Fetching jiffy v1.1.2
===> Skipping typerefl (from {git,"https://github.com/ieQu1/typerefl.git",{tag,"0.9.1"}}) as an app of the same name has already been fetched
===> Analyzing applications...
===> Compiling snabbkaffe
===> Compiling jiffy
===> Compiling emqx_http_lib
===> Compiling emqx_utils
===> Compiling emqx_plugin_helper
===> Compiling c_src/decoder.c
===> Compiling c_src/encoder.c
===> Compiling c_src/jiffy.c
===> Compiling c_src/termstack.c
===> Compiling c_src/utf8.c
===> Compiling c_src/util.c
===> Compiling c_src/doubles.cc
===> Compiling c_src/objects.cc
===> Compiling c_src/double-conversion/bignum-dtoa.cc
===> Compiling c_src/double-conversion/bignum.cc
===> Compiling c_src/double-conversion/cached-powers.cc
===> Compiling c_src/double-conversion/diy-fp.cc
===> Compiling c_src/double-conversion/double-conversion.cc
===> Compiling c_src/double-conversion/fast-dtoa.cc
===> Compiling c_src/double-conversion/fixed-dtoa.cc
===> Compiling c_src/double-conversion/strtod.cc
===> Linking /Users/zw/my_rabbitmq_plugin/_build/default/plugins/jiffy/priv/jiffy.so
===> Plugin emqx_plugin_helper does not export init/1. It will not be used.
===> Skipping erlang_qq (from {git,"https://github.com/k32/erlang_qq.git",
{ref,"beab75239f799240397aee0aec30685b9bbf33bb"}}) as an app of the same name has already been fetched
===> Skipping typerefl (from {git,"https://github.com/ieQu1/typerefl.git",{tag,"0.9.1"}}) as an app of the same name has already been fetched
===> Plugin emqx_plugin_helper does not export init/1. It will not be used.
===> Verifying dependencies...
===> Fetching emqx_plugin_helper (from {git,"https://github.com/emqx/emqx-plugin-helper.git",
{tag,"v5.9.0"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/emqx/emqx-plugin-helper
===> Fetching emqx_utils (from {git_subdir,"https://github.com/emqx/emqx.git",
{tag,"e5.9.0"},
"apps/emqx_utils"})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/emqx/emqx
===> Fetching snabbkaffe (from {git,"https://github.com/kafka4beam/snabbkaffe.git",
{tag,"1.0.10"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/kafka4beam/snabbkaffe
===> Fetching typerefl (from {git,"https://github.com/ieQu1/typerefl",{tag,"0.9.6"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/ieQu1/typerefl
===> Fetching emqx_http_lib (from {git,"https://github.com/emqx/emqx_http_lib.git",
{tag,"0.5.3"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/emqx/emqx_http_lib
===> Fetching erlang_qq (from {git,"https://github.com/k32/erlang_qq.git",{tag,"1.0.0"}})
===> Git reference-cache hit: /Users/zw/.emqx_cache/github.com/k32/erlang_qq
===> Skipping erlang_qq (from {git,"https://github.com/k32/erlang_qq.git",
{ref,"beab75239f799240397aee0aec30685b9bbf33bb"}}) as an app of the same name has already been fetched
===> Fetching jiffy v1.1.2
===> Skipping typerefl (from {git,"https://github.com/ieQu1/typerefl.git",{tag,"0.9.1"}}) as an app of the same name has already been fetched
===> Analyzing applications...
===> Compiling erlang_qq
===> Compiling typerefl
===> Compiling snabbkaffe
===> Compiling jiffy
===> Compiling emqx_http_lib
===> Compiling emqx_utils
===> Compiling emqx_plugin_helper
===> Compiling c_src/decoder.c
===> Compiling c_src/encoder.c
===> Compiling c_src/jiffy.c
===> Compiling c_src/termstack.c
===> Compiling c_src/utf8.c
===> Compiling c_src/util.c
===> Compiling c_src/doubles.cc
===> Compiling c_src/objects.cc
===> Compiling c_src/double-conversion/bignum-dtoa.cc
===> Compiling c_src/double-conversion/bignum.cc
===> Compiling c_src/double-conversion/cached-powers.cc
===> Compiling c_src/double-conversion/diy-fp.cc
===> Compiling c_src/double-conversion/double-conversion.cc
===> Compiling c_src/double-conversion/fast-dtoa.cc
===> Compiling c_src/double-conversion/fixed-dtoa.cc
===> Compiling c_src/double-conversion/strtod.cc
===> Linking /Users/zw/my_rabbitmq_plugin/_build/default/lib/jiffy/priv/jiffy.so
===> Analyzing applications...
===> Compiling my_rabbitmq_plugin
===> Assembling release my_rabbitmq_plugin-1.0.0...
===> There are missing function calls in the release.
===> Make sure all applications needed at runtime are included in the release.
===> my_rabbitmq_plugin:hook/0 calls undefined function emqx_hooks:add/3
===> my_rabbitmq_plugin:on_client_authorize/4 calls undefined function emqx_topic:match/2
===> my_rabbitmq_plugin:on_message_puback/4 calls undefined function emqx_message:to_map/1
===> my_rabbitmq_plugin:unhook/0 calls undefined function emqx_hooks:del/2
===> my_rabbitmq_plugin_app:start/2 calls undefined function emqx_ctl:register_command/2
===> my_rabbitmq_plugin_app:stop/1 calls undefined function emqx_ctl:unregister_command/1
===> my_rabbitmq_plugin_cli:cmd/1 calls undefined function emqx_ctl:print/2
===> my_rabbitmq_plugin_cli:cmd/1 calls undefined function emqx_ctl:usage/1
===> my_rabbitmq_plugin_cli:cmd/1 calls undefined function emqx_utils_json:encode/1
===> Warnings generating release:
*WARNING* Missing application sasl. Can not upgrade with this release
===> Release successfully assembled: _build/default/rel/my_rabbitmq_plugin
===> [emqx_plugrel] Pre-processing to create tarball for my_rabbitmq_plugin-1.0.0
===> [emqx_plugrel] Trying create /Users/zw/my_rabbitmq_plugin/_build/default/emqx_plugrel/my_rabbitmq_plugin-1.0.0.tar.gz
➜ my_rabbitmq_plugin cat .tool-versions
erlang 27.2
elixir 1.18.3-otp-27
重点是要设置对 erlang 的版本,仔细看 Readme,没明白代码结构前,不要强行按自己的想法去改。
对了: 用的是 GitHub - emqx/emqx-plugin-template: EMQX Plugin Template and Demo 的最新 master,里面模版生成的用的是 v5.9.0,只需要一个依赖。
祝你好运