emqx-elixir-plugin icon indicating copy to clipboard operation
emqx-elixir-plugin copied to clipboard

An Example Plugin for EMQX in Elixir

Example EMQX Elixir Plugin Template

An example Mix project that can be used to build an EMQX 5.0.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. 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):

    :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"
    }