Skip to content

Configuring Fluxzero

The FluxzeroBuilder interface is the primary entry point for configuring a Fluxzero instance. It allows fine-grained customization of all core behaviors, including message consumers, dispatch logic, interceptors, caching, serialization, metrics, and much more.

Most applications use the default builder via:

FluxzeroBuilder builder = DefaultFluxzero.builder();

In Spring environments, it can be customized by implementing the FluxzeroCustomizer interface:

@Component
public class MyCustomizer implements FluxzeroCustomizer {
@Override
public FluxzeroBuilder customize(FluxzeroBuilder builder) {
return builder.addParameterResolver(new CustomResolver());
}
}

  • configureDefaultConsumer(MessageType, UnaryOperator<ConsumerConfiguration>) to adjust the default consumer template per message type. In perHandler mode this template is copied for generated handler consumers; in defaultAppConsumer mode it is the shared fallback consumer.
  • addConsumerConfiguration(...) to register additional consumers for selected message types.
  • forwardWebRequestsToLocalServer(...) to redirect incoming @HandleWeb calls to an existing local HTTP server.
  • addHandlerInterceptor(...), addBatchInterceptor(...), and addDispatchInterceptor(...) to apply interceptors by message type.
  • Interceptors may be prioritized (highPriority = true) or restricted to specific message types.
  • replaceMessageRoutingInterceptor(...) overrides the routing logic for outbound messages.
  • addHandlerDecorator(...) adds more generic handler-level logic.
  • replaceIdentityProvider(...) to control ID generation for messages or functional identifiers.
  • replaceCorrelationDataProvider(...) to define how correlation metadata is attached to outbound messages.
  • registerUserProvider(...) to integrate custom user authentication and inject User into handlers.
  • replaceCache(...) and withAggregateCache(...) to plug in custom caching backends.
  • replaceRelationshipsCache(...) for customizing the cache used in association-based message routing.
  • replaceSnapshotSerializer(...) if you want to store snapshots differently from events.
  • replaceSerializer(...) changes the default JSON serializer (e.g., for Jackson customizations).
  • replaceDocumentSerializer(...) lets you influence how document fields are indexed and stored for search.
  • Prefer fluxzero.serialization.typeAliases or FLUXZERO_SERIALIZATION_TYPE_ALIASES to configure the complete list of exact and package aliases per deployment.
  • addTypeAlias(...), addTypeAliases(...), addPackageAlias(...), and addPackageAliases(...) provide programmatic configuration when aliases are intentionally owned by application code. These aliases take precedence over property configuration for the same source.

See Upcasting and downcasting for the alias syntax, resolution order, and TestFixture behavior.

  • addParameterResolver(...) registers a ParameterResolver to inject custom arguments into handler methods.
  • replaceValidator(...) replaces the validator used by payload validation, web parameter validation, and ValidationUtils convenience methods.
  • replaceDefaultResponseMapper(...) and replaceWebResponseMapper(...) to change how handler return values are mapped into responses.
  • addPropertySource(...) and replacePropertySource(...) control the configuration hierarchy (e.g., ENV > system props > application.properties).
  • Integrates with ApplicationProperties for encrypted or templated config values.

ApplicationProperties merges every application.properties resource visible as a separate classpath resource, including resources in Spring Boot nested JARs. A custom uber-JAR build that collapses equal resource names must merge those files in its own packaging configuration.

  • replaceTaskScheduler(...) to inject a custom scheduler for async or delayed task execution.

These methods disable internal features as needed:

MethodDisables
disableErrorReporting()Suppresses error publishing to ErrorGateway
disableShutdownHook()Prevents the JVM shutdown hook
disableMessageCorrelation()Skips automatic correlation ID injection
disablePayloadValidation()Turns off payload type validation
disableDataProtection()Disables @ProtectData and @DropProtectedData filtering
disableAutomaticAggregateCaching()Skips aggregate cache setup
disableScheduledCommandHandler()Removes default handler for scheduled commands
disableTrackingMetrics()Prevents emitting metrics during message tracking
disableCacheEvictionMetrics()Disables cache eviction telemetry
disableWebResponseCompression()Prevents gzip compression for web responses
disableAdhocDispatchInterceptor()Disallows use of AdhocDispatchInterceptor.runWith...() utilities

Use onMissingProtectedData(...) to configure the application-wide response when a message references protected data that has already been dropped. The same setting is available as fluxzero.dataProtection.onMissingProtectedData; an explicit builder setting takes precedence. Environment variables may use FLUXZERO_DATA_PROTECTION_ON_MISSING_PROTECTED_DATA or FLUXZERO_DATAPROTECTION_ONMISSINGPROTECTEDDATA.


Once the builder is configured, construct the Fluxzero instance by passing in a Client (usually a WebSocketClient or LocalClient):

Fluxzero flux = builder.build(myClient);

To mark it as the global application-wide instance (i.e., accessible via Fluxzero.get()):

builder.makeApplicationInstance(true).build(myClient);

This is the central instance that orchestrates message gateways, tracking, scheduling, and storage across your application. If Spring is used, the application instance is automatically set by Spring and unset when the Spring context is closed.


Fluxzero integrates well with Spring. If you’re using Spring (or Spring Boot), many components are auto-configured for you:

  • If you provide a bean of type Serializer, Cache, Client, UserProvider, or WebResponseMapper, it will be automatically picked up by the builder.
  • Upcasters and Downcasters are auto-registered if detected on Spring beans.
  • Handlers (@Handle...) are automatically registered after the context is refreshed.
  • @TrackSelf, @Stateful, and @SocketEndpoint beans are auto-detected and wired via post-processors.
  • If no Client is configured explicitly, Fluxzero tries to create a WebSocketClient (based on available properties), or falls back to a LocalClient.

You can always override or customize behavior via a FluxzeroCustomizer.

Fluxzero exposes several core components as Spring beans, making them easy to inject into your application:

Bean typePurpose
FluxzeroAccess to the full runtime and configuration
CommandGatewayDispatch commands and receive results
EventGatewayPublish events to the global log
QueryGatewaySend queries and await answers
MetricsGatewayEmit custom metrics messages
ErrorGatewayReport errors manually
ResultGatewayManually publish results from async flows
MessageSchedulerSchedule commands or other messages
AggregateRepositoryLoad and store aggregates
DocumentStoreSearch, filter, and persist document models
KeyValueStoreAccess key-value persisted state

You can simply inject any of these into your Spring-managed components:

@Component
@AllArgsConstructor
public class MyService {
private final CommandGateway commandGateway;
public void doSomething() {
commandGateway.sendAndForget(new MyCommand(...));
}
}

Instead, prefer using the static methods on the Fluxzero class:

Fluxzero.sendCommand(new MyCommand(...));
Fluxzero.query(new GetUserProfile(userId));
Fluxzero.publishEvent(new UserLoggedIn(...));

This avoids boilerplate, reduces coupling to Spring, and works equally well in non-Spring contexts like tests or lightweight setups.


© 2026 Fluxzero