Interface FluxzeroBuilder

All Superinterfaces:
FluxzeroConfiguration
All Known Implementing Classes:
DefaultFluxzero.Builder

public interface FluxzeroBuilder extends FluxzeroConfiguration
Builder interface for constructing a Fluxzero instance.

This interface exposes advanced configuration hooks for customizing message handling, dispatch behavior, serialization, user resolution, correlation tracking, and many other aspects of a Fluxzero client. It is primarily used via DefaultFluxzero but can be extended or wrapped for deeper integrations.

  • Method Details

    • configureDefaultConsumer

      FluxzeroBuilder configureDefaultConsumer(MessageType messageType, UnaryOperator<ConsumerConfiguration> updateFunction)
      Update the default consumer configuration for the specified message type.
    • addConsumerConfiguration

      FluxzeroBuilder addConsumerConfiguration(ConsumerConfiguration consumerConfiguration, MessageType... messageTypes)
      Adds a specific consumer configuration for one or more message types.
    • addBatchInterceptor

      FluxzeroBuilder addBatchInterceptor(BatchInterceptor interceptor, MessageType... forTypes)
      Registers a BatchInterceptor that applies to the given message types.

      You can use @Order on the interceptor class to influence ordering. Lower values have higher priority. Interceptors with a negative order value run before Fluxzero's built-in batch interceptors, while zero, positive, or missing values run after them. Interceptors registered via Java's ServiceLoader are also picked up automatically and participate in the same ordering.

    • addDispatchInterceptor

      FluxzeroBuilder addDispatchInterceptor(DispatchInterceptor interceptor, MessageType... forTypes)
      Adds a DispatchInterceptor that modifies or monitors message dispatch.

      You can use @Order on the interceptor class to influence ordering. Lower values have higher priority. Interceptors with a negative order value run in the high-priority slot, while zero, positive, or missing values run in the regular slot. Interceptors registered via Java's ServiceLoader are also picked up automatically and participate in the same ordering.

    • addHandlerInterceptor

      default FluxzeroBuilder addHandlerInterceptor(HandlerInterceptor interceptor, MessageType... forTypes)
      Adds a HandlerInterceptor for given message types.

      You can use @Order on the interceptor class to influence ordering. Lower values have higher priority. Interceptors with a negative order value run in the high-priority slot, while zero, positive, or missing values run in the regular slot. Interceptors registered via Java's ServiceLoader are also picked up automatically and participate in the same ordering.

    • addHandlerDecorator

      FluxzeroBuilder addHandlerDecorator(HandlerDecorator decorator, MessageType... forTypes)
      Adds a HandlerDecorator for the given message types.

      You can use @Order on the decorator class to influence ordering. Lower values have higher priority. Decorators with a negative order value run in the high-priority slot, while zero, positive, or missing values run in the regular slot. Decorators registered via Java's ServiceLoader are not discovered automatically; automatic service loading applies to interceptor interfaces.

    • replaceMessageRoutingInterceptor

      FluxzeroBuilder replaceMessageRoutingInterceptor(DispatchInterceptor messageRoutingInterceptor)
      Replaces the default routing interceptor used for message dispatch.
    • replaceCache

      FluxzeroBuilder replaceCache(Cache cache)
      Replaces the default cache implementation.
    • withAggregateCache

      FluxzeroBuilder withAggregateCache(Class<?> aggregateType, Cache cache)
      Configures a dedicated cache for a specific aggregate type.
    • replaceRelationshipsCache

      FluxzeroBuilder replaceRelationshipsCache(UnaryOperator<Cache> replaceFunction)
      Replaces the internal relationships cache with a new implementation.
    • forwardWebRequestsToLocalServer

      default FluxzeroBuilder forwardWebRequestsToLocalServer(int port)
      Forwards incoming MessageType.WEBREQUEST messages to a locally running HTTP server on the specified port.

      This allows applications to handle web requests using their own HTTP server rather than Fluxzero’s message-based @HandleWeb infrastructure.

      Note: This feature pushes requests to the local server and bypasses Fluxzero's pull-based dispatch model. Its use is discouraged unless integration with an existing HTTP stack is required.

      Parameters:
      port - the port on which the local HTTP server is listening
      Returns:
      this builder instance
      See Also:
    • forwardWebRequestsToLocalServer

      FluxzeroBuilder forwardWebRequestsToLocalServer(LocalServerConfig localServerConfig, UnaryOperator<ConsumerConfiguration> consumerConfigurator)
      Configures forwarding of MessageType.WEBREQUEST messages to a local HTTP server using the specified LocalServerConfig and custom consumer configuration.

      This mechanism is useful for advanced integration scenarios but bypasses Fluxzero's pull-based message tracking. Prefer native @HandleWeb handlers when possible.

      Parameters:
      localServerConfig - configuration for the local server (e.g., port, error behavior)
      consumerConfigurator - function to customize the underlying ConsumerConfiguration
      Returns:
      this builder instance
      See Also:
    • replaceDefaultResponseMapper

      FluxzeroBuilder replaceDefaultResponseMapper(ResponseMapper responseMapper)
      Replaces the default response mapper used for generic result mapping.
    • replaceWebResponseMapper

      FluxzeroBuilder replaceWebResponseMapper(WebResponseMapper webResponseMapper)
      Replaces the WebResponseMapper used for handling web responses.
    • replaceTaskScheduler

      FluxzeroBuilder replaceTaskScheduler(Function<Clock, TaskScheduler> function)
      Replaces the default TaskScheduler implementation.
    • replaceIdentityProvider

      FluxzeroBuilder replaceIdentityProvider(UnaryOperator<IdentityProvider> replaceFunction)
      Replaces the identity provider used to generate message and entity identifiers.
    • addParameterResolver

      FluxzeroBuilder addParameterResolver(ParameterResolver<? super DeserializingMessage> parameterResolver)
      Registers a ParameterResolver to support injection of method arguments in handlers.
    • replaceSerializer

      FluxzeroBuilder replaceSerializer(Serializer serializer)
      Replaces the default serializer used for events, commands, snapshots, and documents.
    • replaceCorrelationDataProvider

      FluxzeroBuilder replaceCorrelationDataProvider(UnaryOperator<CorrelationDataProvider> correlationDataProvider)
      Replaces the CorrelationDataProvider used to attach correlation data to messages.
    • replaceSnapshotSerializer

      FluxzeroBuilder replaceSnapshotSerializer(Serializer serializer)
      Overrides the serializer used specifically for snapshot serialization.
    • replaceDocumentSerializer

      FluxzeroBuilder replaceDocumentSerializer(DocumentSerializer documentSerializer)
      Replaces the document serializer for search indexing.
    • registerUserProvider

      FluxzeroBuilder registerUserProvider(UserProvider userProvider)
      Registers a user provider used for resolving and authenticating User instances.
    • addPropertySource

      default FluxzeroBuilder addPropertySource(PropertySource propertySource)
      Adds a PropertySource to the configuration chain.
    • replacePropertySource

      FluxzeroBuilder replacePropertySource(UnaryOperator<PropertySource> replacer)
      Replaces the existing property source.
    • disableErrorReporting

      FluxzeroBuilder disableErrorReporting()
      Disables automatic error reporting (e.g., via ErrorGateway).
    • disableShutdownHook

      FluxzeroBuilder disableShutdownHook()
      Prevents registration of a shutdown hook.
    • disableMessageCorrelation

      FluxzeroBuilder disableMessageCorrelation()
      Disables automatic message correlation.
    • disablePayloadValidation

      FluxzeroBuilder disablePayloadValidation()
      Disables payload validation.
    • disableWebParameterValidation

      FluxzeroBuilder disableWebParameterValidation()
      Disables validation of injected web parameters (e.g. @PathParam, @QueryParam).
    • disableDataProtection

      FluxzeroBuilder disableDataProtection()
      Disables security filtering based on @FilterContent.
    • disableAutomaticAggregateCaching

      FluxzeroBuilder disableAutomaticAggregateCaching()
      Disables automatic caching of aggregates.
    • disableScheduledCommandHandler

      FluxzeroBuilder disableScheduledCommandHandler()
      Prevents installation of the default scheduled command handler.
    • disableAutomaticTracking

      default FluxzeroBuilder disableAutomaticTracking()
      Helper method that disables all processes that contain automatic trackers. Useful for low-level applications that want to run as lean as possible.

      E.g., this disables the scheduled command handler and automatic entity caching.

    • disableTrackingMetrics

      FluxzeroBuilder disableTrackingMetrics()
      Disables tracking of processing metrics.
    • disableCacheEvictionMetrics

      FluxzeroBuilder disableCacheEvictionMetrics()
      Disables metrics related to cache eviction.
    • disableWebResponseCompression

      FluxzeroBuilder disableWebResponseCompression()
      Disables compression for web responses.
    • disableAdhocDispatchInterceptor

      FluxzeroBuilder disableAdhocDispatchInterceptor()
      Disables support for dynamically injected dispatch interceptors.
    • makeApplicationInstance

      FluxzeroBuilder makeApplicationInstance(boolean makeApplicationInstance)
      Marks the built instance as the global (application-level) Fluxzero.
    • disableKeepalive

      FluxzeroBuilder disableKeepalive()
      Disables Fluxzero’s built-in keepalive mechanism.

      By default, a Fluxzero instance keeps the JVM running after it is built by maintaining a single non-daemon thread. Calling this method disables that behavior, allowing the application to terminate normally once the main thread finishes.

    • enableHostMetrics

      default FluxzeroBuilder enableHostMetrics()
      Enables host metrics collection with default configuration.

      Host metrics include JVM memory, GC, threads, CPU usage, file descriptors, and more. Metrics are collected periodically (default: every 30 seconds) and published via MetricsGateway.

      Returns:
      this builder instance
      See Also:
    • enableHostMetrics

      Enables host metrics collection with a configuration customizer.

      Example usage:

      builder.enableHostMetrics(config -> config
          .collectionInterval(Duration.ofSeconds(60))
          .applicationName("my-app")
          .collectDisk(true));
      
      Parameters:
      configurer - a function to customize the configuration builder
      Returns:
      this builder instance
      See Also:
    • enableHostMetrics

      FluxzeroBuilder enableHostMetrics(HostMetricsConfiguration configuration)
      Enables host metrics collection with a custom configuration.
      Parameters:
      configuration - the host metrics configuration
      Returns:
      this builder instance
      See Also:
    • build

      Fluxzero build(Client client)
      Builds the Fluxzero instance using the provided low-level Client.