Skip to content

Different corePoolSize for different Mailer instances (with using batch module) #565

Open
@elalbertinoprimo

Description

@elalbertinoprimo

I am trying to configure different corePoolSize for 2 Mailer instances, but so far without success. As i understand from documentation, all i need is to define different clusterKey for each Mailer. But it doesn`t work as I expect. I also use batch-module.

  1. new SmtpConnectionPoolClustered beeing created here just for 1st Mailer. For 2nd I am getting warning "Global SMTP Connection pool is already configured with pool defaults ...".
    private void ensureClusterInitialized(@NotNull OperationalConfig operationalConfig) {
    if (smtpConnectionPool == null) {
    LOGGER.warn("Starting SMTP connection pool cluster: JVM won't shutdown until the pool is manually closed with mailer.shutdownConnectionPool() (for each mailer in the cluster)");
    smtpConnectionPool = new SmtpConnectionPoolClustered(configureSmtpClusterConfig(operationalConfig));
    } else if (compareClusterConfig(operationalConfig, smtpConnectionPool.getClusterConfig())) {
    LOGGER.warn("Global SMTP Connection pool is already configured with pool defaults from the first Mailer instance, ignoring relevant properties from {}", operationalConfig);
    }
    }
  2. So there is just one instance of ResourceClusters created with clusterConfig (including corePoolSize) from 1st MailerBuilder cofig. Then it`s beeing reused for 2nd cluster as well.
    https://github.com/bbottema/clustered-object-pool/blob/5857ced611c5be3489cd3cb763bfce8421aab9d9/src/main/java/org/bbottema/clusteredobjectpool/core/ResourceClusters.java#L55

My config:

    @Bean(name = FIRST_SERVER_HOST)
    public Mailer mailerFirst() {
        return MailerBuilder
                .withSMTPServer(FIRST_SERVER_HOST, FIRST_SERVER_PORT)
                .async()
                .withThreadPoolSize(20)
                .withConnectionPoolCoreSize(1)
                .withClusterKey(UUID.randomUUID())
                .buildMailer();
    }

    @Bean(name = SECOND_SERVER_HOST)
    public Mailer mailerSecond() {
        return MailerBuilder
                .withSMTPServer(SECOND_SERVER_HOST, SECOND_SERVER_PORT)
                .async()
                .withThreadPoolSize(20)
                .withConnectionPoolCoreSize(0)
                .withClusterKey(UUID.randomUUID())
                .buildMailer();
    }

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions