Skip to content

Commit 89a9f9f

Browse files
committed
ApiBoot Message Push自动化配置
1 parent 49c952d commit 89a9f9f

File tree

4 files changed

+179
-2
lines changed

4 files changed

+179
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.autoconfigure.push;
19+
20+
import cn.jpush.api.JPushClient;
21+
import org.minbox.framework.api.boot.plugin.message.push.ApiBootMessagePushService;
22+
import org.minbox.framework.api.boot.plugin.message.push.aop.advistor.ApiBootMessagePushClientSwitchAdvisor;
23+
import org.minbox.framework.api.boot.plugin.message.push.aop.interceptor.ApiBootMessagePushSwitchAnnotationInterceptor;
24+
import org.minbox.framework.api.boot.plugin.message.push.model.PushClientConfig;
25+
import org.minbox.framework.api.boot.plugin.message.push.support.ApiBootMessagePushJiGuangServiceImpl;
26+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
27+
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
28+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
29+
import org.springframework.context.annotation.Bean;
30+
import org.springframework.context.annotation.Configuration;
31+
import org.springframework.util.ObjectUtils;
32+
33+
import java.util.HashMap;
34+
import java.util.Map;
35+
36+
/**
37+
* ApiBoot Message Push Auto Configuration
38+
*
39+
* @author:恒宇少年 - 于起宇
40+
* <p>
41+
* DateTime:2019-04-20 14:27
42+
* Blog:http://blog.yuqiyu.com
43+
* WebSite:http://www.jianshu.com/u/092df3f77bca
44+
* Gitee:https://gitee.com/hengboy
45+
* GitHub:https://github.com/hengboy
46+
*/
47+
@Configuration
48+
@ConditionalOnClass({ApiBootMessagePushService.class, JPushClient.class})
49+
@EnableConfigurationProperties(ApiBootMessagePushProperties.class)
50+
public class ApiBootMessagePushAutoConfiguration {
51+
/**
52+
* ApiBoot Message Push Properties
53+
*/
54+
private ApiBootMessagePushProperties apiBootMessagePushProperties;
55+
/**
56+
* default client name
57+
*/
58+
private static final String DEFAULT_CLIENT_NAME = "default";
59+
60+
public ApiBootMessagePushAutoConfiguration(ApiBootMessagePushProperties apiBootMessagePushProperties) {
61+
this.apiBootMessagePushProperties = apiBootMessagePushProperties;
62+
}
63+
64+
/**
65+
* instantiation message push service
66+
*
67+
* @return ApiBootMessagePushService
68+
*/
69+
@Bean
70+
@ConditionalOnMissingBean
71+
ApiBootMessagePushService apiBootMessagePushService() {
72+
Map<String, PushClientConfig> configs = getClientConfig();
73+
return new ApiBootMessagePushJiGuangServiceImpl(configs, apiBootMessagePushProperties.isProduction());
74+
}
75+
76+
/**
77+
* Message Push Aop Interceptor
78+
*
79+
* @return ApiBootMessagePushSwitchAnnotationInterceptor
80+
*/
81+
@Bean
82+
@ConditionalOnMissingBean
83+
ApiBootMessagePushSwitchAnnotationInterceptor apiBootMessagePushSwitchAnnotationInterceptor() {
84+
return new ApiBootMessagePushSwitchAnnotationInterceptor();
85+
}
86+
87+
/**
88+
* Message Push Aop Advisor
89+
*
90+
* @return ApiBootMessagePushClientSwitchAdvisor
91+
*/
92+
@Bean
93+
@ConditionalOnMissingBean
94+
ApiBootMessagePushClientSwitchAdvisor apiBootMessagePushClientSwitchAdvisor() {
95+
return new ApiBootMessagePushClientSwitchAdvisor(apiBootMessagePushSwitchAnnotationInterceptor());
96+
}
97+
98+
/**
99+
* get client config
100+
*
101+
* @return
102+
*/
103+
private Map<String, PushClientConfig> getClientConfig() {
104+
105+
Map<String, PushClientConfig> configs = new HashMap(1);
106+
107+
// default client config
108+
configs.put(DEFAULT_CLIENT_NAME, apiBootMessagePushProperties.getClient());
109+
110+
// multiple
111+
if (!ObjectUtils.isEmpty(apiBootMessagePushProperties.getMultiple())) {
112+
configs.putAll(apiBootMessagePushProperties.getMultiple());
113+
}
114+
return configs;
115+
}
116+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright [2019] [恒宇少年 - 于起宇]
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
package org.minbox.framework.api.boot.autoconfigure.push;
19+
20+
import lombok.Data;
21+
import org.minbox.framework.api.boot.plugin.message.push.model.PushClientConfig;
22+
import org.springframework.boot.context.properties.ConfigurationProperties;
23+
import org.springframework.context.annotation.Configuration;
24+
25+
import java.util.Map;
26+
27+
import static org.minbox.framework.api.boot.autoconfigure.push.ApiBootMessagePushProperties.API_BOOT_PUSH_PREFIX;
28+
29+
/**
30+
* ApiBoot Message Push Properties
31+
*
32+
* @author:恒宇少年 - 于起宇
33+
* <p>
34+
* DateTime:2019-04-20 14:52
35+
* Blog:http://blog.yuqiyu.com
36+
* WebSite:http://www.jianshu.com/u/092df3f77bca
37+
* Gitee:https://gitee.com/hengboy
38+
* GitHub:https://github.com/hengboy
39+
*/
40+
@Data
41+
@Configuration
42+
@ConfigurationProperties(prefix = API_BOOT_PUSH_PREFIX)
43+
public class ApiBootMessagePushProperties {
44+
/**
45+
* push 配置前缀
46+
*/
47+
public static final String API_BOOT_PUSH_PREFIX = "api.boot.push";
48+
/**
49+
* 极光推送客户端配置
50+
*/
51+
private PushClientConfig client;
52+
/**
53+
* 多个推送客户端配置集合
54+
*/
55+
private Map<String, PushClientConfig> multiple;
56+
/**
57+
* 配置是否生产环境推送,适用IOS平台
58+
*/
59+
private boolean production = false;
60+
}

api-boot-project/api-boot-autoconfigure/src/main/resources/META-INF/spring.factories

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
1010
org.minbox.framework.api.boot.autoconfigure.sms.ApiBootSmsAutoConfiguration,\
1111
org.minbox.framework.api.boot.autoconfigure.quartz.ApiBootQuartzAutoConfiguration,\
1212
org.minbox.framework.api.boot.autoconfigure.datasource.ApiBootDataSourceSwitchAutoConfiguration,\
13-
org.minbox.framework.api.boot.autoconfigure.resource.ApiBootResourceLoadAutoConfiguration
13+
org.minbox.framework.api.boot.autoconfigure.resource.ApiBootResourceLoadAutoConfiguration,\
14+
org.minbox.framework.api.boot.autoconfigure.push.ApiBootMessagePushAutoConfiguration

api-boot-project/api-boot-autoconfigure/src/main/resources/banner.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
|
77
'
88
:: Based On SpringBoot Version : ${spring-boot.formatted-version} ::
9-
:: ApiBoot Version : v2.0.5.RC1 ::
9+
:: ApiBoot Version : v2.0.5.RELEASE ::

0 commit comments

Comments
 (0)