CZT
2023-09-06 71c4fa1e27f75ae4b765c95c67a3069c84dc72ba
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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;
    }
}