¶Ô±ÈÐÂÎļþ |
| | |
| | | package org.springblade.core.oss.config; |
| | | |
| | | import com.aliyun.oss.OSSClient; |
| | | import com.obs.services.ObsClient; |
| | | import com.obs.services.ObsConfiguration; |
| | | import lombok.AllArgsConstructor; |
| | | import org.springblade.core.oss.HuaweiObsTemplate; |
| | | import org.springblade.core.oss.props.OssProperties; |
| | | import org.springblade.core.oss.rule.BladeOssRule; |
| | | import org.springblade.core.oss.rule.OssRule; |
| | | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; |
| | | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
| | | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
| | | import org.springframework.context.annotation.Bean; |
| | | |
| | | /** |
| | | * @author Tonny |
| | | */ |
| | | @AllArgsConstructor |
| | | @AutoConfiguration(after = OssConfiguration.class) |
| | | @EnableConfigurationProperties(OssProperties.class) |
| | | @ConditionalOnClass({OSSClient.class}) |
| | | @ConditionalOnProperty(value = "oss.name", havingValue = "huaweiobs") |
| | | public class HuaweiObsConfiguration { |
| | | private final OssProperties ossProperties; |
| | | |
| | | @Bean |
| | | @ConditionalOnMissingBean(OssRule.class) |
| | | public OssRule ossRule() { |
| | | return new BladeOssRule(ossProperties.getTenantMode()); |
| | | } |
| | | |
| | | @Bean |
| | | @ConditionalOnMissingBean(ObsClient.class) |
| | | public ObsClient ossClient() { |
| | | // 使ç¨å¯å®å¶ååæ°çé
置类ï¼ObsConfigurationï¼å建OBS客æ·ç«¯ï¼ObsClientï¼ï¼åå»ºå®æå䏿¯æå次修æ¹åæ° |
| | | ObsConfiguration conf = new ObsConfiguration (); |
| | | |
| | | conf.setEndPoint(ossProperties.getEndpoint()); |
| | | // 设置OSSClientå
许æå¼çæå¤§HTTPè¿æ¥æ°ï¼é»è®¤ä¸º1024个ã |
| | | conf.setMaxConnections(1024); |
| | | // 设置Socketå±ä¼ è¾æ°æ®çè¶
æ¶æ¶é´ï¼é»è®¤ä¸º50000毫ç§ã |
| | | conf.setSocketTimeout(50000); |
| | | // 设置建ç«è¿æ¥çè¶
æ¶æ¶é´ï¼é»è®¤ä¸º50000毫ç§ã |
| | | conf.setConnectionTimeout(50000); |
| | | // 设置ä»è¿æ¥æ± ä¸è·åè¿æ¥çè¶
æ¶æ¶é´ï¼åä½ï¼æ¯«ç§ï¼ï¼é»è®¤ä¸è¶
æ¶ã |
| | | conf.setConnectionRequestTimeout(1000); |
| | | // è®¾ç½®è¿æ¥ç©ºé²è¶
æ¶æ¶é´ãè¶
æ¶åå
³éè¿æ¥ï¼é»è®¤ä¸º60000毫ç§ã |
| | | conf.setIdleConnectionTime(60000); |
| | | // 设置失败请æ±éè¯æ¬¡æ°ï¼é»è®¤ä¸º3次ã |
| | | conf.setMaxErrorRetry(5); |
| | | |
| | | return new ObsClient(ossProperties.getAccessKey(), ossProperties.getSecretKey(), conf); |
| | | } |
| | | |
| | | @Bean |
| | | @ConditionalOnMissingBean(HuaweiObsTemplate.class) |
| | | @ConditionalOnBean({ObsClient.class, OssRule.class}) |
| | | public HuaweiObsTemplate huaweiobsTemplate(ObsClient ossClient, OssRule ossRule) { |
| | | return new HuaweiObsTemplate(ossClient, ossProperties, ossRule); |
| | | } |
| | | } |