Я бы хотел объединить HiveMQ Client и HiveMQ Community Edition, которые являются реализацией для брокера, в один проект.Я попытался добавить клиент HiveMQ в качестве зависимости к файлу build.gradle в Hive MQ Community Edition (брокер).Он был в состоянии построить успешно, но я не уверен, правильно ли я это сделал.Когда я пытался ссылаться на клиентские классы внутри Community Edition, это приводило меня к ошибкам.Я что-то пропустил?Я хочу иметь возможность просто поместить проект клиента в редакцию сообщества брокеров и создать клиента и получить доступ ко всем классам, которые я мог использовать в клиенте HiveMQ.Я оставил инструкции с веб-сайта клиента HiveMQ, ссылки, а также то, как файл build.gradle выглядит как версия сообщества HiveMQ.
Ошибка, которую я получаю: Не удается разрешить импорт com.hivemq.client (происходит со всем импортом, ссылающимся на что-либо в проекте клиента HiveMQ)
Ссылка на GitHubs HiveMQ:
https://github.com/hivemq/hivemq-mqtt-client
https://github.com/hivemq/hivemq-community-edition
Код из Main.Java, который выдает ошибку
package com.main;
import java.util.UUID;
import com.hivemq.client.mqtt.MqttGlobalPublishFilter;
import com.hivemq.client.mqtt.datatypes.MqttQos;
import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient;
import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient.Mqtt5Publishes;
import com.hivemq.client.mqtt.mqtt5.Mqtt5Client;
import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish;
import java.util.logging.Logger;
import java.nio.ByteBuffer;
import java.util.Optional;
import java.util.logging.Level;
import java.util.concurrent.TimeUnit;
public class Main {
private static final Logger LOGGER = Logger.getLogger(Main.class.getName()); // Creates a logger instance
public static void main(String[] args) {
// Creates the client object using Blocking API
Mqtt5BlockingClient client1 = Mqtt5Client.builder()
.identifier(UUID.randomUUID().toString()) // the unique identifier of the MQTT client. The ID is randomly generated between
.serverHost("0.0.0.0") // the host name or IP address of the MQTT server. Kept it 0.0.0.0 for testing. localhost is default if not specified.
.serverPort(1883) // specifies the port of the server
.buildBlocking(); // creates the client builder
client1.connect(); // connects the client
System.out.println("Client1 Connected");
String testmessage = "How is it going";
byte[] messagebytesend = testmessage.getBytes(); // stores a message as a byte array to be used in the payload
try {
Mqtt5Publishes publishes = client1.publishes(MqttGlobalPublishFilter.ALL); // creates a "publishes" instance thats used to queue incoming messages
client1.subscribeWith() // creates a subscription
.topicFilter("test/topic")
.send();
System.out.println("The client has subscribed");
client1.publishWith() // publishes the message to the subscribed topic
.topic("test/topic")
.payload(messagebytesend)
.send();
Mqtt5Publish receivedMessage = publishes.receive(5,TimeUnit.SECONDS).orElseThrow(() -> new RuntimeException("No message received.")); // receives the message using the "publishes" instance
LOGGER.info("Recieved: " + receivedMessage);
byte[] getdata = receivedMessage.getPayloadAsBytes();
System.out.println(getdata.toString());
System.out.println(receivedMessage);
}
catch (Exception e) { // Catches all exceptions using the "base exception"
LOGGER.log(Level.SEVERE, "Something went wrong.", e);
}
}
}