emqx / emqx-plugin-template

EMQX Plugin Template and Demo
https://www.emqx.io
Apache License 2.0
73 stars 71 forks source link

how to get config saved in pri/config.hocon #108

Closed AnhNH143 closed 1 year ago

AnhNH143 commented 1 year ago

This is my config.hocon file { "topic" = "mqtt_presence", "port" = 9092 }

How do i can get them to emqx-plugin-messenger.erl to use as define variables

AnhNH143 commented 1 year ago

@HJianBo can you help me ?plz

MikeDombo commented 1 year ago

How do you read the configuration properly from an emqx plugin?

zmstone commented 10 months ago

EMQX v5 plugins so far (5.5) has to manage configs independently. Meaning the configs do not have to be of hocon format, but it's recommended to use hocon.

Plugins can store their configs in the priv directory, and load the configs in app start function.

arvindh123 commented 9 months ago

@zmstone @AnhNH143

How to set plugin specific configuration value ?, In which file it need to be set?, and How to access them in plugin .erl file ?, Is there any example.

application:get_all_env() is always empty. I could not read the configuration value of myserver in plugin

## NOTE:
## This config file overrides data/configs/cluster.hocon,
## and is merged with environment variables which start with 'EMQX_' prefix.
##
## Config changes made from EMQX dashboard UI, management HTTP API, or CLI
## are stored in data/configs/cluster.hocon.
## To avoid confusion, please do not store the same configs in both files.
##
## See https://www.emqx.io/docs/en/v5.0/configuration/configuration.html for more details.
## Configuration full example can be found in etc/examples

node {
  name = "emqx@127.0.0.1"
  cookie = "emqxsecretcookie"
  data_dir = "data"
}

cluster {
  name = emqxcl
  discovery_strategy = manual
}

dashboard {
    listeners.http {
        bind = 18083
    }
}

myserver.listeners {
    http {
        port = 8080
    }
    https {
        port = 8083
        ssl {
            cacertfile = "config/ssl/ca.pem"
            keyfile = "config/ssl/server.key"
            certfile = "config/ssl/server.pem"
        }
    }
}
myserver.concurrent_users_limit=1000
zmstone commented 9 months ago

Hi @arvindh123

You cannot add plugin configs to emqx's hocon config file. The suggested solution for now is for your application to load config from it's priv dir (or a known dir), for example:

{ok, MyConfig} = hocon:load("/opt/emqx/etc/myplugin.hocon"),
persistent_term:put(myplugin_config, MyConfig).