Skip to content

Commit

Permalink
Merge pull request #96 from HongDam-org/feat/thread-pool-retry-backoff
Browse files Browse the repository at this point in the history
[FEAT] thread pool and retry backoff setting
  • Loading branch information
ohksj77 authored Oct 9, 2024
2 parents 82e5f99 + 4637860 commit bf07e52
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.retry.backoff.FixedBackOffPolicy;
import org.springframework.retry.backoff.ExponentialBackOffPolicy;
import org.springframework.retry.policy.SimpleRetryPolicy;
import org.springframework.retry.support.RetryTemplate;

Expand Down Expand Up @@ -132,8 +132,8 @@ public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(
final SimpleRabbitListenerContainerFactory factory =
new SimpleRabbitListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setConcurrentConsumers(3);
factory.setMaxConcurrentConsumers(10);
factory.setConcurrentConsumers(20);
factory.setMaxConcurrentConsumers(200);
factory.setRetryTemplate(retryTemplate());
return factory;
}
Expand All @@ -145,8 +145,10 @@ public RetryTemplate retryTemplate() {
final SimpleRetryPolicy retryPolicy = new SimpleRetryPolicy();
retryPolicy.setMaxAttempts(3);

final FixedBackOffPolicy backOffPolicy = new FixedBackOffPolicy();
backOffPolicy.setBackOffPeriod(3000);
final ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
backOffPolicy.setInitialInterval(10_000);
backOffPolicy.setMultiplier(1.5);
backOffPolicy.setMaxInterval(60_000);

retryTemplate.setRetryPolicy(retryPolicy);
retryTemplate.setBackOffPolicy(backOffPolicy);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

import lombok.RequiredArgsConstructor;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.ChannelRegistration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
Expand Down Expand Up @@ -38,4 +41,34 @@ public void configureMessageBroker(final MessageBrokerRegistry registry) {

registry.setApplicationDestinationPrefixes("/pub");
}

@Override
public void configureClientInboundChannel(final ChannelRegistration registration) {
registration.taskExecutor(inboundTaskExecutor());
}

@Override
public void configureClientOutboundChannel(final ChannelRegistration registration) {
registration.taskExecutor(outboundTaskExecutor());
}

@Bean
public ThreadPoolTaskExecutor inboundTaskExecutor() {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(15);
executor.setMaxPoolSize(150);
executor.setThreadNamePrefix("stomp-inbound-");
executor.initialize();
return executor;
}

@Bean
public ThreadPoolTaskExecutor outboundTaskExecutor() {
final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(20);
executor.setMaxPoolSize(200);
executor.setThreadNamePrefix("stomp-outbound-");
executor.initialize();
return executor;
}
}

0 comments on commit bf07e52

Please sign in to comment.