package com.ld.igds.mq;
|
|
import com.ld.igds.io.constant.ProtocolEnum;
|
import org.springframework.beans.BeansException;
|
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.stereotype.Component;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
/**
|
* 实现消息队列接口管理
|
*/
|
@Component(ReceiveManager.BEAN_ID)
|
public class ReceiveManager implements ApplicationContextAware {
|
|
public static final String BEAN_ID = "core.redisReceiveManager";
|
|
/**
|
* RedisReceiveService 接口的实现类
|
*/
|
public static Map<String, RedisReceiveService> serviceMap = new HashMap<>();
|
|
@Override
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
Map<String, RedisReceiveService> tempMap = applicationContext.getBeansOfType(RedisReceiveService.class);
|
for (String key : tempMap.keySet()) {
|
serviceMap.put(tempMap.get(key).getTopic(), tempMap.get(key));
|
}
|
}
|
|
/**
|
* 根据协议获取协议实现接口
|
*
|
* @param topic
|
* @return
|
*/
|
public RedisReceiveService getRedisReceiveService(String topic) {
|
RedisReceiveService redisReceiveService = serviceMap.get(topic);
|
if (null == redisReceiveService) {
|
topic = ProtocolEnum.TCP_DEFAULT.getCode();
|
redisReceiveService = serviceMap.get(topic);
|
}
|
return redisReceiveService;
|
}
|
}
|