aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/traccar/MainModule.java13
-rw-r--r--src/main/java/org/traccar/forward/EventForwarderMqtt.java6
-rw-r--r--src/main/java/org/traccar/forward/PositionForwarderMqtt.java6
-rw-r--r--src/main/java/org/traccar/helper/MqttUtil.java40
4 files changed, 37 insertions, 28 deletions
diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java
index c3c3586be..d5b7f7d75 100644
--- a/src/main/java/org/traccar/MainModule.java
+++ b/src/main/java/org/traccar/MainModule.java
@@ -35,7 +35,18 @@ import org.traccar.config.Keys;
import org.traccar.database.LdapProvider;
import org.traccar.database.OpenIdProvider;
import org.traccar.database.StatisticsManager;
-import org.traccar.forward.*;
+import org.traccar.forward.EventForwarder;
+import org.traccar.forward.EventForwarderJson;
+import org.traccar.forward.EventForwarderAmqp;
+import org.traccar.forward.EventForwarderKafka;
+import org.traccar.forward.EventForwarderMqtt;
+import org.traccar.forward.PositionForwarder;
+import org.traccar.forward.PositionForwarderJson;
+import org.traccar.forward.PositionForwarderAmqp;
+import org.traccar.forward.PositionForwarderKafka;
+import org.traccar.forward.PositionForwarderRedis;
+import org.traccar.forward.PositionForwarderUrl;
+import org.traccar.forward.PositionForwarderMqtt;
import org.traccar.geocoder.AddressFormat;
import org.traccar.geocoder.BanGeocoder;
import org.traccar.geocoder.BingMapsGeocoder;
diff --git a/src/main/java/org/traccar/forward/EventForwarderMqtt.java b/src/main/java/org/traccar/forward/EventForwarderMqtt.java
index 90e8500ea..83df795b1 100644
--- a/src/main/java/org/traccar/forward/EventForwarderMqtt.java
+++ b/src/main/java/org/traccar/forward/EventForwarderMqtt.java
@@ -21,11 +21,11 @@ import org.traccar.helper.MqttUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.hivemq.client.mqtt.mqtt3.Mqtt3AsyncClient;
+import com.hivemq.client.mqtt.mqtt5.Mqtt5AsyncClient;
public class EventForwarderMqtt implements EventForwarder {
- private final Mqtt3AsyncClient client;
+ private final Mqtt5AsyncClient client;
private final ObjectMapper objectMapper;
private final String topic;
@@ -49,4 +49,4 @@ public class EventForwarderMqtt implements EventForwarder {
MqttUtil.publish(client, topic, payload, (message, e) -> resultHandler.onResult(e == null, e));
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/org/traccar/forward/PositionForwarderMqtt.java b/src/main/java/org/traccar/forward/PositionForwarderMqtt.java
index e530c76a1..a6d0965b8 100644
--- a/src/main/java/org/traccar/forward/PositionForwarderMqtt.java
+++ b/src/main/java/org/traccar/forward/PositionForwarderMqtt.java
@@ -21,10 +21,10 @@ import org.traccar.helper.MqttUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.hivemq.client.mqtt.mqtt3.Mqtt3AsyncClient;
+import com.hivemq.client.mqtt.mqtt5.Mqtt5AsyncClient;
public class PositionForwarderMqtt implements PositionForwarder {
- private final Mqtt3AsyncClient client;
+ private final Mqtt5AsyncClient client;
@Override
public void forward(final PositionData positionData, final ResultHandler resultHandler) {
@@ -52,4 +52,4 @@ public class PositionForwarderMqtt implements PositionForwarder {
MqttUtil.publish(client, pubTopic, payload, (message, e) -> resultHandler.onResult(e == null, e));
}
-} \ No newline at end of file
+}
diff --git a/src/main/java/org/traccar/helper/MqttUtil.java b/src/main/java/org/traccar/helper/MqttUtil.java
index 54167f65c..9fc16012f 100644
--- a/src/main/java/org/traccar/helper/MqttUtil.java
+++ b/src/main/java/org/traccar/helper/MqttUtil.java
@@ -21,11 +21,11 @@ import java.util.UUID;
import java.util.function.BiConsumer;
import com.hivemq.client.mqtt.datatypes.MqttQos;
-import com.hivemq.client.mqtt.mqtt3.Mqtt3AsyncClient;
-import com.hivemq.client.mqtt.mqtt3.Mqtt3Client;
-import com.hivemq.client.mqtt.mqtt3.Mqtt3ClientBuilder;
-import com.hivemq.client.mqtt.mqtt3.message.auth.Mqtt3SimpleAuth;
-import com.hivemq.client.mqtt.mqtt3.message.publish.Mqtt3Publish;
+import com.hivemq.client.mqtt.mqtt5.Mqtt5AsyncClient;
+import com.hivemq.client.mqtt.mqtt5.Mqtt5Client;
+import com.hivemq.client.mqtt.mqtt5.Mqtt5ClientBuilder;
+import com.hivemq.client.mqtt.mqtt5.message.auth.Mqtt5SimpleAuth;
+import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5PublishResult;
public final class MqttUtil {
@@ -33,7 +33,7 @@ public final class MqttUtil {
}
- public static Mqtt3AsyncClient createClient(final String url) {
+ public static Mqtt5AsyncClient createClient(final String url) {
URI uri;
try {
uri = new URI(url);
@@ -41,17 +41,14 @@ public final class MqttUtil {
throw new RuntimeException(e);
}
- final Mqtt3SimpleAuth simpleAuth = getSimpleAuth(uri);
+ Mqtt5SimpleAuth simpleAuth = getSimpleAuth(uri);
- final String host = uri.getHost();
- final int port = uri.getPort();
- final Mqtt3ClientBuilder builder = Mqtt3Client.builder().identifier("traccar-" + UUID.randomUUID())
+ String host = uri.getHost();
+ int port = uri.getPort();
+ Mqtt5ClientBuilder builder = Mqtt5Client.builder().identifier("traccar-" + UUID.randomUUID())
.serverHost(host).serverPort(port).simpleAuth(simpleAuth).automaticReconnectWithDefaultConfig();
- final Mqtt3AsyncClient client;
-
+ Mqtt5AsyncClient client;
client = builder.buildAsync();
-
-
client.connectWith().send().whenComplete((message, e) -> {
throw new RuntimeException(e);
});
@@ -59,25 +56,26 @@ public final class MqttUtil {
return client;
}
- private static Mqtt3SimpleAuth getSimpleAuth(final URI uri) {
- final String userInfo = uri.getUserInfo();
- Mqtt3SimpleAuth simpleAuth = null;
+ private static Mqtt5SimpleAuth getSimpleAuth(final URI uri) {
+ String userInfo = uri.getUserInfo();
+ Mqtt5SimpleAuth simpleAuth = null;
if (userInfo != null) {
int delimiter = userInfo.indexOf(':');
if (delimiter == -1) {
throw new IllegalArgumentException("Wrong MQTT credentials. Should be in format \"username:password\"");
} else {
- simpleAuth = Mqtt3SimpleAuth.builder().username(userInfo.substring(0, delimiter++))
+ simpleAuth = Mqtt5SimpleAuth.builder().username(userInfo.substring(0, delimiter++))
.password(userInfo.substring(delimiter).getBytes()).build();
}
}
return simpleAuth;
}
- public static void publish(final Mqtt3AsyncClient client, final String pubTopic, final String payload,
- final BiConsumer<? super Mqtt3Publish, ? super Throwable> whenComplete) {
+ public static void publish(final Mqtt5AsyncClient client, final String pubTopic, final String payload,
+ final BiConsumer<? super Mqtt5PublishResult,
+ ? super Throwable> whenComplete) {
client.publishWith().topic(pubTopic).qos(MqttQos.AT_LEAST_ONCE).payload(payload.getBytes()).send()
.whenComplete(whenComplete);
}
-} \ No newline at end of file
+}