Class DaRelaySender

java.lang.Object
de.frzy.darelay.DaRelaySender

public final class DaRelaySender extends Object
Publishes messages to Valkey/Redis channels.

Uses the settings from DaRelayListener.connect(java.lang.String, int, java.lang.String, java.lang.String, boolean) automatically, or call init(java.lang.String, int, java.lang.String, java.lang.String, boolean) yourself on a server that only sends.

send(java.lang.String, java.lang.String) blocks on the network (connecting and waiting for the reply each time out after 5 s), so from a game's main thread prefer sendAsync(java.lang.String, java.lang.String).

This is plain pub/sub: a message reaches the servers that are connected right now and nobody else. Nothing is stored or re-sent.

  • Method Details

    • init

      public static void init(String host, int port, String user, String password, boolean tls)
      Configure the sender explicitly. Only needed if you never call DaRelayListener.connect().
    • send

      public static long send(String channel, String message)
      Publish a message. Returns how many subscribers received it.

      If a connection that was already open turns out to be closed, the message is sent once more on a fresh one. A timeout is never retried, because the message may have gone out.

      Throws:
      UncheckedIOException - if Valkey can't be reached or refuses the message
      IllegalStateException - if neither init() nor DaRelayListener.connect() was called
    • sendAsync

      public static CompletableFuture<Long> sendAsync(String channel, String message)
      Same as send(java.lang.String, java.lang.String), but runs off the calling thread. Messages go out in the order they were queued. A failure is logged and also completes the returned future exceptionally, so you may ignore the future if a log line is enough for you.
    • close

      public static void close()
      Close the sending connection and forget the settings. Called by DaRelayListener.shutdown(). Waits up to 2 s for messages already handed to sendAsync(java.lang.String, java.lang.String) to go out first.