Class LocalClient

All Implemented Interfaces:
Namespaced<Client>, Client

public class LocalClient extends AbstractClient
An in-memory Client implementation used for local development, testing, or isolated environments where no connection to the Fluxzero Runtime is required.

This client simulates all major subsystems — including event storage, scheduling, key-value access, and document search — using in-memory data structures with optional message expiration. It is ideal for use cases such as:

  • Unit testing message handlers
  • Running local development instances without Fluxzero Runtime dependencies
  • Offline simulations and demos

Configuration

The default expiration time for messages and scheduled tasks is 2 minutes, but a custom duration can be specified:
LocalClient client = LocalClient.newInstance(Duration.ofMinutes(5));

Features

  • Simulates gateway clients for all MessageTypes
  • Provides in-memory implementations of event store, scheduling, key-value, and search clients
  • Uses the FLUXZERO_TASK_ID environment property or the JVM process name as its local-only ID
  • Reads FLUXZERO_APPLICATION_NAME and FLUXZERO_APPLICATION_ID from environment or system properties

Usage

Typical usage involves passing this client into the FluxzeroBuilder:
Fluxzero fluxzero = DefaultFluxzero.builder().build(LocalClient.newInstance());
  • Constructor Details

  • Method Details

    • newInstance

      public static LocalClient newInstance()
      Creates an in-memory client using FLUXZERO_LOG_RETENTION from application properties, defaulting to two minutes of message retention.
    • newInstance

      public static LocalClient newInstance(Duration messageExpiration)
      Creates an in-memory client with the supplied message-retention duration.
    • newInstance

      public static LocalClient newInstance(Duration messageExpiration, Duration initialPositionLag)
      Creates a local client with configurable message retention and initial look-back for new consumers.
      Parameters:
      messageExpiration - retention duration for local messages
      initialPositionLag - duration subtracted from the current time for consumers without a stored position
      Returns:
      a new local client
    • setClock

      public void setClock(@NonNull @NonNull Clock clock)
      Links the local scheduling store to the Fluxzero clock.

      This is called by the Fluxzero builder so local schedules and test-time shifts observe the same time source as the rest of the SDK.

    • getNamespaces

      public CompletableFuture<List<String>> getNamespaces()
      Description copied from interface: Client
      Returns a sorted, duplicate-free snapshot of namespaces in this client's storage environment. The Runtime includes persisted namespaces without active clients. Local clients include namespaces created within the same root client; independent local clients remain isolated. Discovery does not create namespaces. This Runtime-wide operation requires a server and deployment route supporting namespace discovery. Custom clients that do not implement discovery fail explicitly instead of returning a partial list.
    • name

      public String name()
      Description copied from interface: Client
      Returns the name of this client as defined in its configuration.
    • applicationId

      public String applicationId()
      Description copied from interface: Client
      Returns the application ID under which this client instance is registered.
    • createGatewayClient

      protected GatewayClient createGatewayClient(io.fluxzero.common.MessageType messageType, String topic)
      Description copied from class: AbstractClient
      Subclasses must implement this method to return a GatewayClient for the given message type and topic.
      Specified by:
      createGatewayClient in class AbstractClient
    • createTrackingClient

      protected TrackingClient createTrackingClient(io.fluxzero.common.MessageType messageType, String topic)
      Description copied from class: AbstractClient
      Subclasses must implement this method to return a TrackingClient for the given message type and topic.
      Specified by:
      createTrackingClient in class AbstractClient
    • createEventStoreClient

      protected EventStoreClient createEventStoreClient()
      Description copied from class: AbstractClient
      Subclasses must implement this method to return a EventStoreClient.
      Specified by:
      createEventStoreClient in class AbstractClient
    • createSchedulingClient

      protected SchedulingClient createSchedulingClient()
      Description copied from class: AbstractClient
      Subclasses must implement this method to return a SchedulingClient.
      Specified by:
      createSchedulingClient in class AbstractClient
    • createKeyValueClient

      protected KeyValueClient createKeyValueClient()
      Description copied from class: AbstractClient
      Subclasses must implement this method to return a KeyValueClient.
      Specified by:
      createKeyValueClient in class AbstractClient
    • createSearchClient

      protected InMemorySearchStore createSearchClient()
      Description copied from class: AbstractClient
      Subclasses must implement this method to return a SearchClient.
      Specified by:
      createSearchClient in class AbstractClient
    • createForNamespace

      protected Client createForNamespace(String namespace)
      Specified by:
      createForNamespace in class AbstractNamespaced<Client>