Skip to content

Documentation inaccuracy for Redis Pub/Sub section #2524

Closed
@sergey-morenets

Description

@sergey-morenets

Hi

Here's the code from the reference documentation to attach custom message handler:

  @Bean
  RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory connectionFactory, DefaultMessageDelegate listener) {

    RedisMessageListenerContainer container = new RedisMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.addMessageListener(new MessageListenerAdapter(listener, "handleMessage"), ChannelTopic.of("chatroom"));
    return container;
  }

However it would fail with the error message:


java.lang.NullPointerException: Cannot invoke "org.springframework.data.redis.listener.adapter.MessageListenerAdapter$MethodInvoker.getMethodName()" because "this.invoker" is null
	at org.springframework.data.redis.listener.adapter.MessageListenerAdapter.onMessage(MessageListenerAdapter.java:307)
	at org.springframework.data.redis.listener.RedisMessageListenerContainer.processMessage(RedisMessageListenerContainer.java:845)
	at org.springframework.data.redis.listener.RedisMessageListenerContainer.lambda$dispatchMessage$7(RedisMessageListenerContainer.java:993)
	at java.base/java.lang.Thread.run(Thread.java:1589)

The issue that this code doesn't invoke afterPropertiesSet as clearly mentioned in JavaDocs of MessageListenerAdapter:

Make sure to call {@link #afterPropertiesSet()} after setting all the parameters on the adapter.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions