/mqtt-broker

This is a basic implementation of an iot message broker using MQTT and GraphQL

Primary LanguageTypeScript

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us

Description

IOT APP This is a basic implementation of an iot message broker using MQTT and GraphQL Nest framework TypeScript starter repository.

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Implementation Approach

The request and response data are stored in memory in a mock database. When a request is made the publisher publishes the request then the subscriber writes the request to a mock database.

Technology Stack

Built With

GraphQL API Architecture

http://localhost:3000/graphql

To send a message to mqtt broker

Mutation

mutation addMessage ($newMessageData: MessageInput!) {
   addMessage (newMessageData: $newMessageData) {
     title,
     description
   }
 }

Pass the Query Variables as follows

{
  "newMessageData": {
    "id": "124",
    "title": "dim4 sample",
    "description":"sample description"
  }
}

Query

query message {
   message(id: "124") {
    title
   }
 }

Query to get all messages and limit number of response NOTE passing limit:0 would return all messages limit: 10 returns 10 messages

query allMessages {
   allMessages(limit: 0) {
    title
   }
 }

Improvements

  1. Setup a database connection and log messages from publisher to DB
  2. Write unit/integration tests

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.

Stay in touch

License

Nest is MIT licensed.