thingsboard / tbmq

Open-source, scalable, and fault-tolerant MQTT broker able to handle 4M+ concurrent client connections, supporting at least 3M messages per second throughput per single cluster node with low latency delivery. The cluster mode supports more than 100M concurrently connected clients.
https://thingsboard.io/products/mqtt-broker/
Apache License 2.0
588 stars 49 forks source link

How to load Default DB Data for TBMQTT? #81

Closed ShukeshAiotel closed 1 year ago

ShukeshAiotel commented 1 year ago

Initialisation of DB

Hello @dmytro-landiak,

I have build TBMQTT from sources and tried to initialise default DB data, I couldn't find any install_dev_db.sh file in path : /application/target/bin/install which I used to load default data in Thingsboard. Is that required to setup kafka environment locally to run TBMQTT application. Could you please guide me how can initialise and run TMQTT broker locally without using .deb or .rpm packages.

Environment

dmytro-landiak commented 1 year ago

Hi @ShukeshAiotel!

You are right, such file install_dev_db.sh is missing in TBMQ. We will add this soon so that the DB can be installed similarly to TB. Do you use any IDE to browse the code? Like IntelliJ IDEA / Visual Studio / Eclipse? If yes, you can find the two classes: /application/src/main/java/org/thingsboard/mqtt/broker/ThingsboardMqttBrokerInstallApplication.java - run it to install DB. /application/src/main/java/org/thingsboard/mqtt/broker/ThingsboardMqttBrokerApplication.java - run it to start the TBMQ.

Kafka is required to start TBMQ. You need either to install it locally as a service or use docker if you have it installed on your PC to run Kafka in docker. I am using the second option for example. If you need the example of docker-compose.yml file with Kafka+Zookeeper I can share it with you (let me know in case you need it). Or you can find an example here: /msa/tbmq/configs/docker-compose.yml

All of the above is needed if you want to start TBMQ and change the code or debug something, etc. If you want to just install the TBMQ and try it locally, please follow one of the next guides: https://thingsboard.io/docs/mqtt-broker/getting-started/ https://thingsboard.io/docs/mqtt-broker/install/docker/

If you have any questions, pls let me know.

dmytro-landiak commented 1 year ago

@ShukeshAiotel pls see the following commit. https://github.com/thingsboard/tbmq/commit/9fea3a8d028be7602c59d1497759857a3ef929b3

After another build in the main branch you will be able to find the requested file to init DB.

ShukeshAiotel commented 1 year ago

Hello @dmytro-landiak, Thank you for taking the time to provide a detailed response. Following your suggestion from the previous message, I executed the ThingsboardMqttBrokerInstallApplication.java to initialize the database. The operation was successful, and the TBMQTT broker application started without any issues.

I am now interested in exploring Kafka and Zookeeper on Docker. Could you please share an example of a docker-compose.yml file for this purpose?

Additionally, I have some general inquiries regarding Spring application development:

  1. When running Thingsboardserverapplication.java or ThingsboardinstallApplication.java on IntelliJ IDEA (installed using snapd) as non-root user, I encountered the following errorMaven resources compiler: Failed to copy. I can able to resolve issue when i run intellij as root (sudo snap run intellij-idea-ultimate). is there any specific IDE settings that i need to update ?.

Detailed Error Message

Maven resources compiler: Failed to copy '/home/user/Documents/tbmq-1.1.0/ui-ngx/target/generated-resources/public/22.1681a1aef3d05d5662ed.js.gz' to '/home/user/Documents/tbmq-1.1.0/ui-ngx/target/classes/public/22.1681a1aef3d05d5662ed.js.gz': Couldn't copy [/home/user/Documents/tbmq-1.1.0/ui-ngx/target/generated-resources/public/22.1681a1aef3d05d5662ed.js.gz] to [/home/user/Documents/tbmq-1.1.0/ui-ngx/target/classes/public/22.1681a1aef3d05d5662ed.js.gz]

  1. Is there a hot reload functionality available for Spring applications? If so, could you please provide relevant information or direct me to a suitable blog or resource on this topic?

Environment OS: Ubuntu 20.04 IntelliJ IDEA Ultimate : 2023.2

dmytro-landiak commented 1 year ago

Hi @ShukeshAiotel,

pls, see the following example of a docker-compose file. It can be used for development/testing purposes (not for production).

version: "3.0"
services:
  zookeeper:
    restart: always
    image: "zookeeper:3.8"
    ports:
      - "2181:2181"
    environment:
      ZOO_MY_ID: 1
      ZOO_SERVERS: server.1=zookeeper:2888:3888;zookeeper:2181
  kafka:
    restart: always
    image: wurstmeister/kafka:2.13-2.8.1
    depends_on:
      - zookeeper
    ports:
      - "9092:9092"
    environment:
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
      KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
  1. Unfortunately, it is hard for me to guide you through the 1 problem. It could be some permissions issue, so I would recommend you investigate this in that direction. I used another installation procedure. Please see the following links for details. As far as I remember, no special settings are needed to be set. https://www.jetbrains.com/help/idea/installation-guide.html#standalone https://linux.how2shout.com/how-to-install-intellij-idea-on-ubuntu-22-04-20-04-lts/

  2. It seems to me I understand what you would like to achieve. Maybe these resources will be helpful for you: https://dev.to/imanuel/auto-reload-springboot-in-intellij-idea-1l65 https://faun.pub/10-steps-to-enabling-auto-reload-for-spring-boot-in-intellij-230326413b68 If I misunderstood your question, pls provide more clarifications.

ShukeshAiotel commented 1 year ago

Hello @dmytro-landiak,

Thanks for sharing resource, your suggestions have effectively assisted me in resolving the issue I encountered.

dmytro-landiak commented 1 year ago

@ShukeshAiotel, I am happy this helped you.