-
-
Notifications
You must be signed in to change notification settings - Fork 9k
refactor:将微信公众号存储自动配置拆分为独立的存储类型配置类,并新增Redisson支持 #3833
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 0 additions & 128 deletions
128
...gin/src/main/java/com/binarywang/solon/wxjava/mp/config/WxMpStorageAutoConfiguration.java
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
...com/binarywang/solon/wxjava/mp/config/storage/AbstractWxMpConfigStorageConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| package com.binarywang.solon.wxjava.mp.config.storage; | ||
|
|
||
| import com.binarywang.solon.wxjava.mp.properties.WxMpProperties; | ||
| import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; | ||
|
|
||
| /** | ||
| * @author <a href="https://github.com/buaazyl">zhangyl</a> | ||
| */ | ||
| public abstract class AbstractWxMpConfigStorageConfiguration { | ||
|
|
||
| protected WxMpDefaultConfigImpl config(WxMpDefaultConfigImpl config, WxMpProperties properties) { | ||
| config.setAppId(properties.getAppId()); | ||
| config.setSecret(properties.getSecret()); | ||
| config.setToken(properties.getToken()); | ||
| config.setAesKey(properties.getAesKey()); | ||
| config.setUseStableAccessToken(properties.isUseStableAccessToken()); | ||
|
|
||
| WxMpProperties.ConfigStorage configStorageProperties = properties.getConfigStorage(); | ||
| config.setHttpProxyHost(configStorageProperties.getHttpProxyHost()); | ||
| config.setHttpProxyUsername(configStorageProperties.getHttpProxyUsername()); | ||
| config.setHttpProxyPassword(configStorageProperties.getHttpProxyPassword()); | ||
| if (configStorageProperties.getHttpProxyPort() != null) { | ||
| config.setHttpProxyPort(configStorageProperties.getHttpProxyPort()); | ||
| } | ||
| return config; | ||
binarywang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
76 changes: 76 additions & 0 deletions
76
.../com/binarywang/solon/wxjava/mp/config/storage/WxMpInJedisConfigStorageConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| package com.binarywang.solon.wxjava.mp.config.storage; | ||
|
|
||
| import com.binarywang.solon.wxjava.mp.properties.RedisProperties; | ||
| import com.binarywang.solon.wxjava.mp.properties.WxMpProperties; | ||
| import lombok.RequiredArgsConstructor; | ||
| import me.chanjar.weixin.common.redis.JedisWxRedisOps; | ||
| import me.chanjar.weixin.common.redis.WxRedisOps; | ||
| import me.chanjar.weixin.mp.config.WxMpConfigStorage; | ||
| import me.chanjar.weixin.mp.config.impl.WxMpRedisConfigImpl; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.noear.solon.annotation.Bean; | ||
| import org.noear.solon.annotation.Condition; | ||
| import org.noear.solon.annotation.Configuration; | ||
| import org.noear.solon.core.AppContext; | ||
| import redis.clients.jedis.Jedis; | ||
| import redis.clients.jedis.JedisPool; | ||
| import redis.clients.jedis.JedisPoolConfig; | ||
|
|
||
| /** | ||
| * @author <a href="https://github.com/buaazyl">zhangyl</a> | ||
| */ | ||
| @Configuration | ||
| @Condition( | ||
| onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.type} = jedis", | ||
binarywang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| onClass = Jedis.class | ||
| ) | ||
| @RequiredArgsConstructor | ||
| public class WxMpInJedisConfigStorageConfiguration extends AbstractWxMpConfigStorageConfiguration { | ||
| private final WxMpProperties properties; | ||
| private final AppContext applicationContext; | ||
|
|
||
| @Bean | ||
| @Condition(onMissingBean = WxMpConfigStorage.class) | ||
| public WxMpConfigStorage wxMpConfigStorage() { | ||
| WxMpRedisConfigImpl config = getWxMpRedisConfigImpl(); | ||
| return this.config(config, properties); | ||
| } | ||
|
|
||
| private WxMpRedisConfigImpl getWxMpRedisConfigImpl() { | ||
| RedisProperties redisProperties = properties.getConfigStorage().getRedis(); | ||
| JedisPool jedisPool; | ||
| if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) { | ||
| jedisPool = applicationContext.getBean("wxMpJedisPool"); | ||
| } else { | ||
| jedisPool = applicationContext.getBean(JedisPool.class); | ||
| } | ||
| WxRedisOps redisOps = new JedisWxRedisOps(jedisPool); | ||
| return new WxMpRedisConfigImpl(redisOps, properties.getConfigStorage().getKeyPrefix()); | ||
| } | ||
|
|
||
| @Bean | ||
| @Condition(onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.redis.host}") | ||
| public JedisPool wxMpJedisPool() { | ||
| WxMpProperties.ConfigStorage storage = properties.getConfigStorage(); | ||
| RedisProperties redis = storage.getRedis(); | ||
|
|
||
| JedisPoolConfig config = new JedisPoolConfig(); | ||
| if (redis.getMaxActive() != null) { | ||
| config.setMaxTotal(redis.getMaxActive()); | ||
| } | ||
| if (redis.getMaxIdle() != null) { | ||
| config.setMaxIdle(redis.getMaxIdle()); | ||
| } | ||
| if (redis.getMaxWaitMillis() != null) { | ||
| config.setMaxWaitMillis(redis.getMaxWaitMillis()); | ||
| } | ||
| if (redis.getMinIdle() != null) { | ||
| config.setMinIdle(redis.getMinIdle()); | ||
| } | ||
| config.setTestOnBorrow(true); | ||
| config.setTestWhileIdle(true); | ||
|
|
||
| return new JedisPool(config, redis.getHost(), redis.getPort(), redis.getTimeout(), redis.getPassword(), | ||
buaazyl marked this conversation as resolved.
Show resolved
Hide resolved
binarywang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| redis.getDatabase()); | ||
| } | ||
| } | ||
29 changes: 29 additions & 0 deletions
29
...com/binarywang/solon/wxjava/mp/config/storage/WxMpInMemoryConfigStorageConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| package com.binarywang.solon.wxjava.mp.config.storage; | ||
|
|
||
| import com.binarywang.solon.wxjava.mp.properties.WxMpProperties; | ||
| import lombok.RequiredArgsConstructor; | ||
| import me.chanjar.weixin.mp.config.WxMpConfigStorage; | ||
| import me.chanjar.weixin.mp.config.impl.WxMpDefaultConfigImpl; | ||
| import org.noear.solon.annotation.Bean; | ||
| import org.noear.solon.annotation.Condition; | ||
| import org.noear.solon.annotation.Configuration; | ||
|
|
||
| /** | ||
| * @author <a href="https://github.com/buaazyl">zhangyl</a> | ||
| */ | ||
| @Configuration | ||
| @Condition( | ||
| onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.type:memory} = memory" | ||
| ) | ||
| @RequiredArgsConstructor | ||
| public class WxMpInMemoryConfigStorageConfiguration extends AbstractWxMpConfigStorageConfiguration { | ||
| private final WxMpProperties properties; | ||
|
|
||
| @Bean | ||
| @Condition(onMissingBean = WxMpConfigStorage.class) | ||
| public WxMpConfigStorage wxMpConfigStorage() { | ||
| WxMpDefaultConfigImpl config = new WxMpDefaultConfigImpl(); | ||
| config(config, properties); | ||
| return config; | ||
| } | ||
| } |
65 changes: 65 additions & 0 deletions
65
...m/binarywang/solon/wxjava/mp/config/storage/WxMpInRedissonConfigStorageConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package com.binarywang.solon.wxjava.mp.config.storage; | ||
|
|
||
| import com.binarywang.solon.wxjava.mp.properties.RedisProperties; | ||
| import com.binarywang.solon.wxjava.mp.properties.WxMpProperties; | ||
| import lombok.RequiredArgsConstructor; | ||
| import me.chanjar.weixin.mp.config.WxMpConfigStorage; | ||
| import me.chanjar.weixin.mp.config.impl.WxMpRedissonConfigImpl; | ||
| import org.apache.commons.lang3.StringUtils; | ||
| import org.noear.solon.annotation.Bean; | ||
| import org.noear.solon.annotation.Condition; | ||
| import org.noear.solon.annotation.Configuration; | ||
| import org.noear.solon.core.AppContext; | ||
| import org.redisson.Redisson; | ||
| import org.redisson.api.RedissonClient; | ||
| import org.redisson.config.Config; | ||
| import org.redisson.config.TransportMode; | ||
|
|
||
| /** | ||
| * @author <a href="https://github.com/buaazyl">zhangyl</a> | ||
| */ | ||
| @Configuration | ||
| @Condition( | ||
| onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.type} = redisson", | ||
| onClass = Redisson.class | ||
| ) | ||
| @RequiredArgsConstructor | ||
| public class WxMpInRedissonConfigStorageConfiguration extends AbstractWxMpConfigStorageConfiguration { | ||
| private final WxMpProperties properties; | ||
| private final AppContext applicationContext; | ||
|
|
||
| @Bean | ||
| @Condition(onMissingBean = WxMpConfigStorage.class) | ||
| public WxMpConfigStorage wxMaConfig() { | ||
buaazyl marked this conversation as resolved.
Show resolved
Hide resolved
buaazyl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| WxMpRedissonConfigImpl config = getWxMpInRedissonConfigStorage(); | ||
| return this.config(config, properties); | ||
| } | ||
|
|
||
| private WxMpRedissonConfigImpl getWxMpInRedissonConfigStorage() { | ||
| RedisProperties redisProperties = properties.getConfigStorage().getRedis(); | ||
| RedissonClient redissonClient; | ||
| if (redisProperties != null && StringUtils.isNotEmpty(redisProperties.getHost())) { | ||
| redissonClient = applicationContext.getBean("wxMpRedissonClient"); | ||
| } else { | ||
| redissonClient = applicationContext.getBean(RedissonClient.class); | ||
| } | ||
| return new WxMpRedissonConfigImpl(redissonClient, properties.getConfigStorage().getKeyPrefix()); | ||
| } | ||
|
|
||
| @Bean | ||
| @Condition(onProperty = "${" + WxMpProperties.PREFIX + ".config-storage.redis.host}") | ||
| public RedissonClient wxMpRedissonClient() { | ||
| WxMpProperties.ConfigStorage storage = properties.getConfigStorage(); | ||
| RedisProperties redis = storage.getRedis(); | ||
|
|
||
| Config config = new Config(); | ||
| config.useSingleServer() | ||
| .setAddress("redis://" + redis.getHost() + ":" + redis.getPort()) | ||
| .setDatabase(redis.getDatabase()); | ||
| if (StringUtils.isNotBlank(redis.getPassword())) { | ||
| config.useSingleServer().setPassword(redis.getPassword()); | ||
| } | ||
| config.setTransportMode(TransportMode.NIO); | ||
| return Redisson.create(config); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.