Skip to content
Open
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 @@ -69,6 +69,7 @@
* @author Ilyass Bougati
* @author Mark Paluch
* @author Christoph Strobl
* @author Dongliang Xie
* @since 4.1
* @see RedisListener
*/
Expand Down Expand Up @@ -248,7 +249,7 @@ public MethodRedisListenerEndpoint createEndpoint(RedisListener redisListener, M
MethodRedisListenerEndpoint endpoint = new MethodRedisListenerEndpoint(bean, method);
endpoint.setMessageHandlerMethodFactory(this.messageHandlerMethodFactory);
endpoint.setId(getEndpointId(redisListener));
endpoint.setTopic(redisListener.topic());
endpoint.setTopic(resolve(redisListener.topic()));
endpoint.setConsumes(redisListener.consumes());

return endpoint;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,20 @@
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;

import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;

import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;

import org.springframework.beans.factory.BeanCreationException;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.MapPropertySource;
import org.springframework.data.redis.config.RedisListenerConfigUtils;
import org.springframework.data.redis.config.RedisListenerEndpointRegistry;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
Expand All @@ -40,6 +43,7 @@
*
* @author Ilyass Bougati
* @author Mark Paluch
* @author Dongliang Xie
*/
class RedisListenerAnnotationBeanPostProcessorIntegrationTests {

Expand All @@ -62,6 +66,24 @@ void registersListenerWithDefaultContainer() {
assertThat(registryRef.get().isRunning()).isFalse();
}

@Test // GH-3393
void resolvesListenerTopicPlaceholder() {

try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
context.getEnvironment().getPropertySources()
.addFirst(new MapPropertySource("redis-listener-test", Map.of("app.my-channel", "my-channel")));
context.register(DefaultConfig.class, PlaceholderTopicService.class);
context.refresh();

RedisMessageListenerContainer container = context.getBean("redisMessageListenerContainer",
RedisMessageListenerContainer.class);
ArgumentCaptor<Topic> topicCaptor = ArgumentCaptor.forClass(Topic.class);

verify(container).addMessageListener(any(), topicCaptor.capture());
assertThat(topicCaptor.getValue().getTopic()).isEqualTo("my-channel");
}
}

@Test // GH-3340
void registersListenerWithNamedContainer() {

Expand Down Expand Up @@ -140,6 +162,13 @@ public void handle(String msg) {}

}

static class PlaceholderTopicService {

@RedisListener(topic = "${app.my-channel}")
public void handle(String msg) {}

}

static class UnnamedContainerService {

@RedisListener(topic = "test-topic", container = "")
Expand Down