Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix redis unsubscribe from all channels during eTranslation high load #50

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface BeanNames {
String BEAN_REDIS_TEMPLATE = "redisTemplate";
String BEAN_REDIS_CACHE_SERVICE = "redisCacheService";
String BEAN_REDIS_MESSAGE_LISTENER_CONTAINER = "redisCacheMessageListenerContainer";
String BEAN_REDIS_MESSAGE_LISTENER_ADAPTER = "redisMessageListenerAdapter";
String BEAN_REDIS_CONNECTION_FACTORY = "redisConnectionFactory";
String BEAN_TRANSLATION_PRE_PROCESSOR_SERVICE = "translationPreProcessorService";
String BEAN_LANGDETECT_PRE_PROCESSOR_SERVICE = "langDetectPreProcessorService";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import eu.europeana.api.commons.config.i18n.I18nService;
Expand Down Expand Up @@ -331,12 +333,24 @@ public RedisCacheService getRedisCacheService(
return new RedisCacheService(redisTemplate);
}

@Bean(BeanNames.BEAN_REDIS_MESSAGE_LISTENER_ADAPTER)
MessageListenerAdapter listenerAdapter() {
return new MessageListenerAdapter();
}

@Bean(BeanNames.BEAN_REDIS_MESSAGE_LISTENER_CONTAINER)
RedisMessageListenerContainer getRedisMessageListenerContainer(
@Qualifier(BeanNames.BEAN_REDIS_CONNECTION_FACTORY) LettuceConnectionFactory redisConnectionFactory) throws AppConfigurationException {
@Qualifier(BeanNames.BEAN_REDIS_CONNECTION_FACTORY) LettuceConnectionFactory redisConnectionFactory,
@Qualifier(BeanNames.BEAN_REDIS_MESSAGE_LISTENER_ADAPTER) MessageListenerAdapter messageListenerAdapter
) throws AppConfigurationException {
RedisMessageListenerContainer container = new RedisMessageListenerContainer();
redisConnectionFactory.afterPropertiesSet();
container.setConnectionFactory(redisConnectionFactory);
/*
* This is needed to avoid some cases redis closes all channels and does not allow any subscriptions (please see here: https://github.com/spring-projects/spring-data-redis/issues/2425).
* In this case we create one channel that is never un-subscribed from.
*/
container.addMessageListener(messageListenerAdapter, new PatternTopic("Dummy"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change to something meaningfull, like default

// container.addMessageListener(messageListener(), topic());
return container;
}
Expand Down
Loading