How do I add a custom extension?

In extensions, the different types of extensions available were discussed. This guide explains how to provide your own custom extension.

The important class to be aware of here is the 'ExtensionsProvider', which allows you to specify any of the extension points you need to use in your flows. It’s not necessary to provide all the extensions here, as any extensions that are not provided will simply fall back to using the default implementations.

All extensions are registered via the model domain class. After your domain model is built, you’ll see:

new XXXDomain.Builder(actorSystem)
    .withXXXExtensions(ExtensionProvider.<XXXAggregate>builder().build())
    .withFallbackExtensions(ExtensionProvider.<Aggregate>builder().build())
    .build();

In this Builder definition, we can see that there are two key methods available:

  • 'withXXXExtensions' - this allows us to define an extension provider that is specific to a given flow (defined via the aggregate definition).

  • 'withFallbackExtensions' - this allows us to define a default extension provider that will apply to all flows. Note: any extension provided at the flow level will take priority over these fallback extensions.

For example, here we can see a standard domain being built which has been provided with a specific error handling extension:

new ErrorHandlingDomain.Builder(actorSystem)
                .withErrorHandlingMappingAdapter(errorHandlingMappingPort)
                .withErrorHandlingExternalDomainActionAdapter(errorHandlingExternalDomainActionPort)
                .withErrorHandlingExtensions(ExtensionProvider.<ErrorHandlingAggregate>builder().flowErrorExtensions(flowErrorExtensions).build())
                .withEventBus(systemEventBus)
                .withDispatcher(new SimpleFloDispatcher())
                .build();