How to config and get value in plugin emqx

217 Views Asked by At

i'm using emqx v5 to pub,sub, connect, v.v.. Meanwhile, I've been developing my plugin and plugin template from this.

Normally, in emqx-plugin-template.erl, i declare my constant like this

enter image description here

and i can use it from all funtion in this file. But now i want to save them in pri/config.hocon and get them to use similarly. This is structure of plugin

enter image description here

I'm having a hard time figuring out how to get them out and how to declare them so I can use them in as many functions as before. Please guide me.

I try: hocon:load(file name) and maps:get(key, Config) but is is match to a file in emqx/_build/emqx/rel/emqx/config.hocon (this is server emqx)..ít's work but that's not what I want because the author of the template already has pri/config.hocon available and i just want to touch my plugin not eqmx server

1

There are 1 best solutions below

0
user1515605 On

There are three options

  1. Put the config somewhere outside of emqx release directory, and use absolute path in the hocon:load call
  2. Call code:priv_dir(emqx_plugin_messenger) to get the path of your app's priv directory
  3. Put the config in EMQX data/ directory, and call emqx:data_dir() to get it.