EsbManager.java
1.55 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
*
* Copyright (c) 2001-2019 泛微软件.
* 泛微协同商务系统,版权所有.
*
*/
package com.weaver.esb.spi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ServiceLoader;
/**
* <p>Title: ${file_name}</p>
* <p>Description: </p>
*
* @author SJZ
* @version 1.0
* @date 2019/5/16
*/
public class EsbManager {
/**
* 日志组件
*/
private static Logger log = LoggerFactory.getLogger(EsbManager.class);
/**
* 获取ESB 服务实现类
* @param protocol
* @param requestConfig
* @return
*/
public static EsbService getService(String protocol, RequestConfig requestConfig){
ServiceLoader<EsbService> loaders = ServiceLoader.load(EsbService.class);
for(EsbService service : loaders){
try {
log.info("find service protocol:" + service.getProtocol());
if (protocol == null || protocol.isEmpty() || service.getProtocol().equalsIgnoreCase(protocol)) {
log.info("service init");
service.init(requestConfig);
log.info("return service protocol:" + service.getProtocol());
return service;
}
}catch (Exception e){
log.error(e.getMessage());
e.printStackTrace();
}
}
log.error("not find service protocol:" + protocol);
return null;
}
public static EsbService getService(RequestConfig requestConfig){
return getService(null,requestConfig);
}
}