1
0
mirror of https://github.com/mainflux/mainflux.git synced 2024-11-20 22:42:14 +08:00
Mainflux.mainflux/mqtt/verne
Drasko DRASKOVIC 5834d364ad Fix Redis event naming (#996)
Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
2020-01-09 14:18:23 +01:00
..
src Fix Redis event naming (#996) 2020-01-09 14:18:23 +01:00
.gitignore NOISSUE - Clean NginX files, move .gitignores to dirs (#853) 2019-09-16 11:47:34 +02:00
Dockerfile NOISSUE - Add docker-compose for MQTT cluster (#841) 2019-09-12 16:55:24 +02:00
README.md Fix doc for ENV vars in README (#920) 2019-10-29 21:28:59 +01:00
rebar3 NOISSUE - Add VerneMQ support (#809) 2019-08-01 12:40:49 +02:00
rebar.config NOISSUE - Add Redis ES Username/Pass for VerneMQ (#991) 2019-12-23 00:17:39 +01:00

MQTT adapter

MQTT adapter provides an MQTT API for sending and receiving messages through the platform.

Configuration

The service is configured using the environment variables presented in the following table. Note that any unset variables will be replaced with their default values.

Variable Description Default
MF_NATS_URL NATS instance URL nats://localhost:4222
MF_THINGS_AUTH_GRPC_URL Things service gRPC URL for Auth tcp://localhost:8183
MF_MQTT_ADAPTER_ES_URL Redis ES URL http://localhost:6379
MF_MQTT_VERNEMQ_GRPC_POOL_SIZE Number of processes to do gRPC comm 10

Apart from this, VerneMQ configuration found here can be customized.

When run in the Docker,

DOCKER_VERNEMQ_PLUGINS__VMQ_PASSWD: "off"
DOCKER_VERNEMQ_PLUGINS__VMQ_ACL: "off"
DOCKER_VERNEMQ_PLUGINS__MFX_AUTH: "on"
DOCKER_VERNEMQ_PLUGINS__MFX_AUTH__PATH: /mainflux/_build/default
DOCKER_VERNEMQ_LISTENER__WS__DEFAULT: "127.0.0.1:8880"

N.B. in this Docker env var setup, __ replaces . in the config file, so plugins.mfx_auth.path becomes DOCKER_VERNEMQ_PLUGINS__MFX_AUTH__PATH

Deployment

Docker

The service is distributed as Docker container. The following snippet provides a compose file template that can be used to deploy the service container locally:

version: "2"
services:
  mqtt-adapter:
      image: mainflux/mqtt:latest
      container_name: mainflux-mqtt
      depends_on:
        - things
        - nats
        - mqtt-redis
      restart: on-failure
      environment:
        MF_MQTT_ADAPTER_LOG_LEVEL: ${MF_MQTT_ADAPTER_LOG_LEVEL}
        MF_MQTT_INSTANCE_ID: mqtt-adapter
        MF_MQTT_ADAPTER_PORT: ${MF_MQTT_ADAPTER_PORT}
        MF_MQTT_ADAPTER_WS_PORT: ${MF_MQTT_ADAPTER_WS_PORT}
        MF_MQTT_ADAPTER_REDIS_URL: tcp://mqtt-redis:${MF_REDIS_TCP_PORT}
        MF_MQTT_ADAPTER_ES_URL: tcp://es-redis:${MF_REDIS_TCP_PORT}
        MF_NATS_URL: ${MF_NATS_URL}
        MF_THINGS_AUTH_HTTP_URL: http://things:${MF_THINGS_AUTH_HTTP_PORT}
        DOCKER_VERNEMQ_PLUGINS__VMQ_PASSWD: "off"
        DOCKER_VERNEMQ_PLUGINS__VMQ_ACL: "off"
        DOCKER_VERNEMQ_PLUGINS__MFX_AUTH: "on"
        DOCKER_VERNEMQ_PLUGINS__MFX_AUTH__PATH: /mainflux/_build/default
        DOCKER_VERNEMQ_LISTENER__WS__DEFAULT: "127.0.0.1:8880"
      ports:
        - ${MF_MQTT_ADAPTER_PORT}:${MF_MQTT_ADAPTER_PORT}
        - ${MF_MQTT_ADAPTER_WS_PORT}:${MF_MQTT_ADAPTER_WS_PORT}
      networks:
        - mainflux-base-net

Native

Generate protobuf files

mkdir -p src/protos
rebar3 grpc gen

Compile

./rebar3 compile

Load Plugin

First start VerneMQ broker:

cd $VERNEMQ_BROKER_PATH
./_build/default/rel/vernemq/bin/vernemq start

Remove other plugins:

cd $VERNEMQ_BROKER_PATH
./_build/default/rel/vernemq/bin/vmq-admin plugin disable -n vmq_passwd
./_build/default/rel/vernemq/bin/vmq-admin plugin disable -n vmq_acl

Enable Mainflux mfx_auth plugin:

cd $VERNEMQ_BROKER_PATH
./_build/default/rel/vernemq/bin/vmq-admin plugin enable -n mfx_auth -p <path_to_mfx_auth_plugin>/_build/default

Debugging

Inspect logs:

cd $VERNEMQ_BROKER_PATH
cat _build/default/rel/vernemq/log/console.log
cat _build/default/rel/vernemq/log/error.log