Package de.frzy.darelay
Class DaRelayListener
java.lang.Object
de.frzy.darelay.DaRelayListener
DaRelay: a tiny, dependency-free pub/sub bridge for Valkey/Redis.
Java 8 compatible; works in Bukkit/Spigot/Paper, Velocity, BungeeCord, Forge and Fabric.
// onEnable / mod constructor
DaRelayListener relay = DaRelayListener.connect("host", 6379, "mcapp", "pass", true);
relay.registerListener(new TestListener(this));
public class TestListener implements RelayListener {
@RelaySub(channel = "mc:proxy")
public void onMessage(RelayEvent e) {
System.out.println(e.getChannel() + " -> " + e.getMessage());
}
}
// from anywhere, any server
DaRelaySender.sendAsync("mc:proxy", "MyMessage");
// onDisable
relay.shutdown();
The connection runs in the background and reconnects on its own (1 s up to 30 s backoff),
re-subscribing to every registered channel. A PING goes out every 15 s; if the server
sends nothing at all for 45 s the connection counts as dead and is replaced.
This is plain pub/sub: messages published while this server is disconnected are not delivered later.
-
Method Summary
Modifier and TypeMethodDescriptionstatic DaRelayListenerStart listening.static DaRelayListenerget()The running instance, or null if not connected.booleanTrue while the listening connection is up and logged in.voidregisterListener(RelayListener listener) Registers everyRelaySubmethod of the listener (including inherited ones).voidshutdown()Stops listening, closes all connections.voidunregisterListener(RelayListener listener) Removes every handler that belongs to this listener object.
-
Method Details
-
connect
public static DaRelayListener connect(String host, int port, String user, String password, boolean tls) Start listening. Returns at once; connecting happens in the background, and problems (wrong password, server down) show up in the log and inisConnected(). Calling it again with the same settings beforeshutdown()returns the same instance.- Parameters:
tls- use TLS (Valkey tls-port); recommended for anything leaving the machine- Throws:
IllegalStateException- if DaRelay is already connected with different settings, which means two plugins/mods share one copy of it; see "Bundling" in the README
-
get
The running instance, or null if not connected. -
isConnected
public boolean isConnected()True while the listening connection is up and logged in. -
registerListener
Registers everyRelaySubmethod of the listener (including inherited ones). Registering the same object again does nothing. -
unregisterListener
Removes every handler that belongs to this listener object. -
shutdown
public void shutdown()Stops listening, closes all connections. Call on plugin disable / mod unload.
-