spring-cloud / spring-cloud/spring-cloud-consul

Make catalogWatchTaskScheduler/configWatchTaskScheduler more sophisticated

Open
#723 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement help wanted
Dominant language
Java
Stars
822
Forks
539
Avg merge
9h 31m
Merged PRs (30d)
7

Description

This issue related to #146. A fix provided there is not suitable.
For example:

  1. The consul is disabled for a local environment and my own configuration for TaskScheduler with 2 threads works well.
  2. The consul is enabled for PROD configuration and there is a single scheduling thread as a result.

To fix this a spring-vault approach with TaskSchedulerWrapper can be used
https://github.com/spring-projects/spring-vault/blob/main/spring-vault-core/src/main/java/org/springframework/vault/config/AbstractVaultConfiguration.java#L324

The advise in the documentation is not very good:

The watch uses a Spring TaskScheduler to schedule the call to consul. By default it is a ThreadPoolTaskScheduler with a poolSize of 1. To change the TaskScheduler, create a bean of type TaskScheduler named with the ConsulConfigAutoConfiguration.CONFIG_WATCH_TASK_SCHEDULER_NAME constant

  1. It doesn't work. It needs to enable bean overriding.
  2. Why I have to add to my application configuration a bean with a wired name, just to have multiple threads in the TaskScheduler?

The simplest workaround is not to use a bean with the same name, but @Primary on the application configuration.

    @Primary
    @Bean(name = "app-scheduler-pool")
    public TaskScheduler appSchedulerPool() {
        ThreadPoolTaskScheduler threadPoolTaskScheduler = new ThreadPoolTaskScheduler();
        threadPoolTaskScheduler.setPoolSize(THREADS_COUNT);
        return threadPoolTaskScheduler;
    }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Read ConsulConfigAutoConfiguration and compare its scheduler selection with the Spring Vault TaskSchedulerWrapper approach linked in the issue. Verify the documented TaskScheduler customization and @Primary configuration behavior; done means the watcher can use the application's configured scheduler without requiring the named-bean workaround.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.