diff --git a/.env b/.env index faed202b..3197d0df 100644 --- a/.env +++ b/.env @@ -196,3 +196,20 @@ MF_POSTGRES_READER_DB_SSL_MODE=disable MF_POSTGRES_READER_DB_SSL_CERT="" MF_POSTGRES_READER_DB_SSL_KEY="" MF_POSTGRES_READER_DB_SSL_ROOT_CERT="" + +# Twins +MF_TWINS_LOG_LEVEL=debug +MF_TWINS_HTTP_PORT=9021 +MF_TWINS_SERVER_CERT="" +MF_TWINS_SERVER_KEY="" +MF_TWINS_DB_NAME=mainflux-twins +MF_TWINS_DB_HOST=twins-db +MF_TWINS_DB_PORT=27018 +MF_TWINS_SINGLE_USER_EMAIL="" +MF_TWINS_SINGLE_USER_TOKEN="" +MF_TWINS_CLIENT_TLS="" +MF_TWINS_CA_CERTS="" +MF_TWINS_MQTT_URL=tcp://mqtt-adapter:1883 +MF_TWINS_THING_ID= +MF_TWINS_THING_KEY= +MF_TWINS_CHANNEL_ID= diff --git a/Makefile b/Makefile index a98b0c52..94451a54 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ BUILD_DIR = build SERVICES = users things http ws coap lora influxdb-writer influxdb-reader mongodb-writer \ mongodb-reader cassandra-writer cassandra-reader postgres-writer postgres-reader cli \ - bootstrap opcua authn + bootstrap opcua authn twins DOCKERS = $(addprefix docker_,$(SERVICES)) DOCKERS_DEV = $(addprefix docker_dev_,$(SERVICES)) CGO_ENABLED ?= 0 diff --git a/docker/addons/twins/docker-compose.yml b/docker/addons/twins/docker-compose.yml new file mode 100644 index 00000000..0ed5679c --- /dev/null +++ b/docker/addons/twins/docker-compose.yml @@ -0,0 +1,56 @@ +# Copyright (c) Mainflux +# SPDX-License-Identifier: Apache-2.0 + +# This docker-compose file contains optional opcua-adapter and opcua-redis services +# for the Mainflux platform. Since this services are optional, this file is dependent on the +# docker-compose.yml file from /docker/. In order to run these services, +# core services, as well as the network from the core composition, should be already running. + +version: "3.7" + +networks: + docker_mainflux-base-net: + external: true + +volumes: + mainflux-twins-db-volume: + mainflux-twins-db-configdb-volume: + +services: + twins-db: + image: mongo:bionic + command: mongod --port ${MF_TWINS_DB_PORT} + container_name: mainflux-twins-db + restart: on-failure + environment: + MONGO_INITDB_DATABASE: ${MF_TWINS_DB_NAME} + ports: + - ${MF_TWINS_DB_PORT}:${MF_TWINS_DB_PORT} + networks: + docker_mainflux-base-net: + volumes: + - mainflux-twins-db-volume:/data/db + - mainflux-twins-db-configdb-volume:/data/configdb + + twins: + image: mainflux/twins:latest + container_name: mainflux-twins + restart: on-failure + environment: + MF_TWINS_LOG_LEVEL: ${MF_TWINS_LOG_LEVEL} + MF_TWINS_HTTP_PORT: ${MF_TWINS_HTTP_PORT} + MF_TWINS_DB_NAME: ${MF_TWINS_DB_NAME} + MF_TWINS_DB_HOST: ${MF_TWINS_DB_HOST} + MF_TWINS_DB_PORT: ${MF_TWINS_DB_PORT} + MF_TWINS_THING_ID: ${MF_TWINS_THING_ID} + MF_TWINS_THING_KEY: ${MF_TWINS_THING_KEY} + MF_TWINS_CHANNEL_ID: ${MF_TWINS_CHANNEL_ID} + MF_NATS_URL: ${MF_NATS_URL} + MF_AUTHN_URL: authn:${MF_AUTHN_GRPC_PORT} + MF_TWINS_MQTT_URL: ${MF_TWINS_MQTT_URL} + ports: + - ${MF_TWINS_HTTP_PORT}:${MF_TWINS_HTTP_PORT} + networks: + docker_mainflux-base-net: + depends_on: + - twins-db diff --git a/twins/README.md b/twins/README.md index b4f8c232..08cd4b92 100644 --- a/twins/README.md +++ b/twins/README.md @@ -92,6 +92,29 @@ MF_TWINS_LOG_LEVEL: [Twins log level] MF_TWINS_HTTP_PORT: [Service HTTP port] MF ## Usage +### Starting twins service + +The twins service publishes notifications on an mqtt topic of the format +`channels//messages//`, where `crudOp` +stands for the crud operation done on twin - create, update, delete or +retrieve - or state - save state. In order to use twin service, one must +inform it - via environment variables - about the Mainflux thing and +channel used for mqtt notification publishing. You can use an already existing +thing and channel - thing has to be connected to channel - or create new ones. + +To set the environment variables, please go to `.env` file and set the following +variables: + +``` +MF_TWINS_THING_ID= +MF_TWINS_THING_KEY= +MF_TWINS_CHANNEL_ID= +``` + +with the corresponding values of the desired thing and channel. If you are +running mainflux natively, than do the same thing in the corresponding console +environment. + For more information about service capabilities and its usage, please check out the [API documentation](swagger.yaml).