Failed to capture SessionDestroyed event in Spring Redis Session + Spring boot framework

I have a Spring Boot project with Spring Session that is backed by Redis. I am trying to capture the sessionDestroyed event so that I can do some cleanup.

The code for capturing the event is below, as per instructions I found elsewhere on Stack Overflow.

 @Component
 public class SessionEndedListener implements     ApplicationListener<SessionDestroyedEvent> {


private final Logger LOGGER = LoggerFactory.getLogger(getClass());

@Override
public void onApplicationEvent(SessionDestroyedEvent event) {

    LOGGER.info("Destroyed session: {}", event.getSessionId()); 

}

      

}

I set up my Redis session configuration like so:

@EnableRedisHttpSession(maxInactiveIntervalInSeconds = 120)
public class RedisSessionConfig {
}

      

I see multiple logs from Spring Redis clearing expired sessions every minute as shown below.

2016-07-21 11: 07: 00,026 ==== RedisSessionExpirationPolicy.java ==== thread: pool-4-thread-1 ==== DEBUG> org.springframework.session.data.redis.RedisSessionExpirationPolicy.cleanExpiredSessions ( ) => [] (line: 107) Cleaning up sessions expiring on Thu Jul 21 11:07:00 EDT 2016

But the code designed to capture the SessionDestroyedEvent is never called. What am I missing here?

Note that I am testing this with a local Redis server where there is no problem setting up key-space events as Egx.

When I debug the code.

This statement

   if(!body.startsWith("spring:session:sessions:")) {
       return;
    }

      

in class org.springframework.session.data.redis.SessionMessageListener is returned prematurely before being able to post the event

since the body variable has a value

\xac\xed\x00\x05t\x00<spring:session:sessions:2392443d-62a9-4f8c-81f0-c0bb446eb16f

I am using spring-session 1.0.2.RELEASE. Has the bug been fixed?

0


source to share





All Articles