to see https://blog.csdn.net/mydream20130314/article/details/84481290 , thank you
#示例
package com.github.onion0715.example.fastdfs;
import com.github.onion0715.example.AppConfig;
import org.csource.fastdfs.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
*
* Created by onion0715 on 2017/7/18.
*/
@Component
public class FastDFSClient implements InitializingBean{
private TrackerClient trackerClient;
private TrackerServer trackerServer;
private StorageServer storageServer;
private StorageClient storageClient;
@Autowired
private AppConfig appConfig;
private Logger logger = LoggerFactory.getLogger(FastDFSClient.class);
public void init(){
try{
String configFileName = appConfig.getFastDfsClientConfigFile();
String groupName = appConfig.getFastDfsGroupName();
/**配置文件优先读取本地文件系统路径,找不到再读classpath路径*/
ClientGlobal.init(configFileName);
trackerClient = new TrackerClient();
/**
* 从配置文件中取tracker的ip和端口建立连接,第一个地址连接失败后,会一次迭代后续地址连接,全部无法连接则失败.错误日志不会打印到文件,而是输出到System.error.
*/
trackerServer = trackerClient.getConnection();
/**下面两个步骤会建立一个新的TCP连接,可以通过建立多个连接,也就是多个storageClient来实现连接池的功能,加速操作效率*/
storageServer = trackerClient.getStoreStorage(trackerServer,groupName);
storageClient = new StorageClient(trackerServer,storageServer);
}catch (Exception e){
throw new FastDfsClientException("init exception",e);
}
}
@Override
public void afterPropertiesSet() throws Exception {
if(appConfig.isFastDfsClientEnable()){
init();
logger.info("FastDFS client init done");
}
}
public StorageClient getStorageClient(){
return storageClient;
}
}
tracker_server=10.0.0.1:22122 #可以设置多个
tracker_server=10.0.0.2:22122
connect_timeout=5 #默认值
network_timeout=30 #默认值
charset=UTF-8 #默认值
##实现
#附录