package
0.16.0
Repository: https://github.com/absmach/supermq.git
Documentation: pkg.go.dev

# Packages

No description provided by the author
No description provided by the author
No description provided by the author

# README

MQTT adapter

MQTT adapter provides an MQTT API for sending messages through the platform. MQTT adapter uses mProxy for proxying traffic between client and MQTT broker.

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.

VariableDescriptionDefault
SMQ_MQTT_ADAPTER_LOG_LEVELLog level for the MQTT Adapter (debug, info, warn, error)info
SMQ_MQTT_ADAPTER_MQTT_PORTmProxy port1883
SMQ_MQTT_ADAPTER_MQTT_TARGET_HOSTMQTT broker hostlocalhost
SMQ_MQTT_ADAPTER_MQTT_TARGET_PORTMQTT broker port1883
SMQ_MQTT_ADAPTER_MQTT_QOSMQTT broker QoS1
SMQ_MQTT_ADAPTER_FORWARDER_TIMEOUTMQTT forwarder for multiprotocol communication timeout30s
SMQ_MQTT_ADAPTER_MQTT_TARGET_HEALTH_CHECKURL of broker health check""
SMQ_MQTT_ADAPTER_WS_PORTmProxy MQTT over WS port8080
SMQ_MQTT_ADAPTER_WS_TARGET_HOSTMQTT broker host for MQTT over WSlocalhost
SMQ_MQTT_ADAPTER_WS_TARGET_PORTMQTT broker port for MQTT over WS8080
SMQ_MQTT_ADAPTER_WS_TARGET_PATHMQTT broker MQTT over WS path/mqtt
SMQ_MQTT_ADAPTER_INSTANCEInstance name for MQTT adapter""
SMQ_CLIENTS_AUTH_GRPC_URLClients service Auth gRPC URLlocalhost:7000
SMQ_CLIENTS_AUTH_GRPC_TIMEOUTClients service Auth gRPC request timeout in seconds1s
SMQ_CLIENTS_AUTH_GRPC_CLIENT_CERTPath to the PEM encoded clients service Auth gRPC client certificate file""
SMQ_CLIENTS_AUTH_GRPC_CLIENT_KEYPath to the PEM encoded clients service Auth gRPC client key file""
SMQ_CLIENTS_AUTH_GRPC_SERVER_CERTSPath to the PEM encoded clients server Auth gRPC server trusted CA certificate file""
SMQ_ES_URLEvent sourcing URLnats://localhost:4222
SMQ_MESSAGE_BROKER_URLMessage broker instance URLnats://localhost:4222
SMQ_JAEGER_URLJaeger server URLhttp://localhost:4318/v1/traces
SMQ_JAEGER_TRACE_RATIOJaeger sampling ratio1.0
SMQ_SEND_TELEMETRYSend telemetry to supermq call home servertrue
SMQ_MQTT_ADAPTER_INSTANCE_IDService instance ID""

Deployment

The service itself is distributed as Docker container. Check the mqtt-adapter service section in docker-compose file to see how service is deployed.

Running this service outside of container requires working instance of the message broker service, clients service and Jaeger server. To start the service outside of the container, execute the following shell script:

# download the latest version of the service
git clone https://github.com/absmach/supermq

cd supermq

# compile the mqtt
make mqtt

# copy binary to bin
make install

# set the environment variables and run the service
SMQ_MQTT_ADAPTER_LOG_LEVEL=info \
SMQ_MQTT_ADAPTER_MQTT_PORT=1883 \
SMQ_MQTT_ADAPTER_MQTT_TARGET_HOST=localhost \
SMQ_MQTT_ADAPTER_MQTT_TARGET_PORT=1883 \
SMQ_MQTT_ADAPTER_MQTT_QOS=1 \
SMQ_MQTT_ADAPTER_FORWARDER_TIMEOUT=30s \
SMQ_MQTT_ADAPTER_MQTT_TARGET_HEALTH_CHECK="" \
SMQ_MQTT_ADAPTER_WS_PORT=8080 \
SMQ_MQTT_ADAPTER_WS_TARGET_HOST=localhost \
SMQ_MQTT_ADAPTER_WS_TARGET_PORT=8080 \
SMQ_MQTT_ADAPTER_WS_TARGET_PATH=/mqtt \
SMQ_MQTT_ADAPTER_INSTANCE="" \
SMQ_CLIENTS_AUTH_GRPC_URL=localhost:7000 \
SMQ_CLIENTS_AUTH_GRPC_TIMEOUT=1s \
SMQ_CLIENTS_AUTH_GRPC_CLIENT_CERT="" \
SMQ_CLIENTS_AUTH_GRPC_CLIENT_KEY="" \
SMQ_CLIENTS_AUTH_GRPC_SERVER_CERTS="" \
SMQ_ES_URL=nats://localhost:4222 \
SMQ_MESSAGE_BROKER_URL=nats://localhost:4222 \
SMQ_JAEGER_URL=http://localhost:14268/api/traces \
SMQ_JAEGER_TRACE_RATIO=1.0 \
SMQ_SEND_TELEMETRY=true \
SMQ_MQTT_ADAPTER_INSTANCE_ID="" \
$GOBIN/supermq-mqtt

Setting SMQ_CLIENTS_AUTH_GRPC_CLIENT_CERT and SMQ_CLIENTS_AUTH_GRPC_CLIENT_KEY will enable TLS against the clients service. The service expects a file in PEM format for both the certificate and the key. Setting SMQ_CLIENTS_AUTH_GRPC_SERVER_CERTS will enable TLS against the clients service trusting only those CAs that are provided. The service expects a file in PEM format of trusted CAs.

For more information about service capabilities and its usage, please check out the API documentation API.