Class RedisMessageTransport

java.lang.Object
dev.ua.theroer.magicutils.messaging.redis.RedisMessageTransport
All Implemented Interfaces:
MessageTransport, AutoCloseable

public final class RedisMessageTransport extends Object implements MessageTransport
Redis pub/sub messaging transport (backed by Jedis).

Publishing borrows a pooled connection and issues PUBLISH channel bytes; receiving runs a dedicated daemon thread blocked in SUBSCRIBE, reconnecting with backoff when the connection drops. Redis fans a message out to every subscriber, so MessageEnvelope carries the Target and the bus filters on receipt.

This class references Jedis types directly and is only loaded when the Redis transport is selected, keeping Jedis an optional dependency of the messaging module.

  • Constructor Details

    • RedisMessageTransport

      public RedisMessageTransport(RedisConfig.Redis config, MessageCodec codec, PlatformLogger logger)
      Creates a Redis transport from resolved settings.
      Parameters:
      config - redis settings
      codec - envelope codec
      logger - platform logger
  • Method Details

    • name

      public String name()
      Description copied from interface: MessageTransport
      Human-readable transport name for diagnostics/logging (for example "plugin-messaging", "redis").
      Specified by:
      name in interface MessageTransport
      Returns:
      transport name
    • start

      public void start(MessageTransport.EnvelopeSink sink)
      Description copied from interface: MessageTransport
      Starts the transport and begins delivering received envelopes to the sink.

      Called once before any MessageTransport.publish(MessageEnvelope). Implementations that need a background subscriber thread or channel registration set it up here.

      Specified by:
      start in interface MessageTransport
      Parameters:
      sink - destination for received envelopes
    • publish

      public void publish(MessageEnvelope envelope)
      Description copied from interface: MessageTransport
      Publishes an encoded envelope to the network.

      The envelope's Target is advisory; transports that cannot route precisely broadcast and rely on receiver-side filtering.

      Specified by:
      publish in interface MessageTransport
      Parameters:
      envelope - envelope to send
    • isConnected

      public boolean isConnected()
      Description copied from interface: MessageTransport
      Returns whether the transport is currently connected/operational.

      The default plugin-messaging transport reports connectivity based on whether the platform channel is registered; Redis reports pool health.

      Specified by:
      isConnected in interface MessageTransport
      Returns:
      true when the transport can currently deliver messages
    • close

      public void close()
      Description copied from interface: MessageTransport
      Stops the transport and releases resources.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface MessageTransport