Interface MessageBus

All Superinterfaces:
AutoCloseable
All Known Implementing Classes:
WorkspaceMessageBus

public interface MessageBus extends AutoCloseable
Live message transport for coordinating work across sessions and processes.

Three consumption modes are exposed:

  • Drain queue (Mode A) — single-consumer, ack-on-read. Each entry is returned at most once; storage drops it the moment it is read.
  • Replay log (Mode C) — multi-consumer, externally bounded. Each reader tracks its own cursor; entries persist until trimmed or capped by maxLen.
  • Transient broadcast (Mode D) — fire-and-forget pub/sub. Only currently-subscribed listeners receive a payload; no history is retained.

Domain helpers (inboxPush(java.lang.String, java.util.Map<java.lang.String, java.lang.Object>), inboxDrain(java.lang.String, int), enqueueWakeup(java.lang.String, java.lang.String, java.lang.String)) map higher-level concepts onto these primitives with a fixed key-naming convention.

Implementations:

  • WorkspaceMessageBus — single-process, no external dependencies
  • Field Details

  • Method Details

    • queuePush

      reactor.core.publisher.Mono<String> queuePush(String key, Map<String,Object> payload)
      Append a payload to the drain queue at the given key.
      Parameters:
      key - queue identifier (caller-defined naming convention)
      payload - JSON-serializable dict to enqueue
      Returns:
      the transport-level entry id
    • queueDrain

      reactor.core.publisher.Mono<List<BusEntry>> queueDrain(String key, int maxCount)
      Drain up to maxCount entries from the queue at the given key. Returned entries are removed from the queue atomically. A subsequent call returns only entries that arrived after this one.
      Parameters:
      key - queue identifier
      maxCount - maximum number of entries to return
      Returns:
      entries in arrival order; empty list when the queue is empty
    • queueDelete

      reactor.core.publisher.Mono<Void> queueDelete(String key)
      Delete the drain queue at the given key and all of its entries. Idempotent.
      Parameters:
      key - queue identifier
    • queuePeek

      reactor.core.publisher.Mono<Boolean> queuePeek(String key)
      Check whether the drain queue at the given key has any entries, without consuming them.
      Parameters:
      key - queue identifier
      Returns:
      true if the queue has at least one entry
    • inboxHasMessages

      default reactor.core.publisher.Mono<Boolean> inboxHasMessages(String sessionId)
      Check whether a session's inbox has pending messages without consuming them.
      Parameters:
      sessionId - the session to check
      Returns:
      true if the inbox has at least one message
    • logAppend

      reactor.core.publisher.Mono<String> logAppend(String key, Map<String,Object> payload, int maxLen)
      Append a payload to the replay log at the given key. Readers track their own cursor; entries persist until trimmed or capped by maxLen.
      Parameters:
      key - log identifier
      payload - JSON-serializable dict to append
      maxLen - cap the log at approximately this many entries; older entries are trimmed when exceeded. Use 0 or negative for no cap.
      Returns:
      the transport-level entry id (usable as a cursor for subsequent reads)
    • logRead

      reactor.core.publisher.Mono<List<BusEntry>> logRead(String key, String since, int maxCount)
      Read up to maxCount entries from the replay log, starting after since. Non-destructive: the same entries can be returned to any number of readers.
      Parameters:
      key - log identifier
      since - cursor — return entries strictly newer than this id. null reads from the beginning.
      maxCount - maximum number of entries to return
      Returns:
      entries in append order; empty list when no entries are newer than since
    • logTrim

      reactor.core.publisher.Mono<Void> logTrim(String key)
      Delete the replay log at the given key and all of its entries. Idempotent.
      Parameters:
      key - log identifier
    • publish

      reactor.core.publisher.Mono<Void> publish(String key, Map<String,Object> payload)
      Publish a payload on the broadcast channel. Only currently-subscribed listeners receive it.
      Parameters:
      key - channel identifier
      payload - JSON-serializable dict
    • subscribe

      reactor.core.publisher.Flux<Map<String,Object>> subscribe(String key)
      Subscribe to a broadcast channel. Yields payloads published after subscription is established. The caller owns the subscription's lifetime — cancelling the Flux ends it.
      Parameters:
      key - channel identifier
      Returns:
      stream of payloads
    • inboxPush

      default reactor.core.publisher.Mono<Void> inboxPush(String sessionId, Map<String,Object> msg)
      Push a message into a session's inbox queue.
      Parameters:
      sessionId - the recipient session
      msg - JSON-serializable payload (typically a serialized HintBlock)
    • inboxDrain

      default reactor.core.publisher.Mono<List<BusEntry>> inboxDrain(String sessionId, int maxCount)
      Drain pending inbox messages for a session.
      Parameters:
      sessionId - the session whose inbox to drain
      maxCount - maximum entries to drain
      Returns:
      entries in arrival order
    • enqueueWakeup

      default reactor.core.publisher.Mono<Void> enqueueWakeup(String userId, String sessionId, String agentId)
      Enqueue a wakeup request and signal dispatchers.
      Parameters:
      userId - the owning user id (for multi-user isolation)
      sessionId - the session to wake
      agentId - the agent that owns the session
    • enqueueWakeup

      default reactor.core.publisher.Mono<Void> enqueueWakeup(String sessionId, String agentId)
      Convenience overload without userId. Delegates to the three-parameter form with an empty userId.
    • subscribeWakeup

      default reactor.core.publisher.Flux<Map<String,Object>> subscribeWakeup()
      Subscribe to the shared wakeup signal channel.
      Returns:
      stream of signal payloads (each indicates "drain the wakeup queue now")
    • sessionPublishEvent

      default reactor.core.publisher.Mono<String> sessionPublishEvent(String sessionId, Map<String,Object> event)
      Append a session event to the replay log and fan it out live. Late-joining subscribers can replay from the log; already-connected subscribers receive it immediately via pub/sub.
      Parameters:
      sessionId - the session this event belongs to
      event - JSON-serializable event payload
      Returns:
      the replay-log entry id
    • sessionReadEvents

      default reactor.core.publisher.Mono<List<BusEntry>> sessionReadEvents(String sessionId, String since, int maxCount)
      Read events from a session's replay log for catch-up / reconnection.
      Parameters:
      sessionId - the session whose events to read
      since - cursor — return entries strictly newer than this id; null reads all
      maxCount - maximum events to return
      Returns:
      entries in append order
    • sessionSubscribeEvents

      default reactor.core.publisher.Flux<Map<String,Object>> sessionSubscribeEvents(String sessionId)
      Live-subscribe to a session's published events. Yields only payloads delivered after the subscription is established.
      Parameters:
      sessionId - the session to subscribe to
      Returns:
      stream of event payloads
    • sessionTrimEvents

      default reactor.core.publisher.Mono<Void> sessionTrimEvents(String sessionId)
      Trim the session's event replay log. Called after a session run completes so late subscribers don't replay stale events from a previous run.
      Parameters:
      sessionId - the session whose event log to clear
    • close

      default void close()
      Release underlying transport resources. Default is a no-op.
      Specified by:
      close in interface AutoCloseable