package com.ruoyi.dataprocess.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class RedisMessageListener implements MessageListener {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void onMessage(Message message, byte[] pattern) {

        RedisSerializer keySerializer 	= redisTemplate.getKeySerializer();
        RedisSerializer valueSerializer = redisTemplate.getValueSerializer();

        log.info("----------Life接收到发布者消息----------");
        log.info("|频道:{}",keySerializer.deserialize(message.getChannel()));
        log.info("|当前监听器绑定的pattern:{}",new String(pattern));
        log.info("|消息内容:{}",valueSerializer.deserialize(message.getBody()));
        log.info("---------------------------------");
    }
}
