Configurable Configurations

In StackSaga framework, there are several configurations that cannot be customized via the configuration properties. If you want to change the default configuration, you can do it by implementing your own in your class path. Here you can see what are the default configurations and how to customize them.

Table 1. Configurable configurations
Title Type Dependency Default Configuration Class Description

SEC engine Transaction Execution Thread-Pool configuration

Thread-Pool

stacksaga-spring-boot-starter

SagaTransactionTaskThreadPoolTaskExecutorDefault

True

SEC engine Transaction RetryExecution Thread-Pool configuration

Thread-Pool

stacksaga-spring-boot-starter

SagaRetryTransactionThreadPoolTaskExecutorProviderDefault

True

SEC engine Async Event Execution Thread-Pool configuration

Thread-Pool

stacksaga-spring-boot-starter

SagaEventThreadPoolTaskExecutorProviderDefault

True

Admin-Connect RestTemplate configuration

Rest Client

stacksaga-spring-boot-starter

SagaAdminConnectRestTemplateProviderDefault

True

Customization

SagaTransactionTaskThreadPoolTaskExecutor

TransactionThreadPool is the main pool of the StackSaga engine which is responsible for starting the transaction and executing the transaction.

because this thread-pool is used for starting your transaction when it is called the SagaTemplate.process() method. after starting the transaction, this thread-pool will handle all the executions of the executors.

There are two thread-pools in the StackSaga engine to execute the transactions called TransactionThreadPool and RetryTransactionThreadPool. the TransactionThreadPool is used for executing new transactions and, the RetryTransactionThreadPool is used for executing the retrying-transactions. Having separate thread-pools ensures the application’s resiliency. Because if the application is full of retrying transactions, it disrupts the new transaction. You can configure the wight for both thread-pools separately as you prefer.

— In case if you want to customize the default configuration such as pool size, name, queue size and so on, you can update the default configuration as follows:

@Component (1)
public class CustomSagaTransactionTaskThreadPoolTaskExecutor
    implements SagaTransactionTaskThreadPoolTaskExecutor { (2)

    @Override
    public ThreadPoolTaskExecutor getTaskExecutor() {
        (3)
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 5);
        ...
        return executor;
    }
}
1 Mark the class as a spring @Component (bean).
2 Implement the custom task-executor provider class from SagaTransactionTaskThreadPoolTaskExecutor and override the getTaskExecutor() method.
3 Provide your custom task-executor configurations by creating a new instance of ThreadPoolTaskExecutor.
Even though you change the prefix of the thread-pool when the task-executor is created, the prefix is changed internally as saga-tx- for maintaining the thread-name uniqueness.

SagaRetryTransactionThreadPoolTaskExecutor

RetryTransactionThreadPool is responsible for retrying the transactions that receive from the StackSaga agent.

— In case if you want to customize the default configuration such as pool size, name, and so on, you can update the default configuration as follows:

@Component (1)
public class CustomSagaRetryTransactionThreadPoolTaskExecutorProvider
    implements SagaRetryTransactionThreadPoolTaskExecutorProvider { (2)

    @Override
    public ThreadPoolTaskExecutor getTaskExecutor() {
        (3)
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 5);
        ...
        return executor;
    }
}
1 Mark the class as a spring @Component (bean).
2 Implement the custom task-executor provider class from SagaRetryTransactionThreadPoolTaskExecutorProvider and override the getTaskExecutor() method.
3 Provide your custom task-executor configurations by creating a new instance of ThreadPoolTaskExecutor.
Even though you change the prefix of the thread-pool when the task-executor is created, the prefix is changed internally as saga-R-tx- for maintaining the thread-name uniqueness.

SagaEventThreadPoolTaskExecutorProvider

— In case if you want to customize the default configuration such as pool size, name, and so on, you can update the default configuration as follows:

@Component (1)
public class CustomSagaEventThreadPoolTaskExecutorProvider implements SagaEventThreadPoolTaskExecutorProvider { (2)
    @Override
    public ThreadPoolTaskExecutor getTaskExecutor() {
        (3)
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(Runtime.getRuntime().availableProcessors() * 5);
        ...
        return executor;
    }
}
1 Mark the class as a spring @Component (bean).
2 Implement the custom task-executor provider class from SagaEventTaskExecutorProvider and override the getTaskExecutor() method.
3 Provide your custom task-executor configurations by creating a new instance of ThreadPoolTaskExecutor.
Even though you change the prefix of the thread-pool when the task-executor is created, the prefix is changed internally as saga-event- for maintaining the thread-name uniqueness.

SagaAdminConnectRestTemplateProvider

If you use StackSaga admin feature in your application SagaAdminConnectRestTemplate is used for communicating with the admin server. The default basic configuration has not been implemented for the SSL. If you want to customize the default configuration for enabling SSL and any additional configurations such as interceptors, filters, and so on, you can update the default configuration as follows:

@Component (1)
public class CustomSagaAdminConnectRestTemplateProvider implements SagaAdminConnectRestTemplateProvider { (2)

    @Override
    public RestTemplate getRestTemplate(RestTemplateBuilder restTemplateBuilder) {
        (3)
        return restTemplateBuilder
                //custom SSL
                .setSslBundle(this.getSslBundle())
                //custom header Interceptor
                .additionalInterceptors((request, body, execution) -> {
                    request.getHeaders().put("X-test-header", Collections.singletonList("TEST_VALUE"));
                    return execution.execute(request, body);
                })
                .build();
    }
}
1 Mark the class as a spring @Component (bean).
2 Implement the CustomSagaAdminConnectRestTemplateProvider class from SagaAdminConnectRestTemplateProvider and override the getRestTemplate(RestTemplateBuilder restTemplateBuilder) method.
3 Build the RestTemplate object with your own configurations by using restTemplateBuilder.
It’s recommended to use the RestTemplateBuilder to build the RestTemplate object because restTemplateBuilder contains the basic necessary configurations for communicating with the admin server. '''