forked from niefy/wx-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'gitee/dev' into dev
# Conflicts: # src/main/java/com/github/niefy/modules/wx/service/WxAccountService.java # src/main/resources/application-dev.yml
- Loading branch information
Showing
22 changed files
with
355 additions
and
145 deletions.
There are no files selected for viewing
This file contains 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 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
51 changes: 51 additions & 0 deletions
51
src/main/java/com/github/niefy/modules/wx/config/EventMessageListenerContainerConfig.java
This file contains 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,51 @@ | ||
package com.github.niefy.modules.wx.config; | ||
|
||
import com.github.niefy.modules.wx.listener.WxAccountChangedMessageListener; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.task.TaskExecutor; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.listener.ChannelTopic; | ||
import org.springframework.data.redis.listener.RedisMessageListenerContainer; | ||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; | ||
|
||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
/** | ||
* @Auther: cheng.tang | ||
* @Date: 2023/11/11 | ||
* @Description: wx-api | ||
*/ | ||
@Configuration | ||
public class EventMessageListenerContainerConfig { | ||
|
||
public static final String WX_ACCOUNT_UPDATE = "event_wx_accounts_changed"; | ||
|
||
@Autowired | ||
private WxAccountChangedMessageListener wxAccountChangedMessageListener; | ||
|
||
@Bean | ||
public TaskExecutor taskExecutor() { | ||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor(); | ||
executor.setCorePoolSize(2); | ||
executor.setMaxPoolSize(50); | ||
executor.setQueueCapacity(100); | ||
executor.setKeepAliveSeconds(600); | ||
executor.setThreadNamePrefix("rEvent-"); | ||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy()); | ||
return executor; | ||
} | ||
|
||
@Bean | ||
public RedisMessageListenerContainer redisMessageListenerContainer(RedisConnectionFactory redisConnectionFactory, | ||
ThreadPoolTaskExecutor threadPoolTaskExecutor) { | ||
RedisMessageListenerContainer container = new RedisMessageListenerContainer(); | ||
container.setConnectionFactory(redisConnectionFactory); | ||
container.setTaskExecutor(threadPoolTaskExecutor); | ||
container.addMessageListener(wxAccountChangedMessageListener, new ChannelTopic(WX_ACCOUNT_UPDATE)); | ||
return container; | ||
} | ||
|
||
|
||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/com/github/niefy/modules/wx/config/RedisTemplateConfig.java
This file contains 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,35 @@ | ||
package com.github.niefy.modules.wx.config; | ||
|
||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.RedisSerializer; | ||
|
||
/** | ||
* @Auther: cheng.tang | ||
* @Date: 2023/11/11 | ||
* @Description: wx-api | ||
*/ | ||
@Configuration | ||
public class RedisTemplateConfig { | ||
|
||
/** | ||
* 默认的JdkSerializationRedisSerializer序列后的结果可读性差 | ||
* | ||
* @param redisConnectionFactory | ||
* @return | ||
*/ | ||
@Bean | ||
public RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) { | ||
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory); | ||
redisTemplate.setKeySerializer(RedisSerializer.string()); | ||
redisTemplate.setValueSerializer(RedisSerializer.json()); | ||
redisTemplate.setHashKeySerializer(RedisSerializer.string()); | ||
redisTemplate.setHashValueSerializer(RedisSerializer.json()); | ||
return redisTemplate; | ||
} | ||
|
||
|
||
} |
12 changes: 11 additions & 1 deletion
12
src/main/java/com/github/niefy/modules/wx/config/WxMpServiceConfiguration.java
This file contains 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 |
---|---|---|
@@ -1,19 +1,29 @@ | ||
package com.github.niefy.modules.wx.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import me.chanjar.weixin.common.redis.RedisTemplateWxRedisOps; | ||
import me.chanjar.weixin.common.redis.WxRedisOps; | ||
import me.chanjar.weixin.mp.api.WxMpService; | ||
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.core.StringRedisTemplate; | ||
|
||
@RequiredArgsConstructor | ||
@Configuration | ||
public class WxMpServiceConfiguration { | ||
|
||
@Bean | ||
public WxMpService wxMpService() { | ||
WxMpService wxMpService = new WxMpServiceImpl(); | ||
WxMpService wxMpService = new WxMpServiceImpl(); | ||
wxMpService.setMaxRetryTimes(3); | ||
return wxMpService; | ||
} | ||
|
||
@Bean | ||
public WxRedisOps wxRedisOps(StringRedisTemplate stringRedisTemplate) { | ||
return new RedisTemplateWxRedisOps(stringRedisTemplate); | ||
} | ||
|
||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/com/github/niefy/modules/wx/listener/WxAccountChangedMessageListener.java
This file contains 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,34 @@ | ||
package com.github.niefy.modules.wx.listener; | ||
|
||
import com.github.niefy.modules.wx.service.WxAccountService; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.data.redis.connection.Message; | ||
import org.springframework.data.redis.connection.MessageListener; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @Auther: cheng.tang | ||
* @Date: 2023/11/11 | ||
* @Description: wx-api | ||
*/ | ||
@Service | ||
@Slf4j | ||
public class WxAccountChangedMessageListener implements MessageListener { | ||
|
||
@Autowired | ||
private WxAccountService wxAccountService; | ||
|
||
@Override | ||
public void onMessage(Message message, byte[] pattern) { | ||
log.info("receiving channel {} body {} pattern {} ", new String(message.getChannel()), new String(message.getBody()), new String(pattern)); | ||
try { | ||
wxAccountService.loadWxMpConfigStorages(); | ||
log.info("finish "); | ||
} catch (Exception e) { | ||
log.error("消息处理失败了 {} ", e.getMessage()); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains 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 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 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.