From cfd91d45b6731e6632ebb8a4913f807bab510707 Mon Sep 17 00:00:00 2001 From: "Rafael E. Ajuria" Date: Wed, 7 Jun 2023 02:28:53 +0000 Subject: redis broadcast implementation --- src/main/java/org/traccar/MainModule.java | 11 ++++++++++- src/main/java/org/traccar/config/Keys.java | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src/main') diff --git a/src/main/java/org/traccar/MainModule.java b/src/main/java/org/traccar/MainModule.java index 6a2fe21c3..b1a8006ee 100644 --- a/src/main/java/org/traccar/MainModule.java +++ b/src/main/java/org/traccar/MainModule.java @@ -28,6 +28,7 @@ import io.netty.util.Timer; import org.apache.velocity.app.VelocityEngine; import org.traccar.broadcast.BroadcastService; import org.traccar.broadcast.MulticastBroadcastService; +import org.traccar.broadcast.RedisBroadcastService; import org.traccar.broadcast.NullBroadcastService; import org.traccar.config.Config; import org.traccar.config.Keys; @@ -340,8 +341,16 @@ public class MainModule extends AbstractModule { @Provides public static BroadcastService provideBroadcastService( Config config, ObjectMapper objectMapper) throws IOException { + String broadcastType = config.getString(Keys.BROADCAST_TYPE); if (config.hasKey(Keys.BROADCAST_ADDRESS)) { - return new MulticastBroadcastService(config, objectMapper); + switch (broadcastType) { + case "multicast": + return new MulticastBroadcastService(config, objectMapper); + case "redis": + return new RedisBroadcastService(config, objectMapper); + default: + return new NullBroadcastService(); + } } return new NullBroadcastService(); } diff --git a/src/main/java/org/traccar/config/Keys.java b/src/main/java/org/traccar/config/Keys.java index d4780ba46..6f42e8937 100644 --- a/src/main/java/org/traccar/config/Keys.java +++ b/src/main/java/org/traccar/config/Keys.java @@ -1755,6 +1755,14 @@ public final class Keys { List.of(KeyType.CONFIG), "time,position,speed,course,accuracy,result"); + /** + * Broadcast method. Available options are "multicast" and "redis". Default is "multicast". + */ + public static final ConfigKey BROADCAST_TYPE = new StringConfigKey( + "broadcast.type", + List.of(KeyType.CONFIG), + "multicast"); + /** * Multicast interface. It can be either an IP address or an interface name. */ -- cgit v1.2.3