Skip to content

Websocket client-server example app, with ActiveMQ message broker

Notifications You must be signed in to change notification settings

kmandalas/smart-home-websockets

 
 

Repository files navigation

Smart Home demo application using Spring Boot, Websockets and ActiveMQ

Websocket client-server example app, with ActiveMQ message broker. This is the code repo for the DZone articles:

Description

In our scenario, all the smart devices have a persistent connection to a server. The server is responsible for sending commands to specific devices, such as turning on the living room lights, or enabling the alarm. It can also receive information from devices. For example there can be a temperature sensor that takes readings every minute, or an oven that sends alerts if the temperature is too high. Finally the server may also issue commands to all devices, such as turn on/off.

Image of Microservices

Each microservice (MS) is written in Java 11, using the Spring Boot framework. The communication with the clients is handled by the Device Management MS. The Control MS exposes the REST API, and communicates with the Device Mgmt MS using an Active MQ Artemis message broker. For incoming traffic routing, service discovery and load balancing we are using Spring Cloud Gateway and Eureka.

Prerequisites

  • Java 11 or above
  • Docker

How to install

From root directory type:

mvn package -DskipTests

To build the docker images run:

docker-compose build

How to run

To dun with docker, after creating the images, navigate to root directory and type:

docker-compose up

This will bring up the server-side part (including ActiveMQ) and one client

How to test

curl --location --request POST 'http://localhost:8000/control-service/device' \
--header 'Content-Type: application/json' \
--data-raw '{
	"destination": "lights_living_room",
	"command": "turn_on",
	"args": {
	}
}'

Then you can monitor the device-client / device-management service logs to see the transmitted messages

Locust scripts

You may find them here

Check the documentation for adapting them to your needs.

Contact details

Feel free to contact us for any questions or suggestions at: kmandalas@gmail.com or submit a github issue.

About

Websocket client-server example app, with ActiveMQ message broker

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 81.0%
  • Python 16.1%
  • Dockerfile 2.9%