package org.enfi.common.modules.redis.receiver;


import cn.hutool.core.util.ObjectUtil;
import lombok.Data;
import org.enfi.common.base.BaseMap;
import org.enfi.common.constant.GlobalConstants;
import org.enfi.common.modules.redis.listener.EnFiRedisListerer;
import org.enfi.common.util.SpringContextHolder;
import org.springframework.stereotype.Component;

/**
 * @author zyf
 */
@Component
@Data
public class RedisReceiver {


    /**
     * 接受消息并调用业务逻辑处理器
     *
     * @param params
     */
    public void onMessage(BaseMap params) {
        Object handlerName = params.get(GlobalConstants.HANDLER_NAME);
        EnFiRedisListerer messageListener = SpringContextHolder.getHandler(handlerName.toString(), EnFiRedisListerer.class);
        if (ObjectUtil.isNotEmpty(messageListener)) {
            messageListener.onMessage(params);
        }
    }

}
