package com.usoftchina.uas.office.listener;

import com.alibaba.fastjson.JSON;
import com.usoftchina.uas.office.dto.UasEvent;
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.stereotype.Component;

/**
 * @author yingp
 * @date 2020/2/16
 */
@Component
public class UasEventListenerAdapter implements MessageListener {
    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private UasEventListenerFactory eventListenerFactory;

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String value = (String) redisTemplate.getValueSerializer().deserialize(message.getBody());
        UasEvent event = JSON.parseObject(value, UasEvent.class);
        eventListenerFactory.invokeListeners(event);
    }
}
