Skip to content

Latest commit

 

History

History
102 lines (68 loc) · 3.17 KB

File metadata and controls

102 lines (68 loc) · 3.17 KB

knot-cloud-protocol-adapter-websocket

KNoT Cloud WebSocket protocol adapter.

Installation and usage

This service is part of the KNoT Cloud and requires a subset of its service to work. It is a websocket service that provides the API for registering and interacting with devices.

Configuration

Configuration is made via a JSON file placed into config folder (see config package documentation for more info), but also it is possible to configure via environment variables. The parameters are:

  • PORT Number Server port number. (Default: 80)
  • MESHBLU_NAMESPACE String Meshblu's namespace on Redis. (Default: meshblu)
  • MESHBLU_MESSAGES_NAMESPACE String Meshblu's messages namespace on Redis. (Default: messages)
  • MESHBLU_REDIS_URI String URI of Redis server used by Meshblu.
  • MESHBLU_FIREHOSE_REDIS_URI String URI of Redis server used by Meshblu Firehose.
  • MESHBLU_CACHE_REDIS_URI String URI of Redis server used by Meshblu cache.
  • MESHBLU_ALIAS_LOOKUP_SERVER_URI String Alias lookup service base URI.
  • MESHBLU_ALIAS_SERVER_URI String Alias service base URI.
  • MESHBLU_JOB_TIMEOUT_SECONDS Number Job timeout in seconds (Default: 30)
  • MESHBLU_JOB_LOG_SAMPLE_RATE Number Job sample rate (Default: 0)
  • MESHBLU_REQUEST_QUEUE_NAME String Meshblu's request queue name (Default: v2:request:queue)
  • MESHBLU_RESPONSE_QUEUE_NAME String Meshblu's response queue name (Default: v2:response:queue)
  • LOGGER_LEVEL String Log level (Default: debug/info)

Only change the MESHBLU_ parameters that have a default value if you know what you are doing.

Build and run (local)

First, install the dependencies:

npm i

Then:

npm run build
npm start

Build and run (local, development)

First, install the dependencies:

npm i

Then, start the server with auto-reload:

npm start:watch

Or, start the server in debug mode:

npm start:debug

Build and run (Docker, development)

A development container is specified at Dockerfile-dev. To use it, execute the following steps:

  1. Build the image:

    docker build . -f Dockerfile-dev -t knot-cloud-protocol-adapter-websocket-dev
    
  2. Create a file containing the configuration as environment variables.

  3. Run the container:

    docker run --env-file adapter.env -p 4000:80 -v `pwd`:/usr/src/app -ti knot-cloud-protocol-adapter-websocket-dev
    

The first argument to -v must be the root of this repository, so if you are running from another folder, replace `pwd` with the corresponding path.

This will start the server with auto-reload.

Run (Docker)

Containers built from the master branch and the published tags in this repository are available on DockerHub.

  1. Create a file containing the configuration as environment variables.
  2. Run the container:
docker run --env-file adapter.env -p 4000:80 -ti cesarbr/knot-cloud-protocol-adapter-websocket

Verify

To verify if the service is running properly, execute:

curl http://<hostname>:<port>/healthcheck